Documentation
¶
Overview ¶
Package core is the layer everything else is built on: bounded readers and writers over io.Reader and io.Writer, a net.Conn wrapper that can be upgraded to TLS, small string and pixel conversions, and the RLE bitmap decompressor.
The read and write helpers (ReadBytes, ReadUint16LE, WriteUInt32BE and the rest) read and write exactly the bytes they name and say which endianness they use, because the protocol mixes both.
Traps:
- Decompress sizes its output from the width, height and bytes per pixel it is given, so those must come from a bounded source; it also applies its own ceiling. On malformed input it returns the part that decoded together with an error, and only the interleaved form can tell that a stream ended early, so a nil error does not always mean a complete picture.
- StartReadBytes runs its callback on a new goroutine and calls it exactly once, including on error; the callback must not assume it runs on the caller's goroutine.
Index ¶
- func BytesToUint64(b []byte) uint64
- func CVAL(p *[]uint8) int
- func CVAL2(p *[]uint8, v *uint16)
- func CVAL3(p *[]uint8, v *[3]uint8)
- func Decompress(input []uint8, width, height int, Bpp int) ([]uint8, error)
- func LittleEndianBytesToUTF16(u []byte) []uint16
- func PutUint16BE(data uint16) (uint8, uint8)
- func REPEAT(f func(), count *int, x *int, width int)
- func RGB555ToRGB(data uint16) (r, g, b uint8)
- func RGB565ToRGB(data uint16) (r, g, b uint8)
- func Random(n int) []byte
- func ReadByte(r io.Reader) (byte, error)
- func ReadBytes(length int, r io.Reader) ([]byte, error)
- func ReadUInt8(r io.Reader) (uint8, error)
- func ReadUInt32BE(r io.Reader) (uint32, error)
- func ReadUInt32LE(r io.Reader) (uint32, error)
- func ReadUint16BE(r io.Reader) (uint16, error)
- func ReadUint16LE(r io.Reader) (uint16, error)
- func Reverse(s []byte) []byte
- func StartReadBytes(length int, r io.Reader, cb ReadBytesComplete)
- func UTF16ToLittleEndianBytes(u []uint16) []byte
- func Uint16BE(d0, d1 uint8) uint16
- func UnicodeDecode(p []byte) string
- func UnicodeEncode(p string) []byte
- func WriteByte(data byte, w io.Writer) (int, error)
- func WriteBytes(data []byte, w io.Writer) (int, error)
- func WriteUInt8(data uint8, w io.Writer) (int, error)
- func WriteUInt16BE(data uint16, w io.Writer) (int, error)
- func WriteUInt16LE(data uint16, w io.Writer) (int, error)
- func WriteUInt32BE(data uint32, w io.Writer) (int, error)
- func WriteUInt32LE(data uint32, w io.Writer) (int, error)
- type ChannelSender
- type FastPathListener
- type FastPathSender
- type PublicKey
- type ReadBytesComplete
- type SocketLayer
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToUint64 ¶
BytesToUint64 reads a little endian 64 bit value from a byte slice.
func CVAL ¶
CVAL reads one byte from a cursor and advances it. An exhausted cursor yields zero rather than a panic, so a decoder that reads past the end has to notice that it is making no progress: a zero byte decodes as a run of nothing.
func Decompress ¶
Decompress decodes one RDP 6.0 compressed bitmap. Bpp is bytes per pixel: 1, 2, 3 or 4 for 8, 16, 24 and 32 bits.
It returns whatever it decoded along with an error when it can tell the input is malformed, rather than a buffer of zeros. That distinction matters: a truncated stream used to leave the interleaved decoder spinning on a zero byte, which decodes as a run of nothing and so advances nothing. Callers can still render the partial result, but they can tell that it is partial.
Only the interleaved form reports an error for a stream that ends early, since it carries an explicit size. The other three are terminated by the buffer ending, so ending early is not distinguishable from ending on purpose.
func LittleEndianBytesToUTF16 ¶
LittleEndianBytesToUTF16 reinterprets little endian bytes as UTF-16 code units.
func PutUint16BE ¶
PutUint16BE splits a value into its two big endian bytes.
func REPEAT ¶
REPEAT calls f once per pixel of a run, eight at a time while the run is long enough, stopping at width.
func RGB555ToRGB ¶
RGB555ToRGB expands a 5-5-5 packed colour to eight bits per channel.
func RGB565ToRGB ¶
RGB565ToRGB expands a 5-6-5 packed colour to eight bits per channel.
func ReadBytes ¶
ReadBytes reads exactly len bytes. On a short read it returns the bytes that were read together with io.ErrUnexpectedEOF (or io.EOF when none were read).
func ReadUInt32BE ¶
ReadUInt32BE reads a big endian 32 bit unsigned integer.
func ReadUInt32LE ¶
ReadUInt32LE reads a little endian 32 bit unsigned integer.
func ReadUint16BE ¶
ReadUint16BE reads a big endian 16 bit unsigned integer.
func ReadUint16LE ¶
ReadUint16LE reads a little endian 16 bit unsigned integer.
func StartReadBytes ¶
func StartReadBytes(length int, r io.Reader, cb ReadBytesComplete)
StartReadBytes reads exactly length bytes from r in a background goroutine and then invokes cb(result, err) exactly once.
On any error - including io.EOF and io.ErrUnexpectedEOF - cb is invoked with that error and no further reads are scheduled by this function. Callers are responsible for stopping their own read chain and surfacing the error.
NOTE: this used to loop forever on io.EOF, spinning the CPU and leaking the goroutine whenever the peer closed the connection.
func UTF16ToLittleEndianBytes ¶
UTF16ToLittleEndianBytes converts UTF-16 code units to their little endian byte representation.
func UnicodeDecode ¶
UnicodeDecode decodes UTF-16 little endian bytes back to a string.
func WriteBytes ¶
WriteBytes writes a slice and reports how many bytes it wrote.
func WriteUInt8 ¶
WriteUInt8 writes one unsigned byte.
func WriteUInt16BE ¶
WriteUInt16BE writes a big endian 16 bit unsigned integer.
func WriteUInt16LE ¶
WriteUInt16LE writes a little endian 16 bit unsigned integer.
func WriteUInt32BE ¶
WriteUInt32BE writes a big endian 32 bit unsigned integer.
Types ¶
type ChannelSender ¶
ChannelSender writes to a named virtual channel.
type FastPathListener ¶
FastPathListener receives a decoded fast path update.
type FastPathSender ¶
type FastPathSender interface {
SendFastPath(secFlag byte, s []byte) (int, error)
// SendFastPathInput writes a client-to-server fast-path input PDU. The
// first header byte carries both the action and the event count.
SendFastPathInput(numEvents byte, s []byte) (int, error)
}
FastPathSender sends a fast path update.
type PublicKey ¶
type PublicKey struct {
N *big.Int `asn1:"explicit,tag:0"` // modulus
E int `asn1:"explicit,tag:1"` // public exponent
}
PublicKey is an RSA public key as RDP carries it.
type ReadBytesComplete ¶
ReadBytesComplete is the callback a reader uses to hand back a completed message along with any error.
type SocketLayer ¶
type SocketLayer struct {
// contains filtered or unexported fields
}
SocketLayer is a Transport over a network connection, with the option of upgrading it to TLS. Reads and writes are not safe for concurrent use, which matches the single reader the protocol layers expect.
func NewSocketLayer ¶
func NewSocketLayer(conn net.Conn) *SocketLayer
NewSocketLayer wraps a connection, reading and writing directly until StartTLS is called.
func (*SocketLayer) Close ¶
func (s *SocketLayer) Close() error
Close closes the underlying connection.
func (*SocketLayer) Read ¶
func (s *SocketLayer) Read(b []byte) (n int, err error)
Read implements the Transport interface.
func (*SocketLayer) SetTLSConfig ¶
func (s *SocketLayer) SetTLSConfig(cfg *tls.Config)
SetTLSConfig overrides the TLS configuration used by StartTLS. When unset a default configuration is used that accepts the self-signed certificates RDP servers normally present. Callers that require verification should supply a config with InsecureSkipVerify=false and the appropriate RootCAs/ServerName.
func (*SocketLayer) StartTLS ¶
func (s *SocketLayer) StartTLS() error
StartTLS upgrades the connection to TLS, using the configuration the layer was created with.
func (*SocketLayer) TlsPubKey ¶
func (s *SocketLayer) TlsPubKey() ([]byte, error)
TlsPubKey returns the server's RSA public key in DER form, which is what CredSSP's version 5 and later binding hash is computed over. It is only meaningful after StartTLS.
type Transport ¶
type Transport interface {
Read(b []byte) (n int, err error)
Write(b []byte) (n int, err error)
Close() error
On(event, listener interface{}) *emission.Emitter
Once(event, listener interface{}) *emission.Emitter
Emit(event interface{}, arguments ...interface{}) *emission.Emitter
}
Transport is the byte stream a protocol layer sits on: a socket, or a TLS wrapper around one.