Skip to content

fix(ghidra): attribute indirect-branch warnings by source address - #5137

Closed
jaelliot wants to merge 41 commits into
morluto:mainfrom
jaelliot:fix/ghidra-warning-attribution-upstream
Closed

jaelliot wants to merge 41 commits into
morluto:mainfrom
jaelliot:fix/ghidra-warning-attribution-upstream

Conversation

@jaelliot

@jaelliot jaelliot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary and dependency

Draft: #5137 corrects unresolved indirect-branch warning attribution by Ghidra's typed instruction address. It depends on #2977 and must not merge independently of that feature.

Current source head: d9bb66a, after a test-only result-projection correction to the non-force merge 079d733, following the non-force, two-parent merge a8596d7 retaining the original #5137 branch and the rebased #2977/typed-warning integration. It contains current upstream main (d3ab0fa); GitHub reports the 27-file diff as mergeable. The inherited #2977 implementation, source-owner migrations, and regression tests account for most of that diff. Its incremental, historical eight-file source-address fix remains reviewable. Existing contributor history and credit are preserved.

Problem and approach

On real Ghidra, a warning printed as 0x0000100c can refer to an instruction at aarch64_overlay:0x100c, while AVR's printed word-address 0x0804 refers to byte offset 0x1008. Parsing that text as a listing address misattributes genuine warnings and loses ghidra-decompiler-warning Evidence. Caller-authored comments can also repeat genuine warning text.

The Ghidra producer now collects complete warning comments from ClangCommentToken with the exact typed source Address. It accepts only consistent token provenance and discounts an authored warning only when its exact rendered occurrence matches at the same source address. No fallback deletes a different warning when an authored comment is wrapped or omitted. A corrected indirect_branch_inventory analysis-profile commitment (listing-computed-jumps-typed-warning-address-v2) invalidates older cache/snapshot results. Unrecovered branch targets remain explicitly unknown.

The existing source-owned AArch64, AVR8 and MIPS32 probe exercises non-entry computed branches, overlay/default collisions, word-address units, delay slots, misleading string literals, wrong addresses, and missing/wrapped comment sources. The current REA schema/application owners and recent workflow revisions are preserved rather than overwritten. This correction adds no general-purpose target execution, arbitrary PSP support or external dependency.

Executed verification and limits

  • Negative real-provider control: fork run 41359021877 reached Ghidra 12.1.4 and failed specifically at aarch64_overlay_outcome before the typed-producer correction.
  • Positive real-provider correction: fork run 41359355962 passed the same source-owned AArch64 default/overlay, AVR word-address and MIPS delay-slot probe, including misleading-comment controls, bridge compilation and owned cleanup.
  • Profile and snapshot validation: fork run 41359939917 passed the corrected real-Ghidra probe and 216/216 focused tests across raw profile digests, provider behavior and snapshot replay. An additional general AArch64 lane in that fork-only run did not qualify: its unrelated native-value compare_functions request exceeded the existing default 1,024 MCP input-element limit.
  • Current upstream PR head: CI run 41367791962 has passed package build, documentation and Source tests at d9bb66a. Built-dependent test shards remain in progress at this checkpoint; the run is not fully green. The preceding 079d733 run passed package build, documentation and source tests; one built test failed because the new legacy-snapshot regression passed an unprojected {ok,value} to parseEvidence. That regression now uses the existing projectCliAnalysisResult helper for both current and replayed results. Static checks on the previous head listed only 16 format issues also present on upstream main, none in these changed files.

The final 27-file tree shares its implementation and verification-code blobs with the positively tested fork revision, except for the updated documentation. The temporary fork-only GitHub Actions trigger is not part of this PR. The exact merge commit has not been rerun through the optional real-Ghidra lane. Earlier historical results in this thread apply to their original revisions, not automatically to the current head.

Not established: live PSP/Allegrex or Monster Hunter runtime correctness, arbitrary module/PRX admission, true overlay residency, Windows/macOS equivalence, or the complete public CLI/MCP path for this source-owned typed-warning probe. AVR testing covers the Ghidra-producing boundary, not AVR admission.

Author readiness

Human owner: @jaelliot

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Prepared with AI assistance from ChatGPT/Codex. This draft remains dependent on #2977 and human review.

Before merge

RishTheFish21 and others added 30 commits October 13, 2026 14:28
Use structured Ghidra comment Addresses instead of printed coordinates, preserving overlay identity and byte offsets while leaving branch targets unresolved. Add real AArch64, AVR8, and MIPS32 regression cases, negative markup controls, and v1 snapshot refusal.

Focused follow-up based on morluto#2977 head 50b39ef.
Preserve the commits and authorship of upstream PR morluto#2977 and the
warning-attribution follow-up while resolving current-main integration.
Advance native API inspection to workflow revision 2; retain upstream
source-limitations, instruction-reference, and function-boundary profiles.
Update the real verifier to current installation/release-policy APIs.

Validated tree: f5faac2
Validated upstream base: 95c8f57
283 focused tests passed; 2 Windows-only tests skipped.
Real Ghidra 12.1.4: 106 assertions passed across four cases.
Static/build and documentation checks passed.

Prepared with AI assistance from ChatGPT/Codex. Draft depends on morluto#2977.
A lint-staged autofix rewrote these unrelated files during a merge; [^/] is invalid in the advertised v-mode pattern and the edit broke format:check.
Ghidra emits each comment word as its own token with whitespace as syntax tokens, so the warning is matched over rebuilt markup text restricted to comment and whitespace characters.
Discount caller-authored jump-table warning lines by the address they name
instead of their full text. Ghidra wraps comment lines past the display
width, so a rendered copy can be cut short and no longer equal the stored
comment, which let a stored copy stand in for a decompiler warning. The
real-Ghidra verifier now also stores a WARNING:-prefixed copy and checks
that the genuine warning still counts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013nDLgq92ifZmGnv55JdGoP
# Conflicts:
#	docs/testing.md
#	src/domain/investigationProviders.ts
#	src/ghidra/GhidraAnalysisProfile.ts
@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: apex

[Medium impact] The changes affect Ghidra native-function analysis and the saved results used by that workflow.

The remaining testing-rule violation must be addressed before merging.

Findings

  1. P2 Tests freeze explanatory sentences ▶
Fix with agent prompt
### Issue 1
src/application/native/NativeApiInspection.test.ts:128-130
These assertions copy whole explanations from `NativeApiInspection.ts`, and the same text is repeated in workflow and MCP tests. The repository's testing guide says to assert facts rather than freeze explanatory sentences. A wording-only edit now breaks several suites.

Before merging, satisfy that requirement by comparing delivered wording with its owning formatter or constant. Separately assert addresses, outcomes, unsupported flags, and unknown counts.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR records unresolved computed jumps and uses typed Ghidra comment addresses to attach warning evidence to the right instruction.

  • Ghidra ties computed-branch warnings to their source instruction and reports unresolved branches.
  • Native API inspection shows unresolved indirect branches as unknowns.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Typed `ClangCommentToken` addresses"] --> B["Warnings grouped by source"]
  C["Saved listing comments"] --> D["Subtract exact matching occurrences"]
  B --> D
  D --> E["Warning evidence"]
  F["Listing computed jumps"] --> G["`unresolved_indirect_branches`"]
  E --> G
  G --> H["`inspect_native_api`"]
  H --> I["Evidence and open questions"]
Loading

Reviews (3) · Last reviewed commit: "test(ghidra): keep synthetic caller toke..." · Reviewed by Greptile

Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
Comment thread docs/native-investigation.md Resolved
Comment thread docs/testing-lanes.md Resolved
Comment on lines +128 to +130
expect(projected.residual_unknowns).toEqual([
"Which targets can the indirect branch at 0x401040 reach? The decompiler could not recover a jump table there and rewrote it as a call or return; it may be a dispatch inside this function or an indirect tail call.",
"Is the indirect branch at 0x401050 a tail call or a dispatch inside this function, and which targets can it reach?",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests freeze explanatory sentences

These assertions copy whole explanations from NativeApiInspection.ts, and the same text is repeated in workflow and MCP tests. The repository's testing guide says to assert facts rather than freeze explanatory sentences. A wording-only edit now breaks several suites.

Before merging, satisfy that requirement by comparing delivered wording with its owning formatter or constant. Separately assert addresses, outcomes, unsupported flags, and unknown counts.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/application/native/NativeApiInspection.test.ts
Line: 128-130

Comment:
**Tests freeze explanatory sentences**

These assertions copy whole explanations from `NativeApiInspection.ts`, and the same text is repeated in workflow and MCP tests. The repository's testing guide says to assert facts rather than freeze explanatory sentences. A wording-only edit now breaks several suites.

Before merging, satisfy that requirement by comparing delivered wording with its owning formatter or constant. Separately assert addresses, outcomes, unsupported flags, and unknown counts.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

jaelliot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing this draft as superseded by #2977, not as an abandoned fix. @RishTheFish21 fast-forwarded the canonical #2977 branch to this PR's exact head e7bb266 and added one test-only commit 063df50 on top. I independently checked the ancestry: the sole delta beyond this branch is src/ghidra/GhidraFunctionValues.test.ts. The typed-source-address warning-attribution correction, retained original contributor history, tests, and authorship are now carried by #2977.

There is no independent merge path left for #5137; future review, CI and integration belong on #2977, with the separate PSP fixture still dependent as #6931. My prior validation caveats (real-Ghidra/current-head qualification and human owner review) continue to apply to the canonical PR; closing this draft does not attest they passed.

@jaelliot jaelliot closed this Nov 4, 2026
@morluto morluto added bug Something isn't working 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

bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants