Repository navigation
feat(ghidra): report decompiler warnings and dropped blocks with derived listing ranges - #4237
RishTheFish21 wants to merge 1 commit into
Conversation
Codex Review Summary: ❌ FailedThis 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. |
[Medium impact] The PR appears safe to merge; no new blocking issue was found. SummaryAdds structured reports for blocks Ghidra removes from pseudocode.
No new actionable defects or confirmed security issues were found. This was a source review; tests were not run. GitHub access was unavailable, so whether another PR supersedes this one could not be checked. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Ghidra pseudocode] --> B[Read removal-warning headers]
B --> C[Exclude caller-authored warning lines]
C --> D{Address maps into function?}
D -->|Yes| E[Collect listing range and instructions]
D -->|No| F[Retain unmapped warning]
E --> G[Function dossier]
F --> G
G --> H[Pseudocode unknowns]
G --> I[Removed-block pages]
Reviews (7) · Last reviewed commit: "Merge commit 'd0067ba34a39ea47dd7e11bb2e..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88f543df89
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4334dd3c62
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
CI/conflict track: the earlier Ran locally on the merged tree: build, |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
baron
left a comment
There was a problem hiding this comment.
Reviewed unchanged head ce4e63c92eb37c201452ca055542409a508bbcc8; repository CI, including CI required, is green and human readiness declarations are filled. The capability is ordinary read-only analysis within existing scope, not a new execution or mutation capability.
[P2] The existing decompiler-warning provenance finding remains partially unresolved. This continues the existing thread, rather than adding another inline duplicate. At ReaGhidraBridge.java:3365–3374, restricting the regex to whole lines before { excludes body string literals, but not user-authored function header comments. Ghidra 12.1.4 enables the entry-point plate/header comment by default (DecompileOptions), encodes that plate text as header (DecompileCallback), and prints ordinary headers and warning headers through the same comment renderer before the function declaration (PrintC).
Consequently, an entry plate comment WARNING: Removing unreachable block (ram,0x401010) naming a valid in-body address has the exact accepted rendering even when no block was removed. It becomes a false removed-block record, unrelated listing assembly, and a false pseudocode omission warning. Please keep the decompiler-owned warning provenance at the producing boundary and add a real-provider plate-comment decoy alongside the existing string-literal decoy, without discarding caller comments from retained evidence.
This is source-derived, supported by a synthetic regex-only probe; I did not reproduce it in a running Ghidra instance. The author's real macOS/Ghidra receipts cover actual removals and string decoys, not this header-comment case. No independent source suite ran here (pinned toolchain/locked dependencies unavailable); no dependencies/providers were installed.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Thanks, confirmed in a running Ghidra 12.1.4. Ghidra passes the entry plate comment to the decompiler as a "header" comment (DecompileCallback.encodeHeaderComment), and PrintC::emitCommentFuncHeader prints it through the same renderer as warningheader comments, so the rendered text alone can't tell them apart. Fixed in in the bridge, where the caller-supplied header text is known. When the header comment option is on, the bridge renders the function's entry plate comment the way PrintLanguage::emitLineComment does, collects the removal-warning identities that rendering produces, and discounts one rendered header match per caller-authored line. Only the remainder is decompiler-owned. Pseudocode and the New real-Ghidra lane: Before the fix (ce4e63c bridge), AArch64 ELF. An entry plate on rea_reachable_block naming its in-body block start becomes a removed block that wasn't removed: After the fix, macOS arm64, Ghidra 12.1.4, both formats pass:
Linux and Windows not run. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Status update: this is merged with current main, with the two #4650 conflicts resolved in analyzeFunctionObservation, and CI is green. From my side it’s ready for another look whenever it suits you |
CassieFox23
left a comment
There was a problem hiding this comment.
TL;DR: Main does not have this feature, and I found no code defect by reading the diff. A change request from baron still stands on an older head, and the commit that answers it has had no re-review. The body is out of date on two points.
Findings
Should fix
- The body is out of date. The "Change and scope" text leaves out the plate comment fix from commit ffc09fc. The "Validation performed" list does not name the new real-Ghidra check,
scripts/verify-real-ghidra-warning-provenance.mjs. The author's comment lists the results, but the template asks that the body stay current. - The body does not say that every native pseudocode view gains a new note when the record is missing. The code adds a "not recorded" note when the field is absent. That covers Hopper and IDA views and older cached Ghidra results. The docs say this and a test checks it. The body says the note appears only when blocks were removed.
Worth knowing
- baron's change request is on the older head ce4e63c. It says an entry plate comment can fake a removal warning. Commit ffc09fc answers it. I read the new bridge code. It renders the plate comment the way Ghidra does in
PrintLanguage::emitLineComment. Then it skips one matching header line for each line the author wrote. I read that Ghidra function at tag Ghidra_12.1.4_build, and the steps match. The author's real-Ghidra results are in the comment above. I did not run them. GitHub still shows the change request, and I saw no newer review from baron. - Pull request 2904 is open and also says it relates to the same issue. Its file list includes
ReaGhidraBridge.java,hopperValues.tsandnativeFunctionView.ts, which this PR also changes. I did not read its diff. Whichever lands second will need to fit the other. This is a maintainer call. - The new real-Ghidra check is not in
package.jsonor any workflow on this head. The README says to run it by hand. The olderverify:ghidra:aarch64-jump-tablecommand is not in a workflow either. So the real-Ghidra evidence is the author's own macOS arm64 runs.
Looks good
- Main does not have the feature. A search of main (e83e3ce) for
decompiler_completeness,removed_blocksandRemoving unreachable blockinsrc,bridge,docsandscriptsfound nothing. - The bridge only reads warning lines in the header, before the line with the opening brace. A string literal in the body cannot match. See the pattern and header cut. A warning that cannot be mapped into the function goes to
unmapped_warningsand is not dropped. - The schema is strict. The Ghidra check rejects duplicate starts. It also rejects assembly with no mapped range. It also checks the new addresses are canonical. The cache profile key moves to
v2, so old snapshots are not replayed. - The unit tests cover bad addresses, unknown reasons and duplicates. They also cover an empty record versus an absent one. All nine bot review threads are resolved and marked outdated. The Codex summary on this head shows no findings. Greptile gave 5/5.
- Hosted CI is green on this head. That covers the 8 test shards, Static checks and Docs Generation. It also covers Portable tests, the
ghidra_bridgecompile job andCI required. ThePR readinessstatus passes. - The body keeps every template heading, label and box.
- I tried a merge of this head with main. Nine files changed on both sides since the merge base, and a three-way text merge of each gave no conflict. This is a text merge only. I did not build or type-check the result.
Not run
- No build and no tests. This is a read-only review of the diff against main.
- I did not run the real-Ghidra checks. The author reports Linux and Windows were not run either.
- The author's macOS results and the claim that the check fails on the old bridge are not verified by me.
- I did not read the full diff of pull request 2904.
Thanks, RishTheFish21, for the feature, and for the fixture and the decoy checks that pin it.
Test setup
🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊
|
Thanks for exposing removed-block observations. #2904 also addresses #2735 and includes warning provenance and comparison coverage, while this PR proposes mapped block ranges and assembly. Could you coordinate on the evidence needed to establish those ranges and keep the distinct supported cases in one review? Both proposals remain open. |
|
Thanks @morluto, and cc @Bobtoshi. I went through #2904 in detail. Here's how the two compare, and a concrete proposal for doing #2735 in one review. What each one covers
Where #2904 stands
|
|
Thanks @RishTheFish21 and @morluto. Yes, let’s use #4237 for the combined warning and instruction-fallback work. I agree with the proposed split: retain #2904’s observed envelope, raw offsets, warning association and Preserving analysts’ comments and reusing the typed-token attribution from #2977 is a better direction than carrying over #2904’s comment-rendering toggle. Keep the comparison-coverage change out of the combined PR; it is a separate breaking decision. Please preserve Bobtoshi’s co-author credit for the incorporated work. The source shape is pinned at a73ec1251. I’ll keep #2904 open as the reference until the combined implementation and attribution are present, so there is no need for competing integrations. |
|
@RishTheFish21 thanks for the PR — this branch has merge conflicts with |
…ved listing ranges Ghidra analyze_function dossiers now carry decompiler_completeness: the warnings Ghidra's decompiler rendered, taken from typed comment tokens so caller-authored comments never count, and one dropped block per "Removing unreachable block" warning with its raw space and offset, resolved start and end: null. A dropped block whose start lies in the function also gets a separately derived listing_block: the listing basic block that contains the reported start, with its exclusive end and assembly. Native views add decompiler_completeness, decompiler_warnings and decompiler_dropped_blocks facets, and the pseudocode view names the omission. The warning-provenance lane checks caller comment decoys on real AArch64 objects and removal coordinates on overlay, colliding, unknown, register and AVR word-addressed spaces. Fixes morluto#2735 Co-authored-by: Bobtoshi <[email protected]>
f6334dd to
ec75e92
Compare
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@morluto Thanks. I've rebuilt this as one commit on current On real Ghidra 12.2 (macOS arm64) the warning-provenance lane passes for ELF and Mach-O, including overlay and AVR word-addressed coordinates. The AArch64 lane passes the removed-block fixtures on both formats; its unrelated host native-value comparison fails the same way on plain |
Summary
Ghidra's decompiler sometimes drops blocks it decides are unreachable. Until now, the only sign of this was a header comment inside the pseudocode, so a caller reading the dossier couldn't tell that code was missing, or where it was. #2735 describes an auth comparison sitting entirely in a dropped block.
This is the combined #2735 implementation agreed with @Bobtoshi on #2904. It keeps #2904's observed shape and adds a listing range and instructions as a separate, derived fact.
analyze_functiondossiers from Ghidra now includedecompiler_completeness:status(warnings,no-warnings-reportedorunavailable),warnings,warning_countanddiagnostic, as Ghidra reported them;dropped_blocks: one entry perRemoving unreachable blockwarning, with Ghidra's rawaddress_spaceandreported_offset, the resolvedstart(ornull), itswarning_indexandend: null;listing_blockon each dropped block: the listing basic block that contains the reported start (relation: "contains-reported-start"), with its exclusiveendand instructions.Fixes #2735
This is one commit on current
main. It no longer depends on #2977.Problem and expected behavior
Before: a removed block shows up only as
/* WARNING: Removing unreachable block (ram,0x...) */in the pseudocode.After, for a function whose block at entry+0x10 is removed (AArch64 ELF fixture, real Ghidra 12.2):
{ "start": "0x100010", "end": null, "address_space": "ram", "reported_offset": "0x00100010", "reason": "unreachable", "warning_index": 0, "listing_block": { "provenance": "ghidra-listing-basic-block", "relation": "contains-reported-start", "start": "0x100010", "end": "0x100018", "assembly": ["0x100010: mov w0, #0x77", "0x100014: ret"] } }endstaysnullbecause Ghidra reports only where a removed block starts.listing_blockis derived from the listing, not reported by the decompiler. It can begin before the reported start and isn't claimed to be the whole removed region; its own limitation says so.listing_block. An unknown or non-memory space givesstart: null.Change and scope
analyzeFunctionObservation):0x0804→ byte0x1008).BasicBlockModel. Their assembly isn't separately bounded: the block lies inside the function, whose full assembly the dossier already carries.decompilerCompletenessSchema(from feat(ghidra)!: preserve paged warnings and require observed comparison coverage #2904, pluslisting_block) is an optional field on the shared dossier. It's required on Ghidra dossiers, and the Ghidra refinement checks provenance, reported offsets and canonical addresses. Every field validates without changing the value, so Hopper's value-keeping reply contracts still hold.decompiler_completeness(summary),decompiler_warningsanddecompiler_dropped_blocks. Apseudocodeview adds an unknown when blocks were dropped.batch_decompile,inspect_native_api,trace_native_valuesand annotation results. That can be a follow-up PR.Contract and boundary impact
analyze_function, thenfunctionDossierSchema(src/domain/native/functionDossier.ts) anddecompilerCompletenessSchema(src/domain/native/decompilerCompleteness.ts). The native views consume the parsed field.decompiler_completenessdossier field (optional in the shared schema, always present for Ghidra), three native view facets, and one pseudocode-view unknown when blocks were dropped.docs/public/product-catalog.json), package, or installation impact: None authored.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/ghidra/GhidraFunctionValues.test.ts: accepts a warning with a derived listing block that starts before the reported start, and a dropped block with no listing block. Requires the field on Ghidra dossiers. Rejects foreign provenance, a non-nullend, a stale count, a status/warnings mismatch, an out-of-rangewarning_index, a missing reported offset, a non-canonical start, a listing block without a start, and anotherrelation.src/domain/analysisView/analysisView.test.ts: the three new facets, the pseudocode unknown, and "not recorded" when the field is absent.tests/conformance/ghidra/decompiler-removed-block.S, checked inverify:ghidra:aarch64-jump-tableon AArch64 ELF and Mach-O: a single removed block, a dead region spanning several listing blocks (one warning per block, each derived listing block matching its reported start), a reachable control, and a string-literal decoy.scripts/verify-real-ghidra-warning-provenance.mjs, with two probes through the production bridge:ReaDecompilerWarningProvenanceProbe.java: caller-authored entry plate and body comments that spell a removal warning (for an in-body address, or for an unknown space) are not recorded and stay incomments. A plate repeating the real warning leaves exactly one dropped block.ReaDecompilerRemovedBlockCoordinateProbe.java: overlay identity, a colliding offset in an ordinary function, unknown and register spaces (start: null), a start outside the function (no listing block), and an AVR word coordinate.main,analyze_functionfor the removed-block fixture returns the warning only insidepseudocode; no field records it.debugnative-value CLI/MCP comparison was skipped locally: it fails the same way on plainmainwith Ghidra 12.2 on this Mac, before any removed-block fixture runs. CI covers it.For evidence-bearing changes:
Validation performed
At head ec75e92, macOS arm64, Ghidra 12.2 (decompiler natives built from the release's own source), Temurin 25.0.5.1, Node 24.22.1:
npm run check:fast— passednpm run format:check— passednpm run knip— passednpm run docs:check— passednpm run verify:ghidra:bridge-sources— passed (Ghidra 12.2, javac 25)npm run test:focused -- src/ghidra/GhidraFunctionValues.test.ts src/domain/analysisView/analysisView.test.ts src/ghidra/GhidraRawProfileDigest.test.ts src/ghidra/GhidraSnapshotCache.test.ts src/ghidra/GhidraProvider.behavior.test.ts src/application/binary/AnalysisSnapshotCache.test.ts src/hopper/HopperReplyContracts.test.ts— 605 passednpm run test:fast— 33,703 passed; 3 failed insrc/desktop/ExportedAppPython.test.ts, which fail the same way onmainon this Macnpm run test:mcp— 2,294 passednode scripts/verify-real-ghidra-warning-provenance.mjs— passed: ELF and Mach-O provenance (13 checks each) and the coordinate probe (AVR word0x0804→0x1008)npm run verify:ghidra:aarch64-jump-table— passed for ELF and Mach-O, including the removed-block fixtures; run with this lane's hostdebugnative-value CLI/MCP comparison skipped locally, because it fails identically on plainmainwith Ghidra 12.2 on this Mac (CLI and MCPtrace_native_valuesevidence IDs differ)Compatibility, safety, and release
Author readiness
Human owner: @RishTheFish21
Author checklist (completed by the PR author before requesting review)
type(scope): outcome.REA_runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.