1
0
mirror of https://github.com/amitbet/vncproxy.git synced 2025-05-01 12:33:18 +00:00

added serverInit listening and recorder adaptation for being created outside of the client

This commit is contained in:
amit bezalel 2017-07-07 13:32:21 +03:00
parent ed0dc6839c
commit 7882e7f051
12 changed files with 840 additions and 892 deletions

View File

@ -1,30 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GOROOT" path="/usr/local/Cellar/go/1.8.3/libexec" /> <component name="GOROOT" path="/usr/local/Cellar/go/1.8.3/libexec" />
<component name="MavenImportPreferences">
<option name="generalSettings">
<MavenGeneralSettings>
<option name="mavenHome" value="Bundled (Maven 3)" />
</MavenGeneralSettings>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project> </project>

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,6 @@ import (
"net" "net"
"unicode" "unicode"
"vncproxy/common" "vncproxy/common"
"vncproxy/tee-listeners"
) )
// A ServerMessage implements a message sent from the server to the client. // A ServerMessage implements a message sent from the server to the client.
@ -21,11 +20,11 @@ type ClientAuth interface {
// Handshake is called when the authentication handshake should be // Handshake is called when the authentication handshake should be
// performed, as part of the general RFB handshake. (see 7.2.1) // performed, as part of the general RFB handshake. (see 7.2.1)
Handshake(net.Conn) error Handshake(io.ReadWriteCloser) error
} }
type ClientConn struct { type ClientConn struct {
conn net.Conn conn io.ReadWriteCloser
//c net.Conn //c net.Conn
config *ClientConfig config *ClientConfig
@ -77,6 +76,7 @@ type ClientConfig struct {
// This only needs to contain NEW server messages, and doesn't // This only needs to contain NEW server messages, and doesn't
// need to explicitly contain the RFC-required messages. // need to explicitly contain the RFC-required messages.
ServerMessages []common.ServerMessage ServerMessages []common.ServerMessage
Listener common.SegmentConsumer
} }
func Client(c net.Conn, cfg *ClientConfig) (*ClientConn, error) { func Client(c net.Conn, cfg *ClientConfig) (*ClientConn, error) {
@ -438,6 +438,15 @@ FindAuth:
} }
c.DesktopName = string(nameBytes) c.DesktopName = string(nameBytes)
srvInit := common.ServerInit{
NameLength: nameLength,
NameText: nameBytes,
FBHeight: c.FrameBufferHeight,
FBWidth: c.FrameBufferWidth,
PixelFormat: c.PixelFormat,
}
rfbSeg := &common.RfbSegment{SegmentType: common.SegmentServerInitMessage, Message: &srvInit}
c.config.Listener.Consume(rfbSeg)
return nil return nil
} }
@ -446,9 +455,8 @@ FindAuth:
// proper channels for users of the client to read. // proper channels for users of the client to read.
func (c *ClientConn) mainLoop() { func (c *ClientConn) mainLoop() {
defer c.Close() defer c.Close()
rec := listeners.NewRecorder("/Users/amitbet/recording.rbs", c.DesktopName, c.FrameBufferWidth, c.FrameBufferHeight)
reader := &common.RfbReadHelper{Reader: c.conn, Listener: rec} reader := &common.RfbReadHelper{Reader: c.conn, Listener: c.config.Listener}
// Build the map of available server messages // Build the map of available server messages
typeMap := make(map[uint8]common.ServerMessage) typeMap := make(map[uint8]common.ServerMessage)

View File

@ -1,13 +1,11 @@
package client package client
import ( import (
"net"
"crypto/des" "crypto/des"
"encoding/binary" "encoding/binary"
"io"
) )
// ClientAuthNone is the "none" authentication. See 7.2.1 // ClientAuthNone is the "none" authentication. See 7.2.1
type ClientAuthNone byte type ClientAuthNone byte
@ -15,7 +13,7 @@ func (*ClientAuthNone) SecurityType() uint8 {
return 1 return 1
} }
func (*ClientAuthNone) Handshake(net.Conn) error { func (*ClientAuthNone) Handshake(closer io.ReadWriteCloser) error {
return nil return nil
} }
@ -28,7 +26,7 @@ func (p *PasswordAuth) SecurityType() uint8 {
return 2 return 2
} }
func (p *PasswordAuth) Handshake(c net.Conn) error { func (p *PasswordAuth) Handshake(c io.ReadWriteCloser) error {
randomValue := make([]uint8, 16) randomValue := make([]uint8, 16)
if err := binary.Read(c, binary.BigEndian, &randomValue); err != nil { if err := binary.Read(c, binary.BigEndian, &randomValue); err != nil {
return err return err
@ -36,7 +34,7 @@ func (p *PasswordAuth) Handshake(c net.Conn) error {
crypted, err := p.encrypt(p.Password, randomValue) crypted, err := p.encrypt(p.Password, randomValue)
if (err != nil) { if err != nil {
return err return err
} }
@ -87,7 +85,7 @@ func (p *PasswordAuth) reverseBits(b byte) byte {
} }
func (p *PasswordAuth) encrypt(key string, bytes []byte) ([]byte, error) { func (p *PasswordAuth) encrypt(key string, bytes []byte) ([]byte, error) {
keyBytes := []byte{0,0,0,0,0,0,0,0} keyBytes := []byte{0, 0, 0, 0, 0, 0, 0, 0}
if len(key) > 8 { if len(key) > 8 {
key = key[:8] key = key[:8]

View File

@ -12,6 +12,9 @@ const (
SegmentBytes SegmentType = iota SegmentBytes SegmentType = iota
SegmentMessageSeparator SegmentMessageSeparator
SegmentRectSeparator SegmentRectSeparator
SegmentFullyParsedClientMessage
SegmentFullyParsedServerMessage
SegmentServerInitMessage
) )
type SegmentType int type SegmentType int
@ -20,7 +23,9 @@ type RfbSegment struct {
Bytes []byte Bytes []byte
SegmentType SegmentType SegmentType SegmentType
UpcomingObjectType int UpcomingObjectType int
Message interface{}
} }
type SegmentConsumer interface { type SegmentConsumer interface {
Consume(*RfbSegment) error Consume(*RfbSegment) error
} }

View File

@ -23,3 +23,10 @@ const (
Bell Bell
ServerCutText ServerCutText
) )
type ServerInit struct {
FBWidth, FBHeight uint16
PixelFormat PixelFormat
NameLength uint32
NameText []byte
}

View File

@ -1,327 +1,325 @@
package encodings package encodings
import ( import (
"errors" "errors"
"fmt" "fmt"
"vncproxy/common" "vncproxy/common"
) )
var TightMinToCompress int = 12 var TightMinToCompress int = 12
const ( const (
TightExplicitFilter = 0x04 TightExplicitFilter = 0x04
TightFill = 0x08 TightFill = 0x08
TightJpeg = 0x09 TightJpeg = 0x09
TightPNG = 0x10 TightPNG = 0x10
TightFilterCopy = 0x00 TightFilterCopy = 0x00
TightFilterPalette = 0x01 TightFilterPalette = 0x01
TightFilterGradient = 0x02 TightFilterGradient = 0x02
) )
type TightEncoding struct { type TightEncoding struct {
//output io.Writer //output io.Writer
logger common.Logger logger common.Logger
} }
// func (t *TightEncoding) SetOutput(output io.Writer) { // func (t *TightEncoding) SetOutput(output io.Writer) {
// t.output = output // t.output = output
// } // }
func (*TightEncoding) Type() int32 { func (*TightEncoding) Type() int32 { return int32(common.EncTight) }
return 7
} // func ReadAndRecBytes(conn io.Reader, rec io.Writer, count int) ([]byte, error) {
// buf, err := readBytes(conn, count)
// func ReadAndRecBytes(conn io.Reader, rec io.Writer, count int) ([]byte, error) { // rec.Write(buf)
// buf, err := readBytes(conn, count) // return buf, err
// rec.Write(buf) // }
// return buf, err // func ReadAndRecUint8(conn io.Reader, rec io.Writer) (uint8, error) {
// } // myUint, err := readUint8(conn)
// func ReadAndRecUint8(conn io.Reader, rec io.Writer) (uint8, error) { // buf := make([]byte, 1)
// myUint, err := readUint8(conn) // buf[0] = byte(myUint) // cast int8 to byte
// buf := make([]byte, 1) // rec.Write(buf)
// buf[0] = byte(myUint) // cast int8 to byte // return myUint, err
// rec.Write(buf) // }
// return myUint, err
// } // func ReadAndRecUint16(conn io.Reader, rec io.Writer) (uint16, error) {
// myUint, err := readUint16(conn)
// func ReadAndRecUint16(conn io.Reader, rec io.Writer) (uint16, error) { // buf := make([]byte, 2)
// myUint, err := readUint16(conn) // //buf[0] = byte(myUint) // cast int8 to byte
// buf := make([]byte, 2) // //var i int16 = 41
// //buf[0] = byte(myUint) // cast int8 to byte // //b := make([]byte, 2)
// //var i int16 = 41 // binary.LittleEndian.PutUint16(buf, uint16(myUint))
// //b := make([]byte, 2)
// binary.LittleEndian.PutUint16(buf, uint16(myUint)) // rec.Write(buf)
// return myUint, err
// rec.Write(buf) // }
// return myUint, err
// } func calcTightBytePerPixel(pf *common.PixelFormat) int {
bytesPerPixel := int(pf.BPP / 8)
func calcTightBytePerPixel(pf *common.PixelFormat) int {
bytesPerPixel := int(pf.BPP / 8) var bytesPerPixelTight int
if 24 == pf.Depth && 32 == pf.BPP {
var bytesPerPixelTight int bytesPerPixelTight = 3
if 24 == pf.Depth && 32 == pf.BPP { } else {
bytesPerPixelTight = 3 bytesPerPixelTight = bytesPerPixel
} else { }
bytesPerPixelTight = bytesPerPixel return bytesPerPixelTight
} }
return bytesPerPixelTight
} func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
bytesPixel := calcTightBytePerPixel(pixelFmt)
func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) { //conn := common.RfbReadHelper{Reader:reader}
bytesPixel := calcTightBytePerPixel(pixelFmt) //conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
//conn := common.RfbReadHelper{Reader:reader}
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat} //var subencoding uint8
compctl, err := r.ReadUint8()
//var subencoding uint8 if err != nil {
compctl, err := r.ReadUint8() fmt.Printf("error in handling tight encoding: %v\n", err)
if err != nil { return nil, err
fmt.Printf("error in handling tight encoding: %v\n", err) }
return nil, err fmt.Printf("bytesPixel= %d, subencoding= %d\n", bytesPixel, compctl)
}
fmt.Printf("bytesPixel= %d, subencoding= %d\n", bytesPixel, compctl) //move it to position (remove zlib flush commands)
compType := compctl >> 4 & 0x0F
//move it to position (remove zlib flush commands)
compType := compctl >> 4 & 0x0F fmt.Printf("afterSHL:%d\n", compType)
switch compType {
fmt.Printf("afterSHL:%d\n", compType) case TightFill:
switch compType { fmt.Printf("reading fill size=%d\n", bytesPixel)
case TightFill: //read color
fmt.Printf("reading fill size=%d\n", bytesPixel) r.ReadBytes(int(bytesPixel))
//read color //byt, _ := r.ReadBytes(3)
r.ReadBytes(int(bytesPixel)) //fmt.Printf(">>>>>>>>>TightFillBytes=%v", byt)
//byt, _ := r.ReadBytes(3) return t, nil
//fmt.Printf(">>>>>>>>>TightFillBytes=%v", byt) case TightJpeg:
return t, nil if pixelFmt.BPP == 8 {
case TightJpeg: return nil, errors.New("Tight encoding: JPEG is not supported in 8 bpp mode")
if pixelFmt.BPP == 8 { }
return nil, errors.New("Tight encoding: JPEG is not supported in 8 bpp mode")
} len, err := r.ReadCompactLen()
if err != nil {
len, err := r.ReadCompactLen() return nil, err
if err != nil { }
return nil, err fmt.Printf("reading jpeg size=%d\n", len)
} r.ReadBytes(len)
fmt.Printf("reading jpeg size=%d\n", len) return t, nil
r.ReadBytes(len) default:
return t, nil
default: if compType > TightJpeg {
fmt.Println("Compression control byte is incorrect!")
if compType > TightJpeg { }
fmt.Println("Compression control byte is incorrect!")
} handleTightFilters(compctl, pixelFmt, rect, r)
return t, nil
handleTightFilters(compctl, pixelFmt, rect, r) }
return t, nil }
}
} func handleTightFilters(subencoding uint8, pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) {
//conn := common.RfbReadHelper{Reader:reader}
func handleTightFilters(subencoding uint8, pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) { var FILTER_ID_MASK uint8 = 0x40
//conn := common.RfbReadHelper{Reader:reader} //var STREAM_ID_MASK uint8 = 0x30
var FILTER_ID_MASK uint8 = 0x40
//var STREAM_ID_MASK uint8 = 0x30 //decoderId := (subencoding & STREAM_ID_MASK) >> 4
var filterid uint8
//decoderId := (subencoding & STREAM_ID_MASK) >> 4 var err error
var filterid uint8
var err error if (subencoding & FILTER_ID_MASK) > 0 { // filter byte presence
filterid, err = r.ReadUint8()
if (subencoding & FILTER_ID_MASK) > 0 { // filter byte presence if err != nil {
filterid, err = r.ReadUint8() fmt.Printf("error in handling tight encoding, reading filterid: %v\n", err)
if err != nil { return
fmt.Printf("error in handling tight encoding, reading filterid: %v\n", err) }
return fmt.Printf("read filter: %d\n", filterid)
} }
fmt.Printf("read filter: %d\n", filterid)
} //var numColors uint8
bytesPixel := calcTightBytePerPixel(pixelFmt)
//var numColors uint8
bytesPixel := calcTightBytePerPixel(pixelFmt) fmt.Printf("filter: %d\n", filterid)
// if rfb.rec != null {
fmt.Printf("filter: %d\n", filterid) // rfb.rec.writeByte(filter_id)
// if rfb.rec != null { // }
// rfb.rec.writeByte(filter_id) lengthCurrentbpp := int(bytesPixel) * int(rect.Width) * int(rect.Height)
// }
lengthCurrentbpp := int(bytesPixel) * int(rect.Width) * int(rect.Height) switch filterid {
case TightFilterPalette: //PALETTE_FILTER
switch filterid {
case TightFilterPalette: //PALETTE_FILTER colorCount, err := r.ReadUint8()
paletteSize := colorCount + 1 // add one more
colorCount, err := r.ReadUint8() fmt.Printf("----PALETTE_FILTER: paletteSize=%d bytesPixel=%d\n", paletteSize, bytesPixel)
paletteSize := colorCount + 1 // add one more //complete palette
fmt.Printf("----PALETTE_FILTER: paletteSize=%d bytesPixel=%d\n", paletteSize, bytesPixel) r.ReadBytes(int(paletteSize) * bytesPixel)
//complete palette
r.ReadBytes(int(paletteSize) * bytesPixel) var dataLength int
if paletteSize == 2 {
var dataLength int dataLength = int(rect.Height) * ((int(rect.Width) + 7) / 8)
if paletteSize == 2 { } else {
dataLength = int(rect.Height) * ((int(rect.Width) + 7) / 8) dataLength = int(rect.Width * rect.Height)
} else { }
dataLength = int(rect.Width * rect.Height) _, err = r.ReadTightData(dataLength)
} if err != nil {
_, err = r.ReadTightData(dataLength) fmt.Printf("error in handling tight encoding, Reading Palette: %v\n", err)
if err != nil { return
fmt.Printf("error in handling tight encoding, Reading Palette: %v\n", err) }
return case TightFilterGradient: //GRADIENT_FILTER
} fmt.Printf("----GRADIENT_FILTER: bytesPixel=%d\n", bytesPixel)
case TightFilterGradient: //GRADIENT_FILTER //useGradient = true
fmt.Printf("----GRADIENT_FILTER: bytesPixel=%d\n", bytesPixel) fmt.Printf("usegrad: %d\n", filterid)
//useGradient = true r.ReadTightData(lengthCurrentbpp)
fmt.Printf("usegrad: %d\n", filterid) case TightFilterCopy: //BASIC_FILTER
r.ReadTightData(lengthCurrentbpp) fmt.Printf("----BASIC_FILTER: bytesPixel=%d\n", bytesPixel)
case TightFilterCopy: //BASIC_FILTER r.ReadTightData(lengthCurrentbpp)
fmt.Printf("----BASIC_FILTER: bytesPixel=%d\n", bytesPixel) default:
r.ReadTightData(lengthCurrentbpp) fmt.Printf("Bad tight filter id: %d\n", filterid)
default: return
fmt.Printf("Bad tight filter id: %d\n", filterid) }
return
} ////////////
//////////// // if numColors == 0 && bytesPixel == 4 {
// rowSize1 *= 3
// if numColors == 0 && bytesPixel == 4 { // }
// rowSize1 *= 3 // rowSize := (int(rect.Width)*bitsPixel + 7) / 8
// } // dataSize := int(rect.Height) * rowSize
// rowSize := (int(rect.Width)*bitsPixel + 7) / 8
// dataSize := int(rect.Height) * rowSize // dataSize1 := rect.Height * rowSize1
// fmt.Printf("datasize: %d, origDatasize: %d", dataSize, dataSize1)
// dataSize1 := rect.Height * rowSize1 // // Read, optionally uncompress and decode data.
// fmt.Printf("datasize: %d, origDatasize: %d", dataSize, dataSize1) // if int(dataSize1) < TightMinToCompress {
// // Read, optionally uncompress and decode data. // // Data size is small - not compressed with zlib.
// if int(dataSize1) < TightMinToCompress { // if numColors != 0 {
// // Data size is small - not compressed with zlib. // // Indexed colors.
// if numColors != 0 { // //indexedData := make([]byte, dataSize)
// // Indexed colors. // readBytes(conn.c, int(dataSize1))
// //indexedData := make([]byte, dataSize) // //readFully(indexedData);
// readBytes(conn.c, int(dataSize1)) // // if (rfb.rec != null) {
// //readFully(indexedData); // // rfb.rec.write(indexedData);
// // if (rfb.rec != null) { // // }
// // rfb.rec.write(indexedData); // // if (numColors == 2) {
// // } // // // Two colors.
// // if (numColors == 2) { // // if (bytesPixel == 1) {
// // // Two colors. // // decodeMonoData(x, y, w, h, indexedData, palette8);
// // if (bytesPixel == 1) { // // } else {
// // decodeMonoData(x, y, w, h, indexedData, palette8); // // decodeMonoData(x, y, w, h, indexedData, palette24);
// // } else { // // }
// // decodeMonoData(x, y, w, h, indexedData, palette24); // // } else {
// // } // // // 3..255 colors (assuming bytesPixel == 4).
// // } else { // // int i = 0;
// // // 3..255 colors (assuming bytesPixel == 4). // // for (int dy = y; dy < y + h; dy++) {
// // int i = 0; // // for (int dx = x; dx < x + w; dx++) {
// // for (int dy = y; dy < y + h; dy++) { // // pixels24[dy * rfb.framebufferWidth + dx] = palette24[indexedData[i++] & 0xFF];
// // for (int dx = x; dx < x + w; dx++) { // // }
// // pixels24[dy * rfb.framebufferWidth + dx] = palette24[indexedData[i++] & 0xFF]; // // }
// // } // // }
// // } // } else if useGradient {
// // } // // "Gradient"-processed data
// } else if useGradient { // //buf := make ( []byte,w * h * 3);
// // "Gradient"-processed data // dataByteCount := int(3) * int(rect.Width) * int(rect.Height)
// //buf := make ( []byte,w * h * 3); // readBytes(conn.c, dataByteCount)
// dataByteCount := int(3) * int(rect.Width) * int(rect.Height) // // rfb.readFully(buf);
// readBytes(conn.c, dataByteCount) // // if (rfb.rec != null) {
// // rfb.readFully(buf); // // rfb.rec.write(buf);
// // if (rfb.rec != null) { // // }
// // rfb.rec.write(buf); // // decodeGradientData(x, y, w, h, buf);
// // } // } else {
// // decodeGradientData(x, y, w, h, buf); // // Raw truecolor data.
// } else { // dataByteCount := int(bytesPixel) * int(rect.Width) * int(rect.Height)
// // Raw truecolor data. // readBytes(conn.c, dataByteCount)
// dataByteCount := int(bytesPixel) * int(rect.Width) * int(rect.Height)
// readBytes(conn.c, dataByteCount) // // if (bytesPixel == 1) {
// // for (int dy = y; dy < y + h; dy++) {
// // if (bytesPixel == 1) {
// // for (int dy = y; dy < y + h; dy++) { // // rfb.readFully(pixels8, dy * rfb.framebufferWidth + x, w);
// // if (rfb.rec != null) {
// // rfb.readFully(pixels8, dy * rfb.framebufferWidth + x, w); // // rfb.rec.write(pixels8, dy * rfb.framebufferWidth + x, w);
// // if (rfb.rec != null) { // // }
// // rfb.rec.write(pixels8, dy * rfb.framebufferWidth + x, w); // // }
// // } // // } else {
// // } // // byte[] buf = new byte[w * 3];
// // } else { // // int i, offset;
// // byte[] buf = new byte[w * 3]; // // for (int dy = y; dy < y + h; dy++) {
// // int i, offset; // // rfb.readFully(buf);
// // for (int dy = y; dy < y + h; dy++) { // // if (rfb.rec != null) {
// // rfb.readFully(buf); // // rfb.rec.write(buf);
// // if (rfb.rec != null) { // // }
// // rfb.rec.write(buf); // // offset = dy * rfb.framebufferWidth + x;
// // } // // for (i = 0; i < w; i++) {
// // offset = dy * rfb.framebufferWidth + x; // // pixels24[offset + i] = (buf[i * 3] & 0xFF) << 16 | (buf[i * 3 + 1] & 0xFF) << 8 | (buf[i * 3 + 2] & 0xFF);
// // for (i = 0; i < w; i++) { // // }
// // pixels24[offset + i] = (buf[i * 3] & 0xFF) << 16 | (buf[i * 3 + 1] & 0xFF) << 8 | (buf[i * 3 + 2] & 0xFF); // // }
// // } // // }
// // } // }
// // } // } else {
// } // // Data was compressed with zlib.
// } else { // zlibDataLen, err := readCompactLen(conn.c)
// // Data was compressed with zlib. // fmt.Printf("compactlen=%d\n", zlibDataLen)
// zlibDataLen, err := readCompactLen(conn.c) // if err != nil {
// fmt.Printf("compactlen=%d\n", zlibDataLen) // return nil, err
// if err != nil { // }
// return nil, err // //byte[] zlibData = new byte[zlibDataLen];
// } // //rfb.readFully(zlibData);
// //byte[] zlibData = new byte[zlibDataLen]; // readBytes(conn.c, zlibDataLen)
// //rfb.readFully(zlibData);
// readBytes(conn.c, zlibDataLen) // // if (rfb.rec != null) {
// // rfb.rec.write(zlibData);
// // if (rfb.rec != null) { // // }
// // rfb.rec.write(zlibData); // // int stream_id = comp_ctl & 0x03;
// // } // // if (tightInflaters[stream_id] == null) {
// // int stream_id = comp_ctl & 0x03; // // tightInflaters[stream_id] = new Inflater();
// // if (tightInflaters[stream_id] == null) { // // }
// // tightInflaters[stream_id] = new Inflater(); // // Inflater myInflater = tightInflaters[stream_id];
// // } // // myInflater.setInput(zlibData);
// // Inflater myInflater = tightInflaters[stream_id]; // // byte[] buf = new byte[dataSize];
// // myInflater.setInput(zlibData); // // myInflater.inflate(buf);
// // byte[] buf = new byte[dataSize]; // // if (rfb.rec != null && !rfb.recordFromBeginning) {
// // myInflater.inflate(buf); // // rfb.recordCompressedData(buf);
// // if (rfb.rec != null && !rfb.recordFromBeginning) { // // }
// // rfb.recordCompressedData(buf);
// // } // // if (numColors != 0) {
// // // Indexed colors.
// // if (numColors != 0) { // // if (numColors == 2) {
// // // Indexed colors. // // // Two colors.
// // if (numColors == 2) { // // if (bytesPixel == 1) {
// // // Two colors. // // decodeMonoData(x, y, w, h, buf, palette8);
// // if (bytesPixel == 1) { // // } else {
// // decodeMonoData(x, y, w, h, buf, palette8); // // decodeMonoData(x, y, w, h, buf, palette24);
// // } else { // // }
// // decodeMonoData(x, y, w, h, buf, palette24); // // } else {
// // } // // // More than two colors (assuming bytesPixel == 4).
// // } else { // // int i = 0;
// // // More than two colors (assuming bytesPixel == 4). // // for (int dy = y; dy < y + h; dy++) {
// // int i = 0; // // for (int dx = x; dx < x + w; dx++) {
// // for (int dy = y; dy < y + h; dy++) { // // pixels24[dy * rfb.framebufferWidth + dx] = palette24[buf[i++] & 0xFF];
// // for (int dx = x; dx < x + w; dx++) { // // }
// // pixels24[dy * rfb.framebufferWidth + dx] = palette24[buf[i++] & 0xFF]; // // }
// // } // // }
// // } // // } else if (useGradient) {
// // } // // // Compressed "Gradient"-filtered data (assuming bytesPixel == 4).
// // } else if (useGradient) { // // decodeGradientData(x, y, w, h, buf);
// // // Compressed "Gradient"-filtered data (assuming bytesPixel == 4). // // } else {
// // decodeGradientData(x, y, w, h, buf); // // // Compressed truecolor data.
// // } else { // // if (bytesPixel == 1) {
// // // Compressed truecolor data. // // int destOffset = y * rfb.framebufferWidth + x;
// // if (bytesPixel == 1) { // // for (int dy = 0; dy < h; dy++) {
// // int destOffset = y * rfb.framebufferWidth + x; // // System.arraycopy(buf, dy * w, pixels8, destOffset, w);
// // for (int dy = 0; dy < h; dy++) { // // destOffset += rfb.framebufferWidth;
// // System.arraycopy(buf, dy * w, pixels8, destOffset, w); // // }
// // destOffset += rfb.framebufferWidth; // // } else {
// // } // // int srcOffset = 0;
// // } else { // // int destOffset, i;
// // int srcOffset = 0; // // for (int dy = 0; dy < h; dy++) {
// // int destOffset, i; // // myInflater.inflate(buf);
// // for (int dy = 0; dy < h; dy++) { // // destOffset = (y + dy) * rfb.framebufferWidth + x;
// // myInflater.inflate(buf); // // for (i = 0; i < w; i++) {
// // destOffset = (y + dy) * rfb.framebufferWidth + x; // // pixels24[destOffset + i] = (buf[srcOffset] & 0xFF) << 16 | (buf[srcOffset + 1] & 0xFF) << 8
// // for (i = 0; i < w; i++) { // // | (buf[srcOffset + 2] & 0xFF);
// // pixels24[destOffset + i] = (buf[srcOffset] & 0xFF) << 16 | (buf[srcOffset + 1] & 0xFF) << 8 // // srcOffset += 3;
// // | (buf[srcOffset + 2] & 0xFF); // // }
// // srcOffset += 3; // // }
// // } // // }
// // } // // }
// // } // }
// // }
// } return
}
return
}

13
main.go
View File

@ -4,9 +4,10 @@ import (
"fmt" "fmt"
"net" "net"
"time" "time"
"vncproxy/client"
"vncproxy/common" "vncproxy/common"
"vncproxy/encodings" "vncproxy/encodings"
"vncproxy/client" listeners "vncproxy/tee-listeners"
) )
func main() { func main() {
@ -21,11 +22,18 @@ func main() {
authArr := []client.ClientAuth{&client.PasswordAuth{Password: "Ch_#!T@8"}, &noauth} authArr := []client.ClientAuth{&client.PasswordAuth{Password: "Ch_#!T@8"}, &noauth}
vncSrvMessagesChan := make(chan common.ServerMessage) vncSrvMessagesChan := make(chan common.ServerMessage)
rec := listeners.NewRecorder("c:/Users/betzalel/recording.rbs")
split := &listeners.MultiListener{}
split.AddListener(rec)
clientConn, err := client.Client(nc, clientConn, err := client.Client(nc,
&client.ClientConfig{ &client.ClientConfig{
Auth: authArr, Auth: authArr,
ServerMessageCh: vncSrvMessagesChan, ServerMessageCh: vncSrvMessagesChan,
Exclusive: true, Exclusive: true,
Listener: split,
}) })
if err != nil { if err != nil {
@ -37,6 +45,7 @@ func main() {
// } // }
tight := encodings.TightEncoding{} tight := encodings.TightEncoding{}
tightPng := encodings.TightPngEncoding{}
//rre := encodings.RREEncoding{} //rre := encodings.RREEncoding{}
//zlib := encodings.ZLibEncoding{} //zlib := encodings.ZLibEncoding{}
//zrle := encodings.ZRLEEncoding{} //zrle := encodings.ZRLEEncoding{}
@ -47,7 +56,7 @@ func main() {
// defer file.Close() // defer file.Close()
//tight.SetOutput(file) //tight.SetOutput(file)
clientConn.SetEncodings([]common.Encoding{&cpyRect, &tight}) clientConn.SetEncodings([]common.Encoding{&cpyRect, &tightPng, &tight})
go func() { go func() {
for { for {

View File

@ -3,6 +3,7 @@ package server
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"vncproxy/common"
"io" "io"
) )
@ -126,7 +127,7 @@ func ServerSecurityHandler(cfg *ServerConfig, c *ServerConn) error {
} }
func ServerServerInitHandler(cfg *ServerConfig, c *ServerConn) error { func ServerServerInitHandler(cfg *ServerConfig, c *ServerConn) error {
srvInit := &ServerInit{ srvInit := &common.ServerInit{
FBWidth: c.Width(), FBWidth: c.Width(),
FBHeight: c.Height(), FBHeight: c.Height(),
PixelFormat: *c.PixelFormat(), PixelFormat: *c.PixelFormat(),

View File

@ -19,12 +19,7 @@ var DefaultClientMessages = []common.ClientMessage{
&ClientCutText{}, &ClientCutText{},
} }
type ServerInit struct {
FBWidth, FBHeight uint16
PixelFormat common.PixelFormat
NameLength uint32
NameText []byte
}
//var _ Conn = (*ServerConn)(nil) //var _ Conn = (*ServerConn)(nil)

View File

@ -8,22 +8,25 @@ import (
"os" "os"
"time" "time"
"vncproxy/common" "vncproxy/common"
"vncproxy/server"
) )
type Recorder struct { type Recorder struct {
//common.BytesListener //common.BytesListener
RBSFileName string RBSFileName string
writer *os.File writer *os.File
logger common.Logger logger common.Logger
startTime int startTime int
buffer bytes.Buffer buffer bytes.Buffer
serverInitMessage *common.ServerInit
sessionStartWritten bool
} }
func getNowMillisec() int { func getNowMillisec() int {
return int(time.Now().UnixNano() / int64(time.Millisecond)) return int(time.Now().UnixNano() / int64(time.Millisecond))
} }
func NewRecorder(saveFilePath string, desktopName string, fbWidth uint16, fbHeight uint16) *Recorder { func NewRecorder(saveFilePath string) *Recorder {
//delete file if it exists //delete file if it exists
if _, err := os.Stat(saveFilePath); err == nil { if _, err := os.Stat(saveFilePath); err == nil {
os.Remove(saveFilePath) os.Remove(saveFilePath)
@ -33,16 +36,25 @@ func NewRecorder(saveFilePath string, desktopName string, fbWidth uint16, fbHeig
var err error var err error
rec.writer, err = os.OpenFile(saveFilePath, os.O_RDWR|os.O_CREATE, 0755) rec.writer, err = os.OpenFile(saveFilePath, os.O_RDWR|os.O_CREATE, 0755)
rec.writeStartSession(desktopName, fbWidth, fbHeight)
if err != nil { if err != nil {
fmt.Printf("unable to open file: %s, error: %v", saveFilePath, err) fmt.Printf("unable to open file: %s, error: %v", saveFilePath, err)
return nil return nil
} }
return &rec return &rec
} }
// func (rec *Recorder) startSession(desktopName string, fbWidth uint16, fbHeight uint16) error {
// err := rec.writeStartSession(desktopName, fbWidth, fbHeight)
// if err != nil {
// fmt.Printf("Recorder was unable to write StartSession to file error: %v", err)
// return nil
// }
// return nil
// }
const versionMsg_3_3 = "RFB 003.003\n" const versionMsg_3_3 = "RFB 003.003\n"
const versionMsg_3_7 = "RFB 003.007\n" const versionMsg_3_7 = "RFB 003.007\n"
const versionMsg_3_8 = "RFB 003.008\n" const versionMsg_3_8 = "RFB 003.008\n"
@ -61,7 +73,11 @@ const (
// // df.write("FBS 001.000\n".getBytes()); // // df.write("FBS 001.000\n".getBytes());
// } // }
func (r *Recorder) writeStartSession(desktopName string, framebufferWidth uint16, framebufferHeight uint16) error { func (r *Recorder) writeStartSession(initMsg *common.ServerInit) error {
desktopName := string(initMsg.NameText)
framebufferWidth := initMsg.FBWidth
framebufferHeight := initMsg.FBHeight
//write rfb header information (the only part done without the [size|data|timestamp] block wrapper) //write rfb header information (the only part done without the [size|data|timestamp] block wrapper)
r.buffer.WriteString("FBS 001.000\n") r.buffer.WriteString("FBS 001.000\n")
@ -90,6 +106,9 @@ func (r *Recorder) writeStartSession(desktopName string, framebufferWidth uint16
func (r *Recorder) Consume(data *common.RfbSegment) error { func (r *Recorder) Consume(data *common.RfbSegment) error {
switch data.SegmentType { switch data.SegmentType {
case common.SegmentMessageSeparator: case common.SegmentMessageSeparator:
if !r.sessionStartWritten {
r.writeStartSession(r.serverInitMessage)
}
switch common.ServerMessageType(data.UpcomingObjectType) { switch common.ServerMessageType(data.UpcomingObjectType) {
case common.FramebufferUpdate: case common.FramebufferUpdate:
r.writeToDisk() r.writeToDisk()
@ -105,6 +124,18 @@ func (r *Recorder) Consume(data *common.RfbSegment) error {
case common.SegmentBytes: case common.SegmentBytes:
_, err := r.buffer.Write(data.Bytes) _, err := r.buffer.Write(data.Bytes)
return err return err
case common.SegmentServerInitMessage:
r.serverInitMessage = data.Message.(*common.ServerInit)
case common.SegmentFullyParsedClientMessage:
clientMsg := data.Message.(common.ClientMessage)
switch clientMsg.Type() {
case common.SetPixelFormatMsgType:
clientMsg := data.Message.(*server.SetPixelFormat)
r.serverInitMessage.PixelFormat = clientMsg.PF
default:
return errors.New("unknown client message type:" + string(data.UpcomingObjectType))
}
default: default:
return errors.New("undefined RfbSegment type") return errors.New("undefined RfbSegment type")

View File

@ -6,11 +6,11 @@ import (
"vncproxy/common" "vncproxy/common"
) )
type PassListener struct { type WriteToListener struct {
io.Writer io.Writer
} }
func (p *PassListener) Consume(seg *common.RfbSegment) error { func (p *WriteToListener) Consume(seg *common.RfbSegment) error {
switch seg.SegmentType { switch seg.SegmentType {
case common.SegmentMessageSeparator: case common.SegmentMessageSeparator:
case common.SegmentRectSeparator: case common.SegmentRectSeparator: