Repository navigation
feat(native): surface inferred prototype instruction conflicts - #8161
Conversation
[Medium impact] The PR appears safe to merge; no blocking issues were found. SummaryAdds read-only x86-32 Ghidra prototype-conflict diagnostics and carries them through function summaries and native API views.
This review was source-based; tests and real Ghidra were not rerun. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Decoded x86-32 instructions] --> C[Limited conflict checks]
B[Analysis-inferred prototype] --> C
C --> D[Optional native_api.prototype_conflicts]
D --> E[Summary count or null]
D --> F[Complete dossier, inspection and retained view]
Reviews (18) · Last reviewed commit: "Merge landed relocation handling into pr..." · Reviewed by Greptile |
Codex Review SummaryThis 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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
- Add evidence-backed x86-32 stack-read and stdcall cleanup diagnostics in ReaGhidraBridge.java without rewriting signatures or function bodies. - Carry prototype conflicts through native API schemas, analysis summaries and retained dossier views so CLI and MCP share the observations. - Update Ghidra analysis profile digests, documentation and MCP boundary tests for the new diagnostic contract.
- Traverse decoded entry-frame paths in ReaGhidraBridge.java instead of stopping at an address-ordered early return, so later reachable reads remain visible. - Detect explicit, implicit and partial EBP writes and use decoded operands with p-code loads, preventing stale-frame warnings and recognizing real Ghidra stack reads. - Compare immediate return cleanup with inferred stdcall stack bytes even when either side is zero, and allow zero in the native API contract. - Add real Ghidra instruction probes and MCP/CI regressions for the reported cases and document the bounded checks.
- Check a decoded stack read before invalidating EBP in ReaGhidraBridge.java so instructions that read and replace the frame still report the conflict. - Match each candidate operand's address p-code to its LOAD pointer so a POP from ESP into an EBP destination cannot masquerade as an argument read. - Cover both decoded instruction cases in ReaPrototypeConflictProbe.java and await verifier-owned scratch cleanup on success and failure.
- Recompute the 6502 and disabled-analyzer raw-binary profile digests in GhidraRawProfileDigest.test.ts so the pinned values commit to the merged shared policy on current main.
5178bcb to
3ceb0c1
Compare
- Find PUSH EBP; MOV EBP, ESP from the function entry address in ReaGhidraBridge.java so an owned block below the entry cannot hide a reachable argument read. - Run analyzeHeadless in its own process group and stop that group before removing scratch in verify-ghidra-prototype-conflicts.mjs, so the JVM and decompiler children are addressed as one owned family. - Cover the lower-owned-block case in ReaPrototypeConflictProbe.java with an entry frame preceded by a decoded lower block.
|
Hey @akshad-exe, thanks for putting this together, the addition looks useful. What's left: it has merge conflicts with main in |
- Allocate the instruction fixture through the lower-block offset in verify-ghidra-prototype-conflicts.mjs so the entry frame and decoded block exist for the probe. - Check the detached process group instead of the leader exit code before cleaning up, so lingering decompiler children receive SIGTERM and SIGKILL before scratch removal.
- Use REA's ProviderProcessSupervisor and token-verified cleanup in verify-ghidra-prototype-conflicts.mjs so the JVM and descendants are stopped before scratch removal, including failed launches. - Preserve the source-owned x86 fixture with an entry frame and lower block while asserting verified cleanup. - Build the pinned verifier dependency graph in the Ghidra bridge CI job and extend its timeout before running the real probe.
- Install SIGINT and SIGTERM handlers before spawning Ghidra and abort the wait, so Ctrl-C no longer leaves the detached process group running. - Keep cleanup handlers installed until the shared process owner reports verified cleanup, then remove scratch only after the process family is stopped.
- Keep interrupt handlers installed through process cleanup and workspace deletion, then check cancellation before reporting success. - Preserve and report the failing cleanup step instead of replacing it with an interruption or deleting a tree that may still be unsafe.
- Record the probe error before cleanup so a late SIGINT or SIGTERM cannot replace its stack and captured Ghidra diagnostics. - Prefer the earlier probe failure when cleanup also fails, while preserving cleanup diagnostics and temporary state for diagnosis.
|
Hi @morluto, the current head |
Resolve GhidraRawProfileDigest conflict by recomputing digests for the merged shared policy (6502 ec9d5bfe..., x86-disabled f61db0ec...). Auto-merges preserved prototype conflict logic.
- The multi-target verifier spawn used a 10s timeout while sibling verifier cases use 25s. - Under 8-way sharded CI load this intermittently exceeded 10s and produced ETIMEDOUT, failing shard 1/8 and portable tests. - Raise to 30s to match the existing verifier budget and avoid load flakes.
- Resolve GhidraAnalysisProfile and raw-digest tests in favour of upstream's producer-identity model, which supersedes the hand-bumped prototype_conflict_evidence marker by hashing the edited bridge sources. - Union the ghidra_bridge CI scope and lane table so the prototype-conflict verifier and probe stay qualified alongside upstream's loader-relocation and instruction-context lanes. - Keep both the prototype-conflict verifier step and upstream's loader-relocation step in the Ghidra bridge workflow, retaining the 30-minute timeout for the added compile and probe. - Migrate verify-ghidra-prototype-conflicts.mjs to the shared VerifierFixture so the workspace root is released only after owned process cleanup confirms, satisfying the new verifier-fixture-root architecture guard. - Take upstream's error-projection import path and kuna verifier deadline comment where both sides converged.
- The ghidra_bridge lane failed in upstream's untouched SDK acquisition step: curl returned 403 with 0 bytes downloaded in 0.046s from the GitHub release CDN. - Push an empty commit to start a fresh run because rerunning on the upstream repository requires admin rights.
- Run the prototype-conflict probe through withVerifierFixture so a probe failure and a failed release surface as one AggregateError that keeps the probe error as its cause and attaches the retained fixture as cleanupLeases, instead of throwing the probe error alone and dropping the cleanup owner. - Report the failed cleanup step and retained project only when the fixture was not released, and keep interrupt handlers installed until release finishes.
Summary
Surface evidence-backed disagreements between Ghidra's inferred x86-32 function prototypes and decoded stack instructions in the function dossier. Fixes #1244.
Problem and expected behavior
A zero-parameter inference can coexist with a direct framed stack read; an inferred four-parameter stdcall signature can coexist with a larger immediate return cleanup. Previously the analyst had to find those instruction-level conflicts manually in assembly. The diagnostic is a disagreement, not a corrected declaration.
Change and scope
[EBP + displacement]reads after an entry frame against a zero-parameter inference, and immediateRETcleanup differences when inferred stdcall parameters occupy simple four-byte stack slots. A direct one-hop shared epilogue can supply theRETwithout expanding the function body; jumps into other functions are excluded.signature_source, the observed instruction and address, byte counts or offset, and unresolved assumptions. No prototype is rewritten; assembly and existing x87 observations remain available. The check is intentionally limited to analysis-inferred x86-32 signatures. The frame scan follows only reachable decoded edges, stops at any explicit, implicit, or partial EBP write, and uses decoded operand objects plus p-code LOAD rather than Ghidra operand read flags. A missing record does not prove a correct prototype.native_apischema and selected views retain the same records; the default function summary reports a count, ornullwhen the check was not recorded. The Ghidra analysis profile changes so old snapshots are not mistaken for observations with this check.Contract and boundary impact
ReaGhidraBridge.java; domain schema and shared CLI/MCP projections consume its facts.native_api.prototype_conflicts; add summarycounts.prototype_conflictswith nullable missing-check semantics.Expected effects:
Evidence and regression coverage
MOV EBP, [EBP + 8](read before the frame write) andPOP [EBP + 8](read fromESP, destination only). The verifier awaits deletion of its newly created scratch on success and on failure; an injected missing-Ghidra failure left no new workspace. No existing scratch directories or downloads were removed.0x406400and0x401b10); MCP tests inject representative structured dossiers; the new Ghidra probe does use real decoded source-owned x86 instructions, but not the DX-BALL executable.For boundary regressions, schema/adapter projections and omitted optional records are covered by focused tests; real producer goldens and end-to-end Ghidra observations are outstanding. Lifecycle regressions are not applicable to this read-only observation addition.
Validation performed
npm run test:focused -- tests/boundary/mcp/ghidraNativeApiMcp.test.ts— 13 passed.npm run test:local -- src/ghidra/GhidraRawProfileDigest.test.ts src/domain/analysisView/analysisView.test.ts src/application/native/NativeApiInspection.test.ts— 49 passed.npm run test:local -- src/domain/analysisView/analysisView.test.ts src/domain/analysisView/nativeInventoryView.test.ts src/domain/analysisView/machoView.test.ts— 58 passed.npm run test:focused -- tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts tests/boundary/mcp/enhancedTools.06-rejects-incomplete-function-dossiers-at.test.ts— 31 passed, 2 skipped.GHIDRA_INSTALL_DIR=/home/akshad/.local/opt/ghidra_12.1.4/ghidra_12.1.4_PUBLIC JAVA_HOME=/home/akshad/.local/share/jdk21 node scripts/verify-ghidra-prototype-conflicts.mjs— passed with decoded x86-32 instructions, includingMOV EBP, [EBP + 8]andPOP [EBP + 8]; scoped cleanup completed before success. Failure injection with a nonexistent install exited nonzero and left no new scratch.npm run test:focused -- tests/boundary/mcp/ghidraNativeApiMcp.test.ts tests/boundary/filesystem/ciChangeScope.test.ts— 339 passed.npm run check:fast— passed; push hook reran it from cache.npm run format:checkandnpm run docs:check— passed.GHIDRA_INSTALL_DIR=/home/akshad/.local/opt/ghidra_12.1.4/ghidra_12.1.4_PUBLIC JAVA_HOME=/home/akshad/.local/share/jdk21 node scripts/verify-ghidra-bridge-sources.mjs— passed; compiled all 10 packaged bridge sources against 195 jars with Ghidra 12.1.4 and javac 21.0.12.1.Maintainer recheck on Ghidra 12.2 and JDK 25 on Apple Silicon: all packaged bridge sources compiled, the real decoded x86 prototype probe passed, and 433 MCP and CI-scope tests passed. The diagnostic takes its signature from the same decompilation as its parameter facts, checks only entry-reachable returns and contiguous stdcall stack slots, and accepts legacy summaries that omit the new count. After the import-only conflict with #11996 was resolved, bridge compilation, the real probe and all 433 tests passed again on
b2683542eb. The exact #1244 executable was unavailable.Compatibility, safety, and release
prototype_conflicts; summaries gain a nullable count. Ghidra profile digest changes intentionally invalidate prior analysis snapshots.Author readiness
Human owner: @akshad-exe
Before merge