core

package
v0.8.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: GPL-3.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToUint64

func BytesToUint64(b []byte) uint64

BytesToUint64 reads a little endian 64 bit value from a byte slice.

func CVAL

func CVAL(p *[]uint8) int

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 CVAL2

func CVAL2(p *[]uint8, v *uint16)

CVAL2 reads a little endian 16 bit value from a cursor.

func CVAL3

func CVAL3(p *[]uint8, v *[3]uint8)

CVAL3 reads three bytes from a cursor.

func Decompress

func Decompress(input []uint8, width, height int, Bpp int) ([]uint8, error)

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

func LittleEndianBytesToUTF16(u []byte) []uint16

LittleEndianBytesToUTF16 reinterprets little endian bytes as UTF-16 code units.

func PutUint16BE

func PutUint16BE(data uint16) (uint8, uint8)

PutUint16BE splits a value into its two big endian bytes.

func REPEAT

func REPEAT(f func(), count *int, x *int, width int)

REPEAT calls f once per pixel of a run, eight at a time while the run is long enough, stopping at width.

func RGB555ToRGB

func RGB555ToRGB(data uint16) (r, g, b uint8)

RGB555ToRGB expands a 5-5-5 packed colour to eight bits per channel, with the same truncating expansion and the same load bearing parentheses as RGB565ToRGB.

func RGB565ToRGB

func RGB565ToRGB(data uint16) (r, g, b uint8)

RGB565ToRGB expands a 5-6-5 packed colour to eight bits per channel. The parentheses are load bearing for the reader rather than for the parser: & and >> have the same precedence and associate left, so the unparenthesised form already means (data & mask) >> shift. That is not obvious, and an obvious looking "fix" of it breaks the colours. The expansion truncates, so full scale comes out as 248 rather than 255.

func Random

func Random(n int) []byte

Random returns n cryptographically random bytes.

func ReadByte

func ReadByte(r io.Reader) (byte, error)

ReadByte reads one byte.

func ReadBytes

func ReadBytes(length int, r io.Reader) ([]byte, error)

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 ReadUInt8

func ReadUInt8(r io.Reader) (uint8, error)

ReadUInt8 reads one unsigned byte.

func ReadUInt32BE

func ReadUInt32BE(r io.Reader) (uint32, error)

ReadUInt32BE reads a big endian 32 bit unsigned integer.

func ReadUInt32LE

func ReadUInt32LE(r io.Reader) (uint32, error)

ReadUInt32LE reads a little endian 32 bit unsigned integer.

func ReadUint16BE

func ReadUint16BE(r io.Reader) (uint16, error)

ReadUint16BE reads a big endian 16 bit unsigned integer.

func ReadUint16LE

func ReadUint16LE(r io.Reader) (uint16, error)

ReadUint16LE reads a little endian 16 bit unsigned integer.

func Reverse

func Reverse(s []byte) []byte

Reverse returns s with its bytes in the opposite order.

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

func UTF16ToLittleEndianBytes(u []uint16) []byte

UTF16ToLittleEndianBytes converts UTF-16 code units to their little endian byte representation.

func Uint16BE

func Uint16BE(d0, d1 uint8) uint16

Uint16BE joins two big endian bytes into a 16 bit value.

func UnicodeDecode

func UnicodeDecode(p []byte) string

UnicodeDecode decodes UTF-16 little endian bytes back to a string.

func UnicodeEncode

func UnicodeEncode(p string) []byte

s.encode('utf-16le')

func WriteByte

func WriteByte(data byte, w io.Writer) (int, error)

WriteByte writes one byte and reports how many it wrote.

func WriteBytes

func WriteBytes(data []byte, w io.Writer) (int, error)

WriteBytes writes a slice and reports how many bytes it wrote.

func WriteUInt8

func WriteUInt8(data uint8, w io.Writer) (int, error)

WriteUInt8 writes one unsigned byte.

func WriteUInt16BE

func WriteUInt16BE(data uint16, w io.Writer) (int, error)

WriteUInt16BE writes a big endian 16 bit unsigned integer.

func WriteUInt16LE

func WriteUInt16LE(data uint16, w io.Writer) (int, error)

WriteUInt16LE writes a little endian 16 bit unsigned integer.

func WriteUInt32BE

func WriteUInt32BE(data uint32, w io.Writer) (int, error)

WriteUInt32BE writes a big endian 32 bit unsigned integer.

func WriteUInt32LE

func WriteUInt32LE(data uint32, w io.Writer) (int, error)

WriteUInt32LE writes a little endian 32 bit unsigned integer.

Types

type ChannelSender

type ChannelSender interface {
	SendToChannel(channel string, s []byte) (int, error)
}

ChannelSender writes to a named virtual channel.

type FastPathListener

type FastPathListener interface {
	RecvFastPath(secFlag byte, s []byte)
}

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

type ReadBytesComplete func(result []byte, err error)

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.

func (*SocketLayer) Write

func (s *SocketLayer) Write(b []byte) (n int, err error)

Write implements the Transport interface.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL