Repository navigation
fix(ghidra): reuse completed decompiles and decompile code outside functions - #14843
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2036a313c3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
[Medium impact] The PR appears safe to merge; no blocking issues remain. SummaryThe bridge reuses completed decompilations and can decompile disassembled code outside known functions without changing the Program.
Reviews (6) · Last reviewed commit: "docs(ghidra): state what an omitted deco..." · Reviewed by Greptile |
|
Added one commit: the Checked on the stripped test ELF: Validation: |
A file-offset selector that mapped to disassembled code without a function failed with advice to choose an inventory procedure, which cannot name that code. The failure now states the fact and that procedure_pseudo_code can decompile it by the mapped analysis address. One predicate now decides that an address holds code outside every function for the address, file-offset and procedure_not_found paths, and the bridge imports UndefinedFunction and SoftReference like its other dependencies.
Review summaryReviewed the diff and the surrounding bridge code against Ghidra 12.2 sources and real runs (macOS arm64, JDK 25). One commit pushed: ac0a705. Confirmed and fixed
Checked, no defect found
Left open, with reasons
Commands
|
A file offset names the same location as its mapped analysis address, but an offset that mapped to code Ghidra disassembled without a function was refused while the address decompiled. The offset now resolves through the same on-the-fly UndefinedFunction path and limitation, and its selection reports the inferred entry as procedure_address. The refusal that sent the caller back to the address form is removed.
…ptions A request that omits decompile_max_payload_mib now leaves the session's payload limit unchanged instead of resetting it to the Ghidra default, so an instruction or metadata read no longer discards completed decompiles. An explicit null still selects the installed default. Boundary limitations for a reused decompile of code outside every function now use the function the decompile widened, not a fresh entry-only UndefinedFunction.
Summary
Fixes #14826 and addresses the dead end in #14829. The Java bridge keeps completed decompilations of the current Program state, and
procedure_pseudo_codecan decompile disassembled code that Ghidra left outside every function.Problem and expected behavior
DecompInterfacekeeps no results, so every bridge request re-ran the native decompiler. Four calls on one large function took about 15 s.analyze_functionis declaredliveon the stated assumption that Ghidra retains its own decompiler cache, which it does not.Ghidra's exception-handler analysis disassembles each
.eh_framerange without creating a function.mainin a stripped ELF is only passed to__libc_start_mainas a pointer, so it has code and no function. On clang- and GCC-built stripped x86_64 ELF (including Debianls,sort,true) every REA route to it failed, and the default error described a missing file-offset mapping.Change and scope
Decompile reuse:
decompile(Function)consults a bounded least-recently-used map of soft references keyed by entry address, whether the function is undefined,Program.getModificationNumber()and the payload limit. Only completed results are stored. The existing invalidation hook and the payload-limit path clear it; the modification number makes a missed invalidation a miss rather than a stale hit. The entry bound is a fixed ceiling with its reason stated in the source.Code outside functions: when a decompile selector resolves to no procedure but names an analysis address holding disassembled code outside every function, the bridge builds
ghidra.util.UndefinedFunctionas Ghidra's decompiler panel does and decompiles that. The Program is unchanged. The result's limitations state that the entry was inferred from control flow and is absent from the inventory. This reading precedes the file-offset fallback.procedure_not_foundandfile_offset_unmappedmessages now say when the address holds code without a function or is a mapped address with no code. A file offset names the same location as its mapped analysis address, so an offset that maps to such code is converted once and takes the sameUndefinedFunctionpath, with the same limitation; itsselectionreports the file offset, the mapped address and the inferred entry asprocedure_address. The refusal that sent the caller back to the address form is removed.Not included: making the procedure inventory complete (on Debian
ls, 139.eh_framestarts hold code with no function), parallel decompilation, and any change to other procedure operations, which still require a function.Contribution scope: not applicable; a fix within existing boundaries.
Contract and boundary impact
limitations.procedure_pseudo_codeand CLIdecompilesucceed for an address, or a file offset mapping to it, that they previously refused. Error text for two failure codes is extended.ghidra.util.UndefinedFunctionandProgram.getModificationNumber, both present in Ghidra 12.2; older supported releases were not checked.list_proceduresremains visible.Expected effects:
Evidence and regression coverage
procedure_pseudo_code11 ms; repeatanalyze_function325–481 ms, previously 3.6–4.4 s. Afterannotate_native_functionrenamed a callee, the caller's next decompile showed the new name. Code outside functions:procedure_pseudo_codeatmainof a stripped ELF returned pseudocode with the limitation; an interior address resolved to the same entry;list_procedureswas unchanged.procedure_pseudo_codewithfile-offset:0x860, which maps to thatmainat0x1001860, returned the sameUndefinedFunction_01001860pseudocode and limitation withselection{file_offset: 2144, mapped_address: 0x1001860, procedure_address: 0x1001860}; the address request that followed was answered from the cache in 3 ms.npm run verify:ghidra. Heap behavior of 32 retained results on very large functions was not measured; soft references are the mitigation. Only x86_64 ELF and one Mach-O were exercised.Validation performed
npm run test:focused -- tests/boundary/filesystem/ghidraBridgeSources.test.ts tests/boundary/providers/ghidra/ghidraBridgeHelpers.test.ts tests/boundary/providers/ghidra/ghidraClient.test.ts tests/boundary/providers/ghidra/ghidraCheckpointLifecycle.test.ts— 4 files, 143 tests passednpm run docs:check— passednode scripts/verify-ghidra-bridge-sources.mjsagainst Ghidra 12.2 — bridge compilesnpm run test:focused -- tests/boundary/mcp/ghidraAmbiguousProcedureMcp.test.ts tests/boundary/mcp/pseudocodeDeliveryMcp.test.ts— 11 tests passednpm run check:fast— typecheck, lint and architecture guards passednpx oxfmt --checkon the changed files — passedCompatibility, safety, and release
Author readiness
Human owner: @morluto
Review follow-up
procedure_infoor an instruction read, now leaves the session's payload limit and completed decompiles unchanged. An explicitnullstill selects the installed Ghidra default.