Reverse engineeringreference
Reverse engineering with a coding agent and headless Ghidra
A shipped binary has no source, and the questions about it concern behaviour its authors never documented. This page covers giving a coding agent a decompiler it can drive as tools, checking raw-firmware imports before trusting their output, and verifying the claims that reach a findings document. The worked examples answer “which protocol messages does this client handle”, “which peripheral does this function write”, and “what changed between these two images”.
The scope is static analysis of software the analyst is entitled to study: interoperability, protocol documentation, one’s own tooling. Mechanisms are read from the harness source and the reverse-engineering skill as of 2026-10-20, with versions and checksums copied from the installer. A re-check on 2026-10-31 found the server pin and tool count had moved (see Evidence); the 2026-10-20 figures below stay labelled with their date. The timeout, persistent-project and vendoring sections were added on 2026-11-12 from the MCP (Model Context Protocol) config, the installer and the REA (Reverse Engineer Anything) 6.7.0 package source. The porting section was added on 2026-11-18 from the harness test runs it reports. The worked example is read from the author’s Soulseek parity research notes of 2026-10-19. The raw-firmware results were measured on an nRF52840 mouse image and a CH32V305 + nRF52820 dongle image, 2026-11-20; their counts describe those images, not a project guarantee.
TL;DR:
- The decompiler is exposed as agent-callable tools, so the model reads pseudocode and cross-references instead of explaining a binary from a strings dump.
- The server exposes ~170 tools (2026-10-20), all
deferred: found through tool search when a task needs them, not declared every turn. - Ghidra 12.1.4 is installed by a script that checks a sha256 before unzipping, on top of JDK (Java Development Kit) 21. Re-running is idempotent.
- The skill is vendored verbatim from the server’s package and bumped together with the server pin.
- A big binary hits two deadlines: the harness’s per-request MCP timeout (60 s by default) and REA’s own Ghidra import-and-analysis deadline (330 s by default). Raising only the first one does not help.
- A second, persistent Ghidra MCP server keeps analysed projects on disk, so repeat questions about the same binary do not pay the analysis again.
- Raw firmware imports go through a checked CLI (command-line interface), and a harness guard blocks hand-assembled
analyzeHeadlesscommands. An earlier wrapper was bypassed in at least 10 sessions; the guard is active whether or not the agent remembers the CLI. - The CLI maps raw firmware images with MMIO (memory-mapped I/O) ranges read-only by default. On one mouse image this resolved 184 MMIO and 348 SRAM (static random-access memory) writes through literal-pool slots that a writable image left anonymous. Firmware that copies code to SRAM at boot needs those copies replayed in the import too, which a separate guide covers.
- Function-start searches, address-table repair and starts after literal pools raised one mouse image from 770 to 912 recovered functions with none lost; every new start was checked against the instruction bytes. Modelling
svcas a call restored itsr0result, and SVD (System View Description) data names peripheral registers. - Structured claims return
VERIFIED,REFUTEDorINCONCLUSIVEagainst the analysed program. A ground-truth set returned 23 true claims verified, 13 false claims refuted and one open claim inconclusive. - Patch comparison checks register arguments as well as pseudocode. It caught an
r1clobber that Ghidra rendered as a call with no arguments. - A community developer’s QingKe extension decoded all 645 WCH (WinChipHead) custom instructions in one dongle image with zero mismatches against an LLVM-checked decoder; stock Ghidra misdecoded all 645.
- The worked example built a feature-parity matrix from the official Soulseek client’s binary and two open-source clients, and found a server message code the public protocol documentation omits.
- A worker stops a helper process by recorded PID (process identifier).
pkill -fmatches the worker’s own command line and kills the worker. - A function ported to C goes through a blind translator, a reviewer on another model family reading Ghidra’s pseudocode, and an emulator test of the original machine code against the port.
Topology
Section titled “Topology”The agent starts with no reverse-engineering tools loaded and finds them through tool search when a task needs them. The MCP server wraps the REA package (rea-agents@6.4.0 on 2026-10-20) and locates Ghidra through GHIDRA_INSTALL_DIR and the JDK through JAVA_HOME. Raw firmware uses the checked CLI for imports, focused queries, claim verification and patch comparison. The binary is analysed statically and never executed.
Which tool for which job
Section titled “Which tool for which job”| You have | Reach for | Why |
|---|---|---|
| A question about a shipped binary or package (what protocol codes it handles, what a function does), for software you may study | The RE MCP server over headless Ghidra | Pseudocode, assembly and cross-references are the raw evidence, and the agent can query them as tools |
| An ordinary source repository, asking how the code behaves | Normal repo tools: read, grep, LSP | Source is authoritative and cheaper; the skill’s own routing says to skip RE for complete source |
| A rarely-used tool capability that only some sessions need | exposure: deferred, found via tool search | Declared schemas are a per-turn prompt cost on every request |
| Repeated questions about one large native binary across sessions | The persistent Ghidra MCP server (or its CLI) | The project and its finished analysis stay on disk; reopening is fast |
A first open_binary on a large binary that times out | Raise both deadlines (below), or run checked headless analysis in the background | The client timeout and REA’s analysis deadline are separate limits |
| Raw firmware with no container metadata | The checked CLI’s import command | Base address, language, entry seeds, volatile ranges and post-run function counts are explicit and checked |
| Bulk export, atomic claims, or a stock and patched firmware pair | The checked CLI’s run-script, verify or patch-diff command | One checked path owns the Ghidra log, analysis health, verdict counter-evidence and register-level patch checks |
| A worker that must stop a helper process it started (a headless analysis run gone long) | Record the PID to a file and kill by PID | pkill -f matches the worker’s own command line and kills the worker |
What static analysis answers
Section titled “What static analysis answers”Use reverse engineering when the question concerns a binary without source or usable documentation. In the worked example the question was what the official Soulseek client can do and which protocol messages each feature uses, and the vendor publishes none of it. Without a decompiler an agent can read strings and guess. With one it can name the symbol a message code reaches and read the pseudocode.
The skill’s boundary is the same: static analysis of software the analyst is entitled to study, never executing the target binary, no licence-circumvention work, no copied or pirated commercial software. The official client’s Linux build is analysed as a shipped artifact (it ships unstripped, with debug symbols) and is never run.
Why deferred
Section titled “Why deferred”The REA server exposes roughly 170 tools1. Every declared tool adds its name, description and parameter schema to each outgoing request. A worker’s first request used to carry about 77.5k prompt tokens with 139 tool schemas loaded across every MCP server, and a local single-lane engine re-prefilled all of it on every cache miss (measured in Which model runs which agent work).
Most turns need no reverse engineering, so declaring it every turn taxes all of them. With "exposure": "deferred" the server’s tools stay out of the per-turn list and the model fetches them through tool search. The entry keeps a description for the search to match: “native binaries via Ghidra (pseudocode, asm, xrefs), JS/Electron, .NET, APKs, SQLite, websites”. The server is also registered "enabled": false globally, and a project that does RE (reverse engineering) work carries a per-project override (mcp.json entry and VENDORED.md, read 2026-10-31).
Tool search solves discovery for MCP tools. It does not make a shell wrapper the default path: an earlier Ghidra batch wrapper was bypassed in at least 10 sessions between 2026-08-15 and 2026-11-20, even after the wrapper was named in the project’s instructions. The wrapper depended on the agent remembering to call it. The harness guard instead intercepts every matching shell command and blocks hand-assembled analyzeHeadless calls, while the checked CLI validates the run. (Session history and guard fixtures, 2026-11-20.)
Timeouts: two deadlines
Section titled “Timeouts: two deadlines”open_binary on a native binary runs Ghidra’s import and full auto-analysis before it returns. On a large binary that takes minutes, and two separate limits can cut it off:
- The harness’s MCP client gives each request a timeout, 60 s by default; progress notifications reset it2. The first
open_binaryon a 1.8 MB MFC (Microsoft Foundation Classes) executable timed out twice at that default. - REA has its own deadline for Ghidra to finish importing and analysing the target:
DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS = 330_000, overridable withREA_GHIDRA_STARTUP_TIMEOUT_MS1. Past it the call fails with “Ghidra did not finish importing and analyzing the target within its … ms startup deadline (REA_GHIDRA_STARTUP_TIMEOUT_MS)”.
Raising only the client timeout moves the failure from the client into REA. The server entry now sets both: a 900 s request timeout and REA_GHIDRA_STARTUP_TIMEOUT_MS=840000, so REA’s own error, which names the setting, arrives before the client gives up. It also gives the headless JVM (Java Virtual Machine) a 16 GB heap (GHIDRA_HEADLESS_MAXMEM). Anything still slower goes to a checked headless run in the background rather than a blocking tool call.
A persistent project for repeat work
Section titled “A persistent project for repeat work”In this setup each REA session analyses its target from scratch, so the second session on the same binary pays the whole analysis again. A second MCP server covers repeat work: a private fork of ghidra-mcp 7.1.03 with raw-firmware base-address and Thumb function-creation patches, installed by the same script with its own pinned sha256. It runs as a user service on a per-user Unix socket, never a TCP (Transmission Control Protocol) listener, and owns persistent Ghidra projects on disk. Its tools are deferred the same way. A small CLI over the same bridge (status, files, decompile, call-graph, plus a read-only smoke test) answers everyday questions without a model round-trip.
The paths split the work: REA for first contact with any artifact family (native, JavaScript, .NET, APK (Android package), SQLite), the persistent server for long-running work on one native binary, and the checked CLI for raw imports, bulk export, claim verification and patch comparison. One process may own a Ghidra project at a time. The CLI preflights the project lock and reports its holder instead of starting a competing JVM.
Checked headless analysis
Section titled “Checked headless analysis”Headless Ghidra (analyzeHeadless) remains the batch engine4. The checked CLI owns its argument construction and validates the result, because a shell command can exit 0 after producing an unusable project. Session history and 115 Ghidra logs supplied 18 failure classes; the most relevant ones here are:
| Failure | Why the run looked finished | Check in the CLI |
|---|---|---|
Made-up flags such as -base or deprecated language ids | Ghidra could warn and continue, or the agent could assume the image was loaded at the intended address | Construct arguments from validated CLI options; require --base for raw images and reject it for PE, ELF and Mach-O; fail on unknown-opinion and deprecation log lines |
Invalid processor or language ids such as ARM:LE:32:CortexM:v8 | Import continued with Using unknown opinion, then used a different variant | Validate against the installed .ldefs files and extensions; suggest close matches |
| Missing or wrong raw-image base addresses | Ghidra placed the image at zero or in its RAM (random-access memory) block | Derive the base from vector targets or explicit evidence; a file header does not provide it |
| MMIO blocks absent or not volatile | The decompiler folded peripheral writes into constants | Require a preset, SVD or explicit volatile ranges; mark peripheral blocks volatile |
| Raw imports with no entry point | Analysis exited 0 with zero functions | Require --entry or --vectors; fail when SeedEntry seeded=0 or DecompileAll ok=0 |
| Python post-scripts without PyGhidra | Scripts were skipped or failed in plain headless runs that exited 0 | Accept Java scripts only and treat every SCRIPT ERROR as fatal |
A Cortex-M import now has one checked shape:
ghidrakit import firmware.bin --project mouse-app \ --preset cortex-m --base 0x1c000 --vectorsThe checks continue after the JVM exits. info reports the language, load range, memory permissions, entry points and image hashes; the import log records the applied memory map, seeds, gp and recovered functions.
| Stage | What the CLI checks |
|---|---|
| Before the JVM | Raw versus container format, language ids, base-address rules, entry seeds, dot-prefixed project paths and lock holders, Java-only scripts, preset-specific language availability, and a heap budget derived from input size and available memory |
| Import log | Unknown loader opinions, deprecated options, missing language, lock errors, out-of-memory and every script error are fatal even when Ghidra exits 0 |
| Seeding and analysis | Entry seeds set Cortex-M Thumb mode; RISC-V gp context is derived before analysis; zero seeds and zero decompiled functions fail the run |
| Decompile health | Warnings are counted by class; warnings above 20% of decompiled functions fail by default, and --strict fails on any |
| Pseudocode against listing | decompile --with-asm places C beside disassembly and compares volatile MMIO store counts; a missing C store means read the instructions |
Read-only images preserve literal-pool addresses
Section titled “Read-only images preserve literal-pool addresses”Ghidra’s default raw import creates a writable image block. The decompiler folds loads only from non-writable memory, so a Thumb literal-pool slot holding a peripheral address remains an anonymous DAT_ location and the write never acquires its register meaning.
The CLI maps a raw image read-only by default when it has MMIO ranges from a preset, --volatile or an SVD. The literal-pool word then resolves as an address, the volatile block preserves the access, and any SVD label supplies its register name. On one nRF52840 mouse image, unresolved writes through pool slots fell from 184 MMIO and 348 SRAM writes to zero; resolved MMIO writes rose from 49 to 496. The function count stayed at 770 in this isolated comparison. (Program listings and before/after decompiles, 2026-11-20.)
The exception is explicit: --no-rom keeps a self-modifying image writable, while --no-volatile blobs and images based in SRAM stay writable unless --rom is given. CH32V305 code builds addresses with lui and addi instead of Thumb literal pools, so its 189 measured MMIO writes resolved under both settings.
Entry seeds, function recovery, svc and SVD names
Section titled “Entry seeds, function recovery, svc and SVD names”Raw-image analysis uses a preset for the fixed layout and flags for the rest: --vectors reads the initial stack pointer and reset vector, --entry supplies extra starts, --svd imports peripheral register names, and --rom applies a flash-sized read-only map. RISC-V (reduced instruction set computer) gp setup follows the entry’s initialisation flow before analysis so indirect jumps resolve through the value the code actually computes.
Function recovery searches the whole initialized image before and after analysis, clears address tables that Ghidra inferred from Thumb halfwords pointing into a broad volatile block, and re-checks the affected table targets. On the mouse image this raised recovery from 770 to 810 functions with none lost. All 40 new starts followed an unconditional transfer and were checked against the instruction bytes; 28 began with push, 11 were leaf functions and one was a branch thunk.
A second gap remained: Ghidra’s Thumb start patterns accept a push after data only when certain instructions follow it, and a function reached only by a tail call (b.w) gets folded into its caller. A further pass skips the literal-pool words an instruction reads after a return, starts a function at the next push {..,lr} when that code is reached only by unconditional jumps or by nothing, and carves folded tail-call targets out of their callers. That moved the mouse image to 889 functions and the nRF52820 radio from 188 to 195, with none lost and no new decompile warnings; the CH32V305 image stayed at 135. (Function bodies, preceding instructions and decompile warnings, 2026-11-20.)
The last Thumb pass starts leaf functions that have no push: code in undefined bytes after a return or a direct branch that disassembles as a subroutine which returns, and code folded into another function that only unconditional jumps reach. Computed jumps such as tbb are excluded, because their table follows them. The mouse image went from 889 to 912 functions and the radio from 195 to 196. On RISC-V, a constant written to mtvec with direct mode starts the trap handler there, and an entry that is only a jump to the next instruction becomes a thunk. A bare-metal CH32V305 image built from source went from 37 to 39 functions, and every function start and call edge in its ELF (Executable and Linkable Format) verified against the raw import. (Function bodies, decompile warnings and ELF symbols, 2026-11-20.)
Ghidra’s ARM (Advanced RISC Machines) spec models svc #N as a CALLOTHER with no output, so the decompiler keeps the old r0 value after the call. With a read-only literal pool, that made one mouse function’s success path unreachable. The CLI replaces each svc with a call to an svc_0xNN stub whose result returns in r0. Across 36 call sites representing 31 service numbers, unreachable blocks fell from 25 in seven functions to 11 in four; the same 770 real functions decompiled. (Call graph, function bodies and decompile warnings, 2026-11-20.)
An Arm CMSIS-SVD (Common Microcontroller Software Interface Standard) file supplies named, volatile peripheral blocks from the derivedFrom register tree. The loader labels and types each register, including arrays, nested clusters and inherited sizes. With the nRF52840 SVD, pseudocode names RADIO_EVENTS_DISABLED, NVMC_CONFIG and USBD_EPINEN instead of an unaffiliated write through DAT_0002211c5. SVD labels and types also give Ghidra defined data before analysis, which widens its function-start search; the address-table recovery run produced the same 810 functions with or without the SVD on this image.
WCH custom instructions
Section titled “WCH custom instructions”The dongle’s CH32V305 uses QingKe XW compressed instructions outside the base RV32IMAC set. Stock Ghidra decodes those sites as other compressed instructions or unknown data. A community developer’s Ghidra extension adds the RISCV:LE:32:QingKe-XW language and coexists with the stock RISC-V languages6.
The extension was evaluated against a separate decoder whose own LLVM (Low Level Virtual Machine) oracle tests covered 49152 compressed encodings and 9775 image records. Across 9904 shared-scope linear records, including all 645 XWCHC instructions, it returned zero semantic mismatches. Stock Ghidra decoded none of those 645 sites as XWCHC: 637 became other instructions and eight were unknown. Both stock and extension decompiles had zero halt_baddata, so clean decompile gates alone did not expose the wrong language. The CLI prefers an installed QingKe language, warns on a stock fallback, and fails a decompile whose warnings exceed the configured gate. (Decoder comparison and image-wide listing audit, 2026-11-20.)
Installing Ghidra
Section titled “Installing Ghidra”The installer script (bin/re-tools-install) pins both pieces:
- Ghidra 12.1.44, matching the 12.1.x line the server’s provider accepts. The zip is
ghidra_12.1.4_PUBLIC_20260921.zip, sha256ddac49f903da9d5bac833e5cc79395098b9c33cfd3279be5f31bd00387d2d4db, checked before unzipping. - A JDK 21+ on PATH, enforced up front with
command -v javac.
The script downloads to a pinned directory, verifies the checksum, unzips into an install tree and symlinks a stable path, so GHIDRA_INSTALL_DIR points at whichever version is current. Re-running skips what is already in place. The same script pins a Lua 5.x bytecode decompiler the same way, for targets that bundle Lua plugins rather than native code.
The vendored skill
Section titled “The vendored skill”The server’s package ships a skill: routing instructions telling the agent which tool to open for which target (native ELF, APK, managed assembly, archive). It is vendored verbatim into the harness’s skill tree, with a provenance file recording the source and the update procedure.
The skill and the server pin carry the same version, and bumping one means bumping both and re-copying the skill. The provenance file does both in one commit: unpack the new package, copy the skill files over, check the diff, then bump the rea-agents pin in mcp.json and in the provenance file itself. A skill edited out of band can describe capabilities the running server lacks and point the agent at tools that changed.
The update copies upstream files over the local ones, so the vendored copy must stay byte-identical to the package. Local method notes (key recovery, firmware-flash safety, computed-address data flow) live in a separate method skill instead; they were first written into the vendored file and moved out on 2026-11-12, when a diff against the rea-agents@6.7.0 package showed 86 local lines the next update would have deleted.
The skill’s routing sets three rules:
- Installing the skill supplies instructions only. Registering the server and installing the engines are separate steps with separate failure modes.
- The first tool depends on the artifact:
open_binaryfor a native binary or archive, a JS/Electron (JavaScript) path for an extracted app, a managed-assembly path for a .NET artifact. Target-free tools take their own explicit path. - Big artifacts get a summary view first, then a focused follow-up on the item that answers the question.
The headless workflow
Section titled “The headless workflow”Headless Ghidra (analyzeHeadless) runs the analysis and dumps results with no window, so the whole loop fits inside the agent’s normal tools. For bulk export, the checked command is ghidrakit import /path/to/slsk-batch-find --project slsk --decompile /tmp/slsk-decompiled: it imports the executable, checks the log and decompile health, and runs DecompileAll.java. The focused MCP workflow for the worked example is:
- Bind the official client’s build through
open_binary, then take thebinary_overviewmetadata and symbol inventory. - Search symbols for the names the questions point at - here, the dispatch table entries each protocol message code reaches.
- Decompile the reached function to read what it does, and cross-reference callers to see who relies on it.
- Record each finding as a row of a coverage matrix, with the evidence (symbol, code, offset) attached.
Every conclusion is marked as observation, inference or unknown. Static analysis establishes that a symbol exists and what its decompiled body does, not that a code path runs at a particular time.
Worked example: a Soulseek feature-parity matrix
Section titled “Worked example: a Soulseek feature-parity matrix”The author builds a Soulseek client, and wanted it to reach feature parity with the official desktop client rather than staying an automation-only tool. The reference is the official client’s shipped Linux build7 - a closed binary, analysed statically. Two open-source clients (Nicotine+8 and slskd9) were inventoried from source for the same feature list, to see what a complete client does with each protocol message.
Because the official build ships unstripped, the symbol table carries 10,894 symbols with names attached, which turns “what does code 128 do” into a direct symbol lookup. The result is a parity matrix with one column per client (the official reference, the two open-source clients, and the author’s own) and one row per feature, marked Y / partial / missing, with the protocol codes each feature still needs.
Two findings came from the binary alone, absent from the public protocol documentation10:
Server code 128, Distributed Delivery Report
Section titled “Server code 128, Distributed Delivery Report”The public protocol document numbers the server messages it covers and skips 128 entirely. The binary has a Server::DNetDeliveryReport(int) symbol that the dispatch table routes code 128 to, decoding a single 32-bit value. The reference client only logs it, so the author’s client can ignore it.
An obfuscated peer connection
Section titled “An obfuscated peer connection”Decompilation of the connect path recovered how peers advertise a second real port and XOR (exclusive OR) the traffic on it with a 4-byte key rotated per block. The open-source clients do not implement it. Recovered from decompilation but not tested against a live peer, so the implementation is gated on a live handshake test.
Each “codes / notes” cell of the matrix names the exact server or peer message an incomplete feature needs next. The binary was downloaded against a pinned checksum and only strings-scanned or symbol-read, never executed.
The official build ships with symbols intact, which turned most questions into a symbol lookup. A stripped or packed target would need more decompilation per question, with the same workflow.
Stopping a helper process by PID
Section titled “Stopping a helper process by PID”A worker running the headless analysis needed to stop an analyzeHeadless run it had started, and ran pkill -f analyzeHeadless. The worker’s own command line contains its prompt, and the prompt named the Ghidra tool, so pkill -f matched the worker and killed it with exit 143 (SIGTERM). The work was lost.
The fix is to record the PID when the helper starts (... & echo $! > pidfile) and kill by that PID. A pattern kill (pkill -f, killall) is safe only when the pattern cannot appear in the killer’s own prompt, and an agent’s prompt usually names the tool it is about to run.
Porting a function to C with Ghidra as a second reading
Section titled “Porting a function to C with Ghidra as a second reading”A port of a function to C that a project will run needs more than the decompiler’s reading. Ghidra’s pseudocode does not compile as it stands: literal-pool loads appear as DAT_ names with the value hidden, pointer parameters on 32-bit targets come out as int, and arithmetic the machine wraps is written as signed int, which is undefined behaviour once compiled. An agent translating the assembly fails elsewhere: the rounding of a magic-number division, asr against lsr, a signed compare read as unsigned, a while loop where the machine runs a do/while. Each can serve as a check on the other, provided neither has seen the other’s output.
The method (added to the harness’s porting skill on 2026-11-18) runs in five steps:
- The parent extracts the disassembly, every data word the function loads and the calling convention, and gets Ghidra’s pseudocode separately, kept where the translator cannot read it.
- A translator agent writes the C from the disassembly alone, in fixed-width types with overflowing arithmetic done unsigned, commenting each block with its address range.
- A reviewer on a different model family gets the disassembly, the port and Ghidra’s pseudocode, lists every semantic difference between the two readings and rules on each from the instructions, citing addresses. Ghidra agreeing with one side settles nothing.
- A differential test runs the original function under the Unicorn emulator11 and the port compiled for the host on the same inputs: edge values per argument first, then seeded random ones, with the return value and every buffer compared after each call. The port is built with UBSan, so a port that matches only because the host compiler also wrapped is reported.
- The passing port, usually a register-by-register transcript, is rewritten as ordinary C and tested again.
The harness itself was checked on a fixture file compiled for x86-64, AArch64, A32, Thumb-2 and RV32IMAC: 49 checks, covering buffers, .rodata reads, calls into helpers, an MMIO read that must stop the run with the faulting address, and raw images. A port that divides in unsigned arithmetic where the source divides signed failed 655 of 2000 cases on every architecture. Ghidra’s own pseudocode for the same function, with its two DAT_ loads replaced by their values and built with -fwrapv, matched on all 3000 cases; without -fwrapv, UBSan flagged its signed multiply. In the same fixture the compiler had turned a bit-by-bit CRC (cyclic redundancy check) loop into a table lookup, and Ghidra showed the table.
An end-to-end run then gave a fresh agent two unseen Thumb-2 functions from a gcc -O2 build (a saturating filter using smull, mla and ssat, and a scan over signed bytes) with the wording “translate the assembly to C”. The prompt named neither the method nor the skill; the agent loaded the porting skill and followed it: a DeepSeek V4 Pro translator, a Gemini reviewer, and a difftest of both functions. The reviewer’s table had three rows: two forms of undefined behaviour in the port and a disputed branch target that the emulator settled. The final port matched the binary on 5000 cases per function with no UBSan reports, and a re-run with another seed agreed. The run took 29 minutes and produced a correct but transcript-shaped port, which is why the rewrite step was added. A rewritten version that compared the bytes as unsigned failed 4295 of 5000 cases.
The emulator covers pure computation. A branch on a peripheral register, state carried between calls, floating point and vendor instruction extensions (WCH’s RISC-V additions, for one) stay outside it and keep the label “decompiled form only”.
Verifying claims against the analysed program
Section titled “Verifying claims against the analysed program”A findings document needs checks at the same addresses as the analysis. The local verifier accepts atomic claims for bytes, integers, strings, instructions, function starts, call edges, MMIO stores, references and reachability. It returns VERIFIED, REFUTED or INCONCLUSIVE; a refutation includes observed bytes, actual mnemonics, the containing function or the real callees. A refutation exits 1; when none are refuted, an inconclusive claim exits 3.
The design follows the structured claim contract in Reverify12, after evaluating that project as a possible dependency. With its optional backends installed, Reverify answered all 10 claims on one PE (Portable Executable) DLL (dynamic-link library) correctly. The evaluated commit had no raw-firmware loader or base-address support, decoded Cortex-M Thumb as A32 or x86, and decoded RISC-V as x86. The firmware tests produced false REFUTED verdicts on true Thumb claims. Wrapping the image in ELF did not repair virtual-address translation or Thumb’s low address bit. The local verifier therefore queries Ghidra’s analysed program, where the language, base and memory map already exist.
The ground-truth set covered an nRF52840 mouse image and a CH32V305 image: 23 true claims returned VERIFIED, 13 deliberately false claims returned REFUTED, and one open claim returned INCONCLUSIVE. The refuted set used sibling-image addresses, mid-body function starts, wrong call edges and absent references, so the test exercised counter-evidence rather than only successful lookups. (Known-answer claim set and observed verdicts, 2026-11-20.)
Comparing stock and patched images
Section titled “Comparing stock and patched images”Patch comparison starts with a byte diff, imports stock and patched images under the same gates, and maps changed ranges to function bodies. It then decompiles each changed or added function pair and checks branches out of the patch, new unaff_* inputs and calls whose argument registers were written before a detour. Unreachable changed bytes are listed separately so data changes and unrecovered code remain visible.
One mouse-firmware regression fixture loaded a callee address into r1 before calling a four-parameter function. That overwrote the callee’s second argument. Ghidra gave the wrapper a void(void) prototype and rendered the call with no arguments, so the pseudocode diff looked harmless. The register-level check flagged the clobber at 0x33884. A separate patched image with 50 changed ranges and 7318 changed bytes produced nine changed and 41 added functions for review, with no clobber found. (Stock/patched byte maps, decompile diffs and call-register audit, 2026-11-20.)
What carries over to another harness
Section titled “What carries over to another harness”The server name, the 170-tool count, the Ghidra 12.1.4 pin and the Soulseek specifics belong to this setup.
- A decompiler exposed as tools lets the agent query the binary instead of guessing from strings.
- A pinned version plus a checksum verified before use lets a finding be re-checked against the same decompiler.
- A capability that a minority of turns need goes behind tool search, with a description the search can match.
- Guidance is vendored next to the server and bumped with it.
- Findings end as a coverage matrix with per-row evidence.
- A port of machine code is tested against that machine code under emulation, and decompiler output counts as a second reading.
- A checked raw-import CLI validates language, base, memory permissions and entry seeds, then treats log warnings, zero functions and decompile failures as run failures. A harness guard makes the checked path the default even when the agent forgets the CLI.
- Memory permissions are analysis inputs. A writable flash image hides literal-pool addresses from the decompiler; a read-only image preserves them. MMIO ranges also need volatile semantics, and SVD data can supply register names.
- Findings need executable checks. Atomic claims against the analysed program return evidence for agreement and counter-evidence for disagreement. Patch review checks argument registers because pseudocode can omit a call’s arguments.
- Gate on instruction-decode checks too: a clean decompile does not prove the instruction language was right. Compare a vendor-ISA (instruction set architecture) extension against an independent decoder and keep a stock-language fallback visible.
Decision guide
Section titled “Decision guide”- Source is available: use normal repository tools (read, grep, LSP (Language Server Protocol)). Reverse engineering is the heavier fallback, reserved for when the artifact is the only source of truth.
- No source, and you are not entitled to study the artifact: stop.
- No source, and you may study it: load the RE tools through tool search and analyse the artifact statically on headless Ghidra installed from a pinned version plus a verified checksum. Overview first, then focused decompilation; the target is never executed. For raw firmware, use the checked CLI so language, base, memory permissions, entry seeds and decompile health are gates.
- A worker that starts a helper process records its PID and kills by PID. A
pkill -fpattern matches the worker’s own argv and kills the worker instead. - Findings end as a coverage matrix with per-row evidence.
Evidence
Section titled “Evidence”| Claim | How checked | Status |
|---|---|---|
The REA server runs bunx -y rea-agents@6.4.0 --mcp and is deferred | Read from the MCP config’s rea entry (command, args, exposure) | Read from source |
| The server exposes ~170 tools | tool_count: 170 in the skill frontmatter, “170 tools” in the harness AGENTS.md rea entry | Read from source |
Ghidra is pinned to 12.1.4, zip ghidra_12.1.4_PUBLIC_20260921.zip, sha256 ddac49f903da9d5bac833e5cc79395098b9c33cfd3279be5f31bd00387d2d4db, JDK 21+ required | Read from the installer script’s GHIDRA_VER, GHIDRA_ZIP, GHIDRA_SHA256 and the javac check | Read from source |
The skill is vendored verbatim from rea-agents@6.4.0 (morluto/rea, MIT (Massachusetts Institute of Technology)) and bumped in step with the MCP pin | Read from the skill’s VENDORED.md provenance and update procedure | Read from source |
Re-check 2026-10-31: the server pin is rea-agents@6.7.0, the skill frontmatter says tool_count: 207, and the Ghidra pin is unchanged | mcp.json rea entry, VENDORED.md, skill frontmatter, bin/re-tools-install | Read from source; the 6.4.0 and ~170 rows above are the 2026-10-20 state |
| The official Soulseek build ships unstripped with 10,894 symbols | Read from the parity research notes (sources table, SoulseekQt row) | Read from source |
| Server code 128 (Distributed Delivery Report) is absent from the public protocol documentation | Server::DNetDeliveryReport(int) symbol confirmed by nm at offset 0x2aa4a0; code 128 absent from the public SLSKPROTOCOL.md (checked against the Nicotine+ copy, which documents 120-127 and 129 onward) | Measured, and re-checked against the public doc 2026-10-20 |
| The obfuscated peer connection (second port, XOR 4-byte key rotated per block) is recovered from decompilation but untested against a live peer | Read from the parity research notes (open questions section) | Read from source; live test not yet run |
| The client’s MCP request timeout defaults to 60 s and progress notifications reset it | Harness MCP documentation, timeout field | Read from source |
REA’s Ghidra startup deadline defaults to 330 s and is overridable with REA_GHIDRA_STARTUP_TIMEOUT_MS | DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS = 330_000 in the rea-agents@6.7.0 package (dist/config/providerStartupTimeout.js), the error text in dist/ghidra/GhidraProviderClient.js, and the package README | Read from source, 2026-11-12 |
The server entry sets timeout: 900, REA_GHIDRA_STARTUP_TIMEOUT_MS=840000 and a 16G headless heap, and reconnects with 207 tools | MCP config rea entry; MCP server list after the change | Read from source and checked, 2026-11-12 |
| The persistent server was upstream ghidra-mcp 7.0.0, sha256-pinned in the installer, deferred | Installer GHIDRA_MCP_VER / GHIDRA_MCP_SHA256; MCP config ghidra entry | Read from source, 2026-11-12 |
Re-check 2026-11-21: the fork is rebased onto upstream 7.1.0 with the same two patches; the running server reports v7.1.0 and its schema still lists import_file base_address and create_function thumb | Installer pin, service log, the server’s tool schema | Read from source and checked, 2026-11-21 |
| Re-check 2026-11-20: the local persistent server is a private 7.0.0-based fork carrying raw-firmware base-address and Thumb function-creation patches | Local server package, installer and live import tests | Read from source and measured, 2026-11-20 |
| Hand-assembled raw imports produced wrong bases and languages, unmarked MMIO, zero-function projects and skipped Python scripts; an earlier wrapper was bypassed in at least 10 sessions | Session histories and 115 Ghidra logs, 2026-08-15 to 2026-11-20 | Session history, 2026-11-20 |
| The checked CLI validates inputs and logs, requires raw-image layout evidence, and fails bad seed, function and decompile counts | Induced-failure fixtures, import logs and live Ghidra runs | Measured, 2026-11-20 |
| Read-only mapping removed 184 MMIO and 348 SRAM unresolved pool writes on the mouse image; resolved MMIO writes rose from 49 to 496 | Program listings and before/after decompiles | Measured, 2026-11-20 |
| Function recovery moved the mouse image from 770 to 810, then 889, then 912 entries with none lost; every new start followed an unconditional transfer | Function bodies, preceding instructions and decompile warnings | Measured, 2026-11-20 |
Modelling 36 svc sites as calls reduced unreachable blocks from 25 in seven functions to 11 in four | Call references and before/after decompiles | Measured, 2026-11-20 |
Claim verification returned 23 VERIFIED, 13 REFUTED and one INCONCLUSIVE on the known-answer set | True, deliberately false and open claims against analysed programs | Measured, 2026-11-20 |
Patch comparison caught the r1 argument clobber at 0x33884 that pseudocode hid | Stock/patched byte map, decompile diff and call-register audit | Measured, 2026-11-20 |
| The QingKe extension returned zero semantic mismatches across 9904 shared-scope records and decoded all 645 XWCHC sites; stock Ghidra got all 645 wrong or unknown | LLVM-oracle decoder tests and an image-wide listing audit | Measured, 2026-11-20 |
| The vendored skill differed from the 6.7.0 package by 86 local lines before the move | diff of the skill tree against npm pack rea-agents@6.7.0 | Measured, 2026-11-12 |
A pkill -f analyzeHeadless worker killed itself, exit 143 | Session history, 2026-10-19 incident | Recorded |
| The difftest harness passes 49 checks on five architectures; the unsigned-division port fails 655 of 2000 cases | The porting skill’s self-test script and the wrong-port run, output read 2026-11-18 | Measured |
Ghidra 12.1.4 pseudocode for the fixture’s scale function matches on 3000 cases with -fwrapv and trips UBSan without it | difftest runs on the decompiled function, DAT_ loads replaced by the literal-pool words | Measured, 2026-11-18 |
| The end-to-end port matched on 5000 cases per function, 0 UBSan reports, after a three-row review | The worker’s report and port, re-run with a second seed | Measured, 2026-11-18 |
| A rewritten port with an unsigned byte compare fails 4295 of 5000 cases | difftest run on the rewritten port | Measured, 2026-11-18 |
Related docs
Section titled “Related docs”- Which model runs which agent work: model routing in a coding-agent harness - the deferred-tools rationale is the same prompt-cost argument measured for the local engine.
- Subagents, worktrees, and parallel agent work - the worker that hit the self-kill is one of the worker kinds described there.
- GPU (graphics processing unit) voltage-frequency curve control without Afterburner - reverse engineering of the driver’s NVAPI (NVIDIA API) curve interfaces, from community findings rather than headless Ghidra.
- The pi harness journey - the hub that owns the MCP server registration and the deferred-exposure mechanism this page builds on.
- Nuvoton M483 flash locks and the glitch-oracle trap and Read-only SWD (Serial Wire Debug) and voltage-glitch harness on a locked Nuvoton M483 - when static updater decompilation hits a locked microcontroller (
SBLOCK/ALOCK), the readback oracle and single-rail-owner SWD/crowbar harness gates that govern hardware probing. - CH32V305 WCH-LinkE read-only debug triage - SDI (serial debug interface) attach triage and FX2 logic-analyzer capture for a separate CH32V305 RISC-V target.
- Patching an nRF52840 mouse firmware in C - the hook-placement, stack-preservation and literal-pool constraints behind the patch comparison checks.
References
Section titled “References”-
morluto, “REA (Reverse Engineering Agent),” MIT. https://github.com/morluto/rea ↩ ↩2
-
pi coding agent, “MCP servers,” configuration reference (
timeout: per-request timeout in seconds, default 60). https://github.com/earendil-works/pi ↩ -
bethington, “ghidra-mcp,” release 7.1.0. https://github.com/bethington/ghidra-mcp/releases/tag/v7.1.0 ↩
-
National Security Agency, “Ghidra,” software reverse engineering framework. https://github.com/NationalSecurityAgency/ghidra ↩ ↩2
-
Nordic Semiconductor, “nRF52840 CMSIS-SVD,” pinned in nrfx v4.7.1. https://raw.githubusercontent.com/NordicSemiconductor/nrfx/5822caf07442042310103c391dd91cbcaaaa1beb/bsp/stable/mdk/nrf52/nrf52840/nrf52840.svd ↩
-
“QingKe XW Ghidra extension,” release 1.1.1. https://github.com/betamax80/ghidra-qingke-xw/releases/tag/v1.1.1 ↩
-
Soulseek, official site and desktop client downloads. https://www.slsknet.org ↩
-
Nicotine+ contributors, “Nicotine+,” the open-source Soulseek client. https://github.com/nicotine-plus/nicotine-plus ↩
-
slskd, “A modern client-server application for the Soulseek file sharing network.” https://github.com/slskd/slskd ↩
-
Nicotine+ contributors, “Soulseek Protocol Documentation,” Nicotine+. https://github.com/nicotine-plus/nicotine-plus/blob/master/doc/SLSKPROTOCOL.md ↩
-
Unicorn Engine, “Unicorn: CPU emulator framework,” version 2.1.4 used. https://github.com/unicorn-engine/unicorn ↩
-
“Reverify,” structured claim verification for binaries, GitHub repository. https://github.com/2akouwu/reverify ↩
Linked from
- CH32V305 WCH-LinkE read-only debug triage
- History of the pi coding-agent harness
- Nuvoton M483 flash locks and fault-injection readback
- Optical-sensor register tables in mouse firmware and diffing them against datasheet lists
- Proving a replacement firmware image in simulation before flashing it
- Read-only SWD and voltage-glitch harness on a locked Nuvoton M483
- Recovering an AES key from power traces: method and controls
- Replaying boot-time RAM copies before decompiling Cortex-M firmware