Skip to content

feat(native): surface inferred prototype instruction conflicts - #8161

Merged
morluto merged 19 commits into
morluto:mainfrom
akshad-exe:fix/native-prototype-conflicts
Nov 19, 2026
Merged

morluto merged 19 commits into
morluto:mainfrom
akshad-exe:fix/native-prototype-conflicts

Conversation

@akshad-exe

@akshad-exe akshad-exe commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

  • The Ghidra bridge records direct [EBP + displacement] reads after an entry frame against a zero-parameter inference, and immediate RET cleanup differences when inferred stdcall parameters occupy simple four-byte stack slots. A direct one-hop shared epilogue can supply the RET without expanding the function body; jumps into other functions are excluded.
  • Each record carries the inferred claim and 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.
  • The native_api schema and selected views retain the same records; the default function summary reports a count, or null when the check was not recorded. The Ghidra analysis profile changes so old snapshots are not mistaken for observations with this check.
  • Return-register forwarding and x87 conversion inferences are not added: the issue describes those as needing further corroboration.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra instruction/decompiler boundary in ReaGhidraBridge.java; domain schema and shared CLI/MCP projections consume its facts.
  • Contribution scope fit and linked maintainer decision: Existing read-only Ghidra observation; no new execution, mutation, injection, or protection recovery. Special maintainer scope decision not applicable.
  • CLI and MCP/tool-catalog contract: Add optional native_api.prototype_conflicts; add summary counts.prototype_conflicts with nullable missing-check semantics.
  • Provider, bridge, target-format, or platform compatibility: Ghidra x86-32 only; other providers and old dossiers omit the new optional field. The refreshed Java bridge builds against the repository's Ghidra 12.2 SDK pin.
  • Evidence, artifact, provenance, or reconstruction contract: Preserve the inferred signature source and instruction address/text, unknowns and original assembly; change the Ghidra profile digest.
  • Target selection, authority, upstream behavior, and cleanup details: No changes to selection or target authority. The diagnostic scans already-decoded instructions and reads one directly referenced shared epilogue without claiming ownership.
  • Generated metadata, package, or installation impact: No generated files committed; CI owns generated catalogs.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Follow-up review regressions: the real Ghidra probe checks MOV EBP, [EBP + 8] (read before the frame write) and POP [EBP + 8] (read from ESP, 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.
  • Tests added or updated: MCP boundary tests assert stack-read and return-cleanup conflicts, including zero cleanup and zero inferred stack bytes, survive full analysis, summary, native API inspection and retained view; raw-profile digest goldens updated. A real Ghidra x86-32 instruction probe checks an early-return branch before a later framed read, XCHG EAX/EBP, MOV BP/AX, and RET 8/RET 0; the bridge CI job now runs the probe.
  • Base reproduction or other evidence: feat(native): surface instruction conflicts with inferred function prototypes #1244 documents the two real Ghidra cases (0x406400 and 0x401b10); MCP tests inject representative structured dossiers; the new Ghidra probe does use real decoded source-owned x86 instructions, but not the DX-BALL executable.
  • User-visible CLI/MCP output: Full dossier and native API selection carry records; summary carries count. The shared projection is used by CLI/MCP.
  • Remaining proof gaps: Real Ghidra output for these exact addresses was not rerun locally. Java bridge compilation passed locally with Ghidra 12.1.4; real-provider execution remains unverified. The decoded-instruction probe verifies the producer predicates, but does not prove that the complete decompiler/dossier path emits either diagnostic for the reported 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.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

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, including MOV EBP, [EBP + 8] and POP [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:check and npm 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

  • Breaking changes or migration steps: Existing complete dossiers can omit prototype_conflicts; summaries gain a nullable count. Ghidra profile digest changes intentionally invalidate prior analysis snapshots.
  • Real Hopper/Ghidra, browser, or OS coverage: Local Ghidra 12.1.4 bridge compilation passed; real-provider dossier output for feat(native): surface instruction conflicts with inferred function prototypes #1244 remains unverified.
  • Package or release metadata impact: No package metadata edited.
  • Security, privacy, process, or containment review: Read-only analysis of decoded instructions; no new target execution or mutation.

Author readiness

Human owner: @akshad-exe

  • 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.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • Validation evidence supports the current diff, including real-provider verification where applicable.
  • The human owner has reviewed the diff and declared readiness above.

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Adds read-only x86-32 Ghidra prototype-conflict diagnostics and carries them through function summaries and native API views.

  • Ghidra reports selected instruction conflicts with inferred x86-32 prototypes.
  • Function summaries show how many prototype conflicts were recorded.

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]
Loading

Reviews (18) · Last reviewed commit: "Merge landed relocation handling into pr..." · Reviewed by Greptile

Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
@akshad-exe
akshad-exe marked this pull request as ready for review October 30, 2026 18:56
Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:56
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T18:56:15.244559Z
We couldn’t complete this review. Comment @codex review to try again.
5178bcb Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

- 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.
@akshad-exe
akshad-exe force-pushed the fix/native-prototype-conflicts branch from 5178bcb to 3ceb0c1 Compare November 3, 2026 12:36
Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
- 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.
@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @akshad-exe, thanks for putting this together, the addition looks useful. What's left: it has merge conflicts with main in src/ghidra/GhidraRawProfileDigest.test.ts (merging main into the branch is fine) and the CI required check is failing (failing job: ghidra_bridge / Compile packaged Ghidra bridge sources). There are 2 unresolved review threads from Greptile (1 still on current code), e.g. "New fixture bytes are missing"; the one on an outdated line may just need resolving if it's already handled. Greptile is at 4/5 on the current head, mainly over "New fixture bytes are missing", so addressing that thread should bump it. Happy to merge once that's sorted.

- 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.
@akshad-exe

Copy link
Copy Markdown
Contributor Author

Hi @morluto, the current head 37698a3ac has all required CI checks passing, including the pinned Ghidra bridge/probe job, and the review threads are resolved. The PR is now MERGEABLE, with no unresolved blocking checks; it is waiting on the maintainer merge/review decision. Please let me know whether you would like to merge it or if anything else is needed.

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.
akshad-exe and others added 3 commits November 17, 2026 10:31
- 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.
@morluto
morluto enabled auto-merge (squash) November 19, 2026 01:40
@morluto
morluto merged commit ae25050 into morluto:main Nov 19, 2026
53 checks passed
@akshad-exe
akshad-exe deleted the fix/native-prototype-conflicts branch November 19, 2026 10:23
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 22, 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(native): surface instruction conflicts with inferred function prototypes

3 participants