Repository navigation
feat(ghidra): Phase 1 — kuna as Ghidra's decompiler core (protocol + extension + docs) - #134
Merged
Merged
Conversation
…extension + docs)
Add ghidra-mode: kuna can drive the stock Ghidra GUI as its native decompiler
core, over Ghidra's existing decompiler-process protocol, with zero changes to
Ghidra's Java side.
kuna never ported the C++ "ghidra mode" glue (ghidra_process.cc/ghidra_arch.cc/
ghidra_translate.cc, excluded as LOSS-002). This is Phase 1 of restoring it in
Rust: the wire protocol is complete; the engine bridge is stubbed.
New crate `decompiler/crates/kuna-ghidra` (binary `kuna_ghidra`):
- protocol.rs: the burst framing (a port of ghidra_arch.cc:50-248) — the
{0,0,1,code} markers, string/bool/byte streams, the getBytes nibble and
getStringData length codecs, the exception channel (-> KunaError::Java).
- process.rs: the command loop (port of ghidra_process.cc) — the exact doit()
lifecycle (response-open before params; archid bind; catch classification;
the always-present 16/17 warnings frame), the archlist session model, and the
seven decomp commands. registerProgram parses the tspec <sleigh> into a real
AddrSpaceManager, so decompileAt decodes real <addr> params; decompileAt
answers the incomplete-function shape (empty payload + a clear warning) so the
GUI shows a clean per-function error, not a hang. structureGraph and the four
signature commands are unregistered — the "Bad command" path is exactly the
graceful-degradation contract Java expects (BSim / nested-graph-layout only).
- client.rs: the 19 typed callback queries (getPcode/getBytes/getMappedSymbols/
...), byte-exact request framing; payloads returned raw for the Phase-2 bridge.
- ids.rs: the protocol element ids at their upstream numbers (229, 239-257,
261/262/264/268), resolved against the C++ source.
- 24 tests incl. a byte-exact MockJava full-session e2e.
Two deliberate, documented divergences from upstream for drop-in robustness:
setOptions tolerates unknown option elements (upstream fails the program-open on
one stale option); a malformed archid answers a clean JavaError instead of
wedging + exiting the process.
Ghidra extension `integrations/ghidra/KunaDecompiler/`: a plugin that reflectively
points DecompileProcessFactory.exepath at the kuna_ghidra binary (the only
substitution seam; flat classpath, no --add-opens), a Tools-menu toggle, and a
status script. Refcounts live plugin instances so restore is JVM-wide-safe.
Docs: `docs/ghidra-integration.md` (the kuna-side design + Phase 1-4 plan) and
`docs/decompiler-core-interface.md` (what Ghidra requires from ANY replacement
core — the durable, core-agnostic protocol record).
Gates: make test (675/675 PARITY OK), make test-stages (PARITY OK), make
rust-test — all green; additive, no existing crate touched.
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017t3eYSdxwUsPjN2s2oLGof
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
Phase 1 of running kuna as the decompiler core inside the stock Ghidra GUI, over Ghidra's existing decompiler-process protocol, with zero changes to Ghidra's Java side.
Ghidra's GUI drives its decompiler as a spawned child process (
decompile) over a burst-framed stdin/stdout protocol. Upstream that process is the C++ghidra_optbuild — the same DECCORE engine kuna ported, plus aGHIDRAglue group (ghidra_process.cc/ghidra_arch.cc/ghidra_translate.cc/…) kuna deliberately excluded from the port (LOSS-002). This PR reimplements that glue group in Rust. The wire protocol is complete; the engine bridge is stubbed (that's Phase 2).Contents
New crate
decompiler/crates/kuna-ghidra(binarykuna_ghidra):protocol.rs— the burst framing (port ofghidra_arch.cc:50-248):{0,0,1,code}markers, string/bool/byte streams, the getBytes/getStringData codecs, the exception channel →KunaError::Java.process.rs— the command loop (port ofghidra_process.cc): the exactdoit()lifecycle (response-open before params, archid bind, catch classification, the always-present 16/17 warnings frame), the archlist session model, and the seven decomp commands.registerProgramparses the tspec<sleigh>into a realAddrSpaceManager(sodecompileAtdecodes real<addr>params);decompileAtreturns the incomplete-function shape (empty payload + a clear warning) so the GUI shows a clean per-function error, not a hang.structureGraphand the four signature commands are unregistered — the "Bad command" path is exactly the graceful-degradation contract Java expects (BSim / nested-graph-layout only).client.rs— the 19 typed callback queries, byte-exact request framing.ids.rs— protocol element ids at their upstream numbers (229, 239–257, 261/262/264/268).Ghidra extension
integrations/ghidra/KunaDecompiler/: a plugin that reflectively pointsDecompileProcessFactory.exepathat the kuna binary (the only viable substitution seam — flat classpath, no--add-opens), a Tools-menu toggle, and a status script. Compiles against a real Ghidra install; refcounts live plugin instances so the JVM-wide restore is multi-tool-safe.Docs:
docs/ghidra-integration.md(kuna-side design + the Phase 1–4 plan) anddocs/decompiler-core-interface.md(what Ghidra requires from any replacement core — the durable, core-agnostic protocol record).Deliberate divergences (for drop-in robustness)
setOptionstolerates unknown option elements (upstream fails the whole program-open on one stale option — the livebaddatacountskew is the motivating case).JavaErrorinstead of wedging +exit(1)ing the process.Both are documented in
docs/ghidra-integration.md§8; the setOptions one gets adocs/divergences.mdDIV entry whensetOptionsstops being a stub (Phase 2).Verification
make test— 675/675 PARITY OKmake test-stages— PARITY OKmake rust-test— greencargo test -p kuna-ghidra— 24/24; extensionjavacclean against a Ghidra 12.1 installAdditive — no existing crate is touched.
Follow-up
Phase 2 (the engine bridge → first real C in the GUI) is proposed in a stacked draft PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_017t3eYSdxwUsPjN2s2oLGof