grdp

module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: GPL-3.0

README

Golang Remote Desktop Protocol

grdp is a pure Go client implementation of Microsoft's Remote Desktop Protocol.

Forked from tomatome/grdp, itself forked from icodeface/grdp.

Status

The connection, authentication, rendering and input paths are implemented and have been verified against real servers. The graphics paths that newer servers prefer are not done yet.

Verified against xrdp 0.9.24 and against a real Windows 10 host:

  • Connection, MCS, capability exchange
  • TLS and NLA (CredSSP with NTLMv2, including the version 6 public key binding)
  • Licensing exchange
  • Bitmap updates, RLE, 24 and 32 bpp
  • Pointer position and pointer shape updates
  • Keyboard and mouse input, including modifier keys
  • Clipboard, text, both directions
  • NSCodec and RemoteFX (RFX) bitmap codecs, checked byte for byte against libfreerdp's own decoder
  • ZGFX, the bulk compression the EGFX channel wraps its messages in, also checked byte for byte against libfreerdp, including against captures of real Windows traffic
  • Surface commands, drdynvc, RDPGFX command parsing
  • EGFX (RDPGFX) rendering, verified against a real Windows server: the desktop, its icons and text come through over the graphics channel with no bitmap updates at all. Off by default, see below.

Not done:

  • RemoteFX Progressive (codec ids 0x0009 and 0x000D), which needs its own arithmetic decoder. The THINCLIENT capability flag asks the server not to use it, and the dispatch error names it if a server does anyway.
  • Orders and the bitmap cache. xrdp never sends orders, so this path is only needed for Windows' partial updates.
  • Interleaved RLE bitmaps, which the bitmap cache revision 3 needs.
  • H.264 (AVC420 / AVC444) codecs, which EGFX servers may choose. Not advertising them is what keeps them out of the negotiation.
  • Scaled surface placement: a surface mapped with scale factors would need resampling. MapSurfaceToOutput is honoured, the scaled variants are not.
  • VNC. The RFB subset this fork inherited is unused and unverified.

Using it as a library

s := client.NewSetting()
s.Width, s.Height = 1024, 768
s.Protocol = "nla"           // "tls" or "nla"

c := client.NewClient("host:3389", "user", "password", client.TC_RDP, s)
c.OnBitmap(func(bs []client.Bitmap) { /* paint */ })
c.OnClipboardText(func(text string) { /* paste */ })
if err := c.Login(); err != nil {
    log.Fatal(err)
}
c.KeyDown(0x1c, "")
c.KeyUp(0x1c, "")

Setting.EnableClipboard opens the clipboard channel, and Setting.EnableEGFX opts into the graphics channel described above. EGFX is off by default because a server that picks it stops sending bitmap updates: with it on, an unsupported codec means a blank screen rather than a degraded one. Use OnSurfaceFrame to receive the surfaces and Surface.Origin to place them.

Trying it out

cmd/rdpcli is a headless client that connects, decodes, and writes what it received to a PNG. It is enough to check a server end to end:

go run ./cmd/rdpcli -host 192.0.2.10:3389 -user user -pass secret -proto nla \
    -wait 20s -dump /tmp/screen.png

# drive input and watch it land
go run ./cmd/rdpcli -host 192.0.2.10:3389 -user user -pass secret -proto nla \
    -wait 20s -dump /tmp/after.png -post-input 4s \
    -key click:400,600 -type 'echo hello' -key press:0x1c

Flags worth knowing: -type types a string (handling shift), -key sends raw input events, -clipboard and -set-clipboard exercise the clipboard, -pointer logs pointer updates, -log 0 is a full trace.

Development

scripts/dev-rdp.sh manages a local xrdp target for integration testing: setup (once, makes the rest passwordless), up, down, status, probe, and probe-session, which prepares a session whose X input events are logged so that input can be verified rather than eyeballed.

scripts/gen-codec-vectors.sh regenerates the codec test vectors from libfreerdp's encoders and decoders, so the image codecs are checked against a reference implementation rather than against hand written expectations. scripts/gen-zgfx-vectors.sh does the same for ZGFX, except that the streams come from our test encoder because FreeRDP's compressor is a stub; FreeRDP's decoder still supplies the expected output.

Take ideas from

Directories

Path Synopsis
client.go
client.go
cmd
rdpcli command
Command rdpcli is a small headless RDP client used to verify connectivity against a live server.
Command rdpcli is a small headless RDP client used to verify connectivity against a live server.
Package codec implements the bitmap codecs that RDP servers use to encode bitmap update and surface command payloads.
Package codec implements the bitmap codecs that RDP servers use to encode bitmap update and surface command payloads.
bitmap.go
bitmap.go
Package orders renders the drawing orders a server sends when the client says it supports them.
Package orders renders the drawing orders a server sends when the client says it supports them.
drdynvc
Package drdynvc implements the dynamic virtual channel channel (MS-RDPEDYC).
Package drdynvc implements the dynamic virtual channel channel (MS-RDPEDYC).
rail
rail.go
rail.go
rdpgfx
Package rdpgfx implements the RDP Graphics Pipeline Extension channel (MS-RDPEGFX), the modern drawing path where a server composites surfaces and sends them as compressed bitmaps.
Package rdpgfx implements the RDP Graphics Pipeline Extension channel (MS-RDPEGFX), the modern drawing path where a server composites surfaces and sends them as compressed bitmaps.
protocol
lic
nla
pdu
rfb
rfb.go
rfb.go
sec

Jump to

Keyboard shortcuts

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