Skip to content

feat(ghidra): configurable import language and analysis seeds - #1667

Merged
morluto merged 4 commits into
morluto:mainfrom
sqmagellan:feat/ghidra-language-and-seeds
Oct 11, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
sqmagellan:feat/ghidra-language-and-seeds

Conversation

@sqmagellan

Copy link
Copy Markdown
Contributor

Summary

Ghidra imports always auto-detect the language and use default analysis. That misses Borland C++ PE images (wrong compiler spec) and code reached only through computed jumps or data. No linked issue.

Change and scope

  • REA_GHIDRA_LANGUAGE_ID / REA_GHIDRA_COMPILER_SPEC_ID: passed as -processor / -cspec; checked against the installation's .ldefs; rejected for DOS imports.
  • REA_GHIDRA_SEED_FILE: address<TAB>function|code|label[<TAB>name] lines applied by a pre-script before auto-analysis.
  • Not included: persistent projects, data seeds, CLI flags.

Contract and boundary impact

  • CLI and MCP/tool-catalog contract: none.
  • Provider compatibility: unchanged when the variables are unset.
  • Evidence: the analysis profile records language_id, compiler_spec_id, language_selection and analysis_seeds (digest and counts). The handshake must report the committed language and seed digest, or the session fails closed. Limitations report seed outcome counts.
  • Package: adds bridge/ghidra/ReaGhidraApplySeeds.java.

Evidence and regression coverage

  • Tests: config parsing, .ldefs admission, profile digests, launcher arguments, seed parsing/snapshot/tamper, handshake mismatch.
  • Real Ghidra 12.1.4 (macOS arm64) on a 3.6 MB Borland C++ PE with borlandcpp and 17,183 seeds: 14,961 functions, 1,592 code seeds and 484 labels applied; xrefs to a computed-jump dispatch global went from 0 to 17.
  • Gaps: Windows P0 and Linux not run.

Validation performed

  • npm run check: pass.
  • npx vitest run src/ghidra tests/boundary/providers/ghidra src/config.test.ts: 366 passed.

REA_GHIDRA_LANGUAGE_ID and REA_GHIDRA_COMPILER_SPEC_ID set the import
language when the header cannot identify the compiler (for example,
Borland C++ PE images).

REA_GHIDRA_SEED_FILE seeds functions, code and labels before
auto-analysis, for code reached only through computed jumps or data.

Both are validated before launch, recorded in the analysis profile and
verified in the bridge handshake.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto
morluto merged commit af88184 into morluto:main Oct 11, 2026
29 checks passed
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I tested the new language setting on Linux with Ghidra 12.1.4. It does not change what #1620 reports, since REA still refuses the MIPS32 files before Ghidra starts. On the one file REA opens, the setting works and is recorded, and bad input fails early.

I used the eight little-endian MIPS32 files from my #1620 test, with REA_GHIDRA_LANGUAGE_ID=MIPS:LE:32:default. That id exists in the Ghidra 12.1.4 install.

Results

Check Result
The other seven files from #1620, with the override Still refused, same messages. Each answer took about 30 ms, so Ghidra never started.
The mips32r2 file, no override vs override Same 3 functions: rea_mips_leaf, rea_mips_entry and rea_mips_probe. Same decompile of 0x201b0. The profile digest differs.
Language in the evidence language_id, compiler_spec_id and language_selection: "configured-v1" appear in the analysis profile of each result.
Bad language id, wrong compiler spec, bad seed line Fail before launch with a clear error (text in the fold).
Seeds on the mips32r2 file Applied, and counted in the result limitations.
npm run verify:ghidra:seeds Exit 0.
The PR's five test files All pass. 21, 18, 33, 14 (1 skipped) and 3 tests.
  • Why the refusal stays: inspectTargetSupport in GhidraProvider.ts (line 152) and resolveGhidraAnalysisProfile in GhidraAnalysisProfile.ts (line 37) both call ghidraMipsUnsupportedReason. That runs before the override is read. The ISA check is line 21 of GhidraMipsProfile.ts. The mips32 files stop there. The file with the ABI field cleared stops at the o32 check on line 24.
  • The setting reaches Ghidra: I gave MIPS:BE:32:default for the little-endian mips32r2 file. REA opened it. The entry function then decompiled to halt_baddata(). With the right language it decompiled cleanly. So REA does not check the override against the file header. A wrong id gives bad output, not an error.
  • Digest: with no override it starts 496f6bb4a799. With the override it starts e4f476f388f9. Adding a compiler spec of default gives 8fd78458814d.
  • Seeds: with 0x20180 function, the result says "1 functions created, 0 already present, 0 failed" and lists a new FUN_00020180. With three seeds that already existed, it says "0 functions created, 3 already present". One seed at 0x20172 failed. I don't know why.
  • Stripped files: the two stripped files are refused with the ISA message, even with the override and a seed file. So I could not test seeds on them.
  • Bad input: the bad language id, the wrong compiler spec and the bad seed line all fail before launch with a clear error. Three other cases stop the MCP server at startup, so a client sees only "Connection closed". A missing seed file gives a generic message. The exact text is in the fold below.

Not run

  • The PR's own motivating case, a Borland C++ PE image. I opened no PE file.
  • Seeds on the stripped files, since REA refuses them.
  • Seeds in real use: computed jumps, data pointers, code seeds on undecoded bytes, and labels on real bss.
  • Big-endian files with a big-endian language.
  • npm run verify:ghidra:mips, the Windows lane, Hopper, IDA and real firmware.
  • The whole test suite. I ran only the files this PR touched.
  • A patch to REA that lets the mips32 files through.

Thanks, sqmagellan, for the PR.

Bad input messages
  • Language MIPS:LE:32:nonesuch: REA configuration is invalid: REA_GHIDRA_LANGUAGE_ID: is not a language defined by Ghidra 12.1.4.
  • Compiler spec borlandcpp with the MIPS language: REA_GHIDRA_COMPILER_SPEC_ID: must be one of the selected language's compiler specs: default, windows, eabi
  • Seed file with notanaddr on line 3: REA_GHIDRA_SEED_FILE: line 3: address must be 0x-prefixed hex
  • Three cases stop the MCP server at startup instead. They are mips32, a compiler spec with no language, and a relative seed path. The message is clear on stderr, for example REA_GHIDRA_COMPILER_SPEC_ID: requires REA_GHIDRA_LANGUAGE_ID. An MCP client only sees "Connection closed".
  • A missing seed file gives a generic message. It says "Analysis could not complete." The path and the reason sit only in the error details.
Commands
npm ci && npm run build
npm run test:local -- src/ghidra/GhidraAnalysisSeeds.test.ts          # exit 0, 21 passed
npm run test:local -- src/ghidra/GhidraLanguageOverride.test.ts       # exit 0, 18 passed
npm run test:local -- src/ghidra/GhidraProvider.behavior.test.ts      # exit 0, 33 passed
npm run test:focused -- tests/boundary/providers/ghidra/ghidraLauncher.test.ts   # exit 0, 14 passed, 1 skipped
npm run test:focused -- tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts   # exit 0, 3 passed
npm run verify:ghidra:seeds                                           # exit 0

Each file ran on its own. I first ran the two boundary files under test:local. They stopped with a note to use test:focused. That was my mistake, so I reran them.

MCP probe, with a fresh server per case and REA_ANALYSIS_PROVIDER=ghidra. The calls were open_binary, binary_session, list_procedures and procedure_pseudo_code at 0x201b0.

Test setup

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

The Borland reproduction makes the need for these Ghidra controls clear, @sqmagellan. Thanks for adding language/compiler selection and analysis seeds, and for recording the supplied choices in the analysis profile. Welcome to the project.

@morluto morluto added enhancement New feature or request area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@matbrgz matbrgz mentioned this pull request Oct 14, 2026
2 tasks done
@morluto morluto added area: setup Setup, packaging, upgrade, install, Doctor, and client registration provider: ghidra Analysis provider / engine: ghidra labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: setup Setup, packaging, upgrade, install, Doctor, and client registration enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants