Skip to content

Tooling

Lakeland97 edited this page Oct 29, 2026 · 19 revisions

Tooling

Everything here exists because a runtime probe is expensive: the guest is an x86-translated Windows VM, a launch takes minutes, and the client is single-instance. The tools split into a wire implementation, binary/pak utilities, dump readers, Frida scripts, and a probe harness.

mock_appserver.py

One file, ~1,000 lines, ThreadingHTTPServer, standard library only. It speaks haxe.remoting (__x in, hxr + serialized out), logs every request raw and decoded, and answers the non-remoting JSON legs.

Structure:

  • HANDSHAKE — the 25-field doHandshake config, including m_drm as an HxEnum.
  • SESSION_CTX — the eight-field session context (plus pgsToken); merged from GUL_CTX_EXTRA, reduced by GUL_CTX_MINIMAL, fields dropped by GUL_CTX_DROP.
  • PGS_PARTY — the generic party blob.
  • OP_REPLIES — 17 shape-bearing ops. Anything else hits UNKNOWN_OP and receives handshake_result_dsur(None), i.e. a generic success. That is deliberate: an unimplemented op must not stall the client.
  • _dsur(payload) — branch A by default, branch B when GUL_DSUR_B or the current op is in GUL_DSUR_B_OPS.
  • do_POST — routes /remoting/<conn>/<op>, the JSON legs, and the {} catch-all.

Env surface (grouped; every knob exists so a shape change is a restart, not an edit):

group variables
transport GUL_BASE, GUL_COMPRESS (none/zlib/deflate), GUL_SER_NOREF, GUL_SER_Z
handshake GUL_M_DRM, GUL_M_DRM_ARG, GUL_SERVER_ENV, GUL_COOLDOWN
session GUL_CTX_MINIMAL, GUL_CTX_EXTRA, GUL_CTX_DROP, GUL_CTX_PROVIDER_ENUM, GUL_CTX_PROVIDER_IDX, GUL_RCONF
branch B GUL_DSUR_B, GUL_DSUR_B_OPS, GUL_DSUR_DIRECT, GUL_DSUR_DIRECT_OPS, GUL_DSUR_DIRECT_VALUE
entities GUL_DSUR_ENTITIES, GUL_DSUR_ENTITIES_STR, GUL_DSUR_ENTITIES_RAW, GUL_DSUR_HX, GUL_DSUR_HX_BODY, GUL_DSUR_HX_CLASSES, GUL_DSUR_HX_TEMPLATE, GUL_DSUR_HX_PURPOSE, GUL_DSUR_HX_TAIL, GUL_DSUR_HX_EMPTY_TEMPLATE, GUL_DSUR_HX_COMPONENTS, GUL_DSUR_HX_COMPONENT, GUL_DSUR_HX_BAGS, GUL_DSUR_HX_PROP_*
store GUL_IID, GUL_IID_TEMPLATE, GUL_IID_TEMPLATE_BLOB, GUL_BLOB_JSON, GUL_BLOB_RAW, GUL_BLOB_INTMAP
PGS GUL_HEARTBEAT_SEC, GUL_USER_STAMP, GUL_USER_POLL_DELAY, GUL_USER_WATCH_STAMP, GUL_USER_WATCH_HOLD, GUL_PGS_ACCOUNTS
replay GUL_TRACK_PUSH_PLAYER, GUL_TRACK_DELAY, GUL_LOG_REQ

The _RAW knobs take wire text, not JSON. Passing ["x"] emits literal brackets; that produced Invalid char [ at position 140 in one round.

tools/haxe_ser.py

Serializer and deserializer for the game's wire format, plus the reply builders.

  • Tokens: n t f z i d k m p y R o g a h u r x b h — enough for observed traffic.
  • Serializer.value() handles dict → anonymous object or StringMap, list → array with u<n> null runs, str → y<len>:, HxEnum → w…, HxClass/HxInstance → declarations + T<idx>:.
  • RawFragment splices verbatim wire text. It is a str subclass, so its check must precede the String branch — a bug that once silently emitted ["x"] instead of x.
  • handshake_response(config) — [V decl][Result.Success(T0 instance)] (the older, one-value-first form).
  • handshake_result_dsur(config) — [n][Result.Success(DSUR)], the universal accepted form.
  • dsur_branch_b(config, entities, blob, extra_classes) — [n][Result.Success(DSUR)] with a non-empty updatedEntities, emitting the enum prefix first so the string table cannot shift.
  • result_success(value) — [n][Result.Success(value)] with no DSUR wrapper, for ops whose consumer reads the payload directly.

Limitations to know before using it: the Unserializer does not implement w (it reads captured requests), so a reply built here cannot be round-tripped; and r object references are not emitted.

tools/hxinflate.py

The hxInflate writer (Deflater.hx grammar) plus a host-side mirror of the reader (Inflater.hx) so payloads can be validated offline. Decl describes a class (name, base, version, custom, fields); Raw injects verbatim text. tests/test_hxinflate.py has 11 tests, including the ZVER3 header, IntMap raw-digit keys, StringMap vs anonymous object, and null runs.

hxinflate.py --decode is the tool used to walk templates.tplc: it validates that a payload decodes to exactly its declared length, which is how the account (36 B) and player (4,296 B) template extents were established.

Pak tools

tools/pakdump.py — UE4 v3 pak reader: index listing and extraction.

tools/pak_patch_url.py — same-length in-place URL patcher. Layout it relies on:

footer 44 B at EOF-44: magic 0x5A6F12E1, version, index_offset, index_size, sha1
index: FString mount, u32 count, then per entry
       FString path, u64 offset, u64 size, u64 csize, u16 method, u16 flags, sha1, 5 zero bytes
on-disk per-file header 53 B at entry.offset: same fields
compression none (v3), no encryption

It patches every occurrence of OLD with NEW (equal length required), refreshes the affected entries' sha1 in both the index and the on-disk header, and refreshes the footer index sha1. Fully reversible: run again with the arguments swapped.

Documented use:

python3 tools/pak_patch_url.py ".../hns-WindowsNoEditor.pak" \
    'https://api.playstreamline.com' 'http://127.0.0.1:8096/////////'

The trailing slashes pad the replacement to the original length; the client's URL join supplies the rest.

Binary utilities

tool purpose
tools/fix_pe_checksum.py MS checksum: zero PE+0x58, 16-bit LE sum with carry fold, add file length once. --check prints stored/computed/delta and exits non-zero on mismatch. Two entry points (scripts/ wrapper, tools/ implementation)
scripts/va2off.py section-aware VA ↔ file offset, prints the bytes at the site. The only sanctioned mapping: .text −0xC00, .rdata −0xE00
scripts/callers.py, rea_callers.py, rea_xref.py, rea_ptrscan.py, rea_funcinfo.py call-site and xref scans over an objdump listing or the Ghidra project
scripts/pe_strings.py, tools/u16scan.py ASCII / UTF-16LE string extraction
scripts/fstring_scan.py find FString literals by {Data, Num, Max} shape
tools/unwind.py, stackscan.py, throwscan.py unwind metadata, stack-frame scanning, throw-site scanning
tools/mdread.py minidump reader: exception record, threads, modules, raw stack scan for return addresses inside a module range
tools/memdump.py hexdump arbitrary addresses out of a minidump's memory ranges

mdread is what turned the frozen-joiner dump into the 24 anchors in GC; memdump then read the GC table entries live.

Frida scripts

Attach target 192.168.64.3:27042.

script purpose
frida_fatal.py attach and report the C++ exception + UE fatal stacks (FATAL_RVA 0x1374C50)
frida_wait_hook.py sample wait states; used to collect the freeze anchors
frida_gc_unwind.py read both GC ThreadInfo entries with live thread contexts
frida_findmatch.py drive the FIND MATCH path in process
frida_quickmatch.py quickmatch objects from a Frida thread (thread-affine; superseded)
frida_spawn_travel.py native ClientTravel call (Joining)

The native-call scripts exist because UI automation failed: synthetic mouse events never reach Slate, and scheduled-task coordinates are not client-relative.

Probe harness

item role
scripts/probe_watch.sh the completion signal. Watches the guest log and the mock log, prints terminal login/crash events and new requests, exits on the first fatal
scripts/probe.sh, probe_batch.sh, probe_reel.sh single probe, batch of variants, and a serial reel that runs one verdict at a time
scripts/batches/, runtime/.batch_commands.* the variant lists used for payload bisection
scripts/plain_run.sh the standard launch arguments
scripts/vmssh.sh, guest_log.sh guest access and log pull
scripts/watchdog.ps1, install_watchdog.bat, watchdog_task.xml in-guest hang watchdog (kills a spinning client so the rig is not lost)
tools/mute_guest.ps1 asserts MUTED=True before any launch
tools/set_tutorial_false.ps1 clears PlayedTutorial (settings reset)
tools/listen_engine.ini, join_engine.ini the two net-timeout / map configurations
scripts/freeze_census_log.sh freezes the mock log to a prefix so census tests stop depending on a growing file
scripts/restart_census.py, replypos.py restart classification and reply-position analysis
scripts/autopilot.sh, cattle_prod.sh hourly bounded autopilot and the watchdog that keeps the session alive (launchd, stable copies under ~/.local/share/streamline/)

The rig is single-writer: runtime/rig.lockdir is held around any probe and released on exit. Two sessions racing without it produced two concurrent reels and void results (R901/R902).

Tests

Entry point python3 tests/run_all.py. The set is offline-only: serializer round-trips, entity payloads, mock reply shapes, login-gate contracts, log-census invariants. No test launches the game.

test covers
test_haxe_ser_decode captured request bodies, token coverage
test_hxinflate writer/reader symmetry, header, IntMap, null runs
test_mock_branch_b branch A/B envelopes, entity-only contract, template negative control
test_tpl_entity_payload the player template entity body, offline
test_login_gate_contract the eight-field context, playerIID, seven-value body (tolerating the eight-value trailer)
test_tracking_reply tracking reply shape
test_unknown_op generic-success fallback
test_post_tutorial_entry, test_tutorial_gamestate, test_fakeid_identity offline-path and DRM contract pins

Counts moved as tests were added: 12 (branch B), 48 (public tree, bare checkout), 141, 151, 166. The public tree runs standalone: every artifact-dependent test skips cleanly with no game/, no runtime/, no exe and no Ghidra project.

Test fragility was a recurring cost (three incidents). The fix pattern is the same each time: pin the property, not a threshold measured against a log that grows with every run. Both log-census tests now read a frozen prefix and separately assert structural soundness on the live log.

Guest automation traps

trap effect workaround
input lands in session 0 clicks never reach the desktop interactive scheduled task, not schtasks /Run from a service context
AMSI / Defender PowerShell tasks report Last Result: 1 and write nothing, looking like "never ran" Defender off + exclusion path + DefendNot run as SYSTEM
task stuck in Running every later /Run is a silent no-op schtasks /End and kill the stray session-0 cmd.exe by PID
schtasks /End does not kill the child the task spawned kill by PID from a fresh tasklist
single-instance guard a new launch silently does nothing kill the running instance first, verify the list is empty
log renamed while open the game keeps writing to the renamed file, so the new log looks stale restart rather than rename
utmctl exec returns no stdout guest agent path unreachable even for echo SSH; if both fail, guest-side work is blocked
Steam/CEF overlay ms-gamingoverlay popups steal focus per-user no-op URI handler (noop.exe "%1")

Evidence

tools/*.py docstrings, scripts/*.sh, runtime/MOCK_OP_COVERAGE.md, runtime/CONSOLE_REACHABILITY.md §5, MODLOG.md R791–R792 (AMSI, screenshots, input), R895 (SSH/Game Bar), R901–R917 (harness failures), R1008 (public-tree verification).

Clone this wiki locally