Skip to content

feat(ghidra)!: identify containing code and data - #8777

Merged
morluto merged 15 commits into
mainfrom
codex/ghidra-containing-instruction
Nov 7, 2026
Merged

morluto merged 15 commits into
mainfrom
codex/ghidra-containing-instruction

Conversation

@morluto

@morluto morluto commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

A byte-search hit inside a Ghidra-listed instruction or defined data object did not identify its containing object. The function-listing workaround fails when there is no containing function, and exact type inspection cannot locate an unknown parent. inspect_native_instruction now preserves the selected address and separately returns the Ghidra Listing's containing instruction or defined data identity. A data object's start can be passed to inspect_native_data_type; no field or union member is selected. The Ghidra adapter checks status, address space and extent before accepting the observation. CLI and MCP descriptions expose the handoff; CLI help also retains the typed incoming-reference guidance from #8514. Addresses #8241 and #8240.

These are provider listing observations, not proof of source layout, runtime execution, or an alternate decode. Type paths may not all be independently resolvable; the defined-object start is the exact-address handoff. Other providers and older Evidence may omit the new fields.

Snapshot compatibility

The Ghidra analysis profile changes once for both code and data observations. Older Ghidra snapshots fail with evidence_integrity_mismatch; open the target without the old snapshot and save a fresh one. This profile-wide break affects snapshots even when they contain no instruction query. Historical Evidence remains importable without either field.

Validation

  • Follow-up: hosted source tests found two simulated Ghidra data fixtures omitted the containing-data object now required by the bridge contract. The fixtures now supply a one-byte defined object at the queried address; no production validation was relaxed. All six focused instruction-reference facet tests pass on Node 24.22.1. Merged main c928bb8 without conflict and re-ran those six tests; no real Ghidra was run for this follow-up.

  • Follow-up: merged main ac30fbd, including the style(test): format CLI help default annotations #9280 CLI-help formatting fix; Node 24 npm run format:check passes. The focused tests below ran before this formatting-only main follow-up.

  • Reconciled with main 2e2f981: retained both containing-listing scope and current paged incoming-reference guidance, combined snapshot commitments and refreshed their raw-profile goldens. On Node 24.22.1, four focused Ghidra profile/snapshot and MCP-boundary suites passed 146 tests; check:fast, docs:check, and diff checks passed. The MCP tests use a simulated provider; live Ghidra was not rerun after reconciliation. Hosted checks must run on the updated head.

  • CI follow-up: the source and portable lanes failed their tool-effects wording check on “data object start.” The description now says “starting address.” The affected test (8 tests), check:ci:fast, and docs:check passed locally; the new CI run remains pending.

  • Real public MCP byte-search workflow on an x86-64 PE: a match at 0x180001002 remained the selected address and identified the containing MOV at 0x180001001. Instruction starts, defined data and outside-memory cases were also checked; the target digest stayed unchanged.

  • Real Ghidra 12.1.4/macOS arm64, full and compact MCP: an AArch64 overlay without a containing function returned its space-qualified instruction start and length. A separate selected project returned not-in-listing for both uninitialized and initialized-but-unlisted memory. These were disposable projects; targets were unchanged.

  • Real Ghidra non-ASCII overlay control in both MCP profiles: a project-authored REA_Ω_DATA address space round-tripped as REA_%CE%A9_DATA, preserving the selected interior address, parent identity and exact type lookup. The default-space instruction at the same offset stayed distinct; all ten selected-project file digests and the target digest were unchanged.

  • Real Ghidra selected-project overlay control in both MCP profiles: the overlay-qualified data address resolved to its parent and exact type layout, while the same default-space offset resolved to an instruction. All ten source-project regular-file digests and the target digest were unchanged.

  • Real Ghidra selected project with a caller-authored union: a byte-search hit inside the structure returned the parent address and type; the existing type tool returned both overlapping union members. Object start, interior, last byte, outside address and CLI inspection were checked. Project-authored bytes are not claimed as target-file bytes.

  • Real Ghidra padding control in both MCP profiles: an interior byte of a project-authored eight-byte structure resolved to the parent; named fields at offsets 0 and 4 did not cover the selected padding byte. No field was inferred and the executable digest remained unchanged.

  • Real Ghidra bit-field control in both MCP profiles: the selected byte resolved to its containing structure; the existing type tool returned both project-authored bit fields at that byte, with their distinct bit sizes and offsets. No field was selected, and the executable digest remained unchanged.

  • Real Ghidra array control in both MCP profiles: an interior byte returned its 12-byte parent; exact type inspection by parent address and by its /dword[3] type path reported three elements with a four-byte stride. The target was unchanged. This is one array type, not a general guarantee that all type paths resolve.

  • Real Ghidra dynamic-string control in both MCP profiles: the containing object reported length 11 while exact type inspection reported a null fixed size. The output schema now explicitly distinguishes object length from dynamic type size; the target digest was unchanged.

  • Snapshot control on the final profile: old snapshot refused unchanged; a fresh snapshot saved and replayed the instruction observation. A pre-change Evidence bundle imported and re-exported with the historical record and ID unchanged. Target and original bundle digests were unchanged.

  • Ghidra headless address-unit control: a synthetic two-byte addressable-word space returned byte offset 6 for word offset 3; the bridge serializes that offset and Ghidra documents instruction length in bytes. This is not a real word-addressed-program test.

  • npm run test:focused -- tests/boundary/mcp/ghidraContainingListingMcp.test.ts tests/boundary/mcp/ghidraCompactReferencesMcp.test.ts src/ghidra/GhidraFunctionValues.test.ts src/ghidra/GhidraRawProfileDigest.test.ts tests/boundary/mcp/toolSchemaValidity.test.ts — 141 passed. Controls include missing, unexpected, wrong-space, invalid and out-of-range containment.

  • After review fixes, npm run test:focused -- src/ghidra/GhidraSnapshotCache.test.ts tests/boundary/mcp/ghidraContainingListingMcp.test.ts — 33 passed. The snapshot test now checks the final revision against previous and absent values; negative controls use valid coordinates and assert the provider-output error, so the status check cannot be masked by a coordinate failure.

  • npm run check:ci:fast and npm run docs:check — passed after the schema-description update. The fast check and live CLI help were also verified after the incoming-reference wording change. The 30 focused MCP and schema tests passed, and the live full MCP output schema contains the dynamic-size clarification.

Other Ghidra versions, Windows/Linux, alternate instruction modes, live Ghidra listings over subsequently uninitialized memory, and real Hopper/IDA/Kuna instruction providers were not exercised. The union control covers one caller-authored layout, not arbitrary recursive or bit-field layouts.

Current main refresh

Merged main at a67525cdf1; the Ghidra provider behavior fixture suite passed (269 tests). No additional real Ghidra run was performed.

Main refresh for inventory profiles

Merged main at f912a68417; retained containing-instruction CLI wording and both instruction-status and inventory-search profile facts, and refreshed the raw profile digest expectations. Ghidra provider fixture, raw profile, and snapshot cache suites passed (295 tests). No additional real Ghidra run was performed.

Author readiness

Human owner:

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

@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; no actionable new issue was found.

Summary

inspect_native_instruction now returns a containing Ghidra instruction or defined data object without replacing the selected address.

  • Ghidra inspection identifies the listed object that contains a selected byte.
  • Ghidra snapshots use a new instruction-status profile.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Selected address] --> B[Ghidra Listing lookup]
  B --> C[Exact instruction]
  B --> D[Containing instruction]
  B --> E[Containing defined data]
  C --> F[Provider result checks]
  D --> F
  E --> F
  F --> G[Evidence preserves selected address]
  E --> H[Starting address]
  H --> I[inspect_native_data_type]
Loading

Reviews (9) · Last reviewed commit: "chore: integrate current main" · Reviewed by Greptile

Comment thread src/ghidra/GhidraAnalysisProfile.ts Resolved
@morluto morluto changed the title feat(ghidra)!: identify containing listed instructions feat(ghidra)!: identify containing code and data Nov 3, 2026
@morluto
morluto marked this pull request as ready for review November 4, 2026 16:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T18:23:04.350354Z a1f930a New commits
ℹ️ 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.

@morluto
morluto enabled auto-merge (squash) November 7, 2026 18:18
@morluto
morluto merged commit 015a02d into main Nov 7, 2026
49 of 51 checks passed
@morluto
morluto deleted the codex/ghidra-containing-instruction branch November 7, 2026 21:26
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 8, 2026
targetDiagnostics.test.ts: main checks the load remediation's arguments
by pattern instead of a frozen sentence; check the branch's added
arguments the same way with stating().

Main's instruction-status (morluto#8777), byte-search coverage (morluto#8608) and
value-flow (morluto#8651) revisions change every Ghidra raw profile digest.
The legacy pins take the digests main computes at 5044e20 for the
same loads, the M-profile pin is recomputed, and
rawLoadCompatibility.test.ts sets aside the new revisions.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 8, 2026
Main's instruction-status (morluto#8777), byte-search coverage (morluto#8608) and
value-flow (morluto#8651) revisions change every Ghidra profile. Control: with
main's GhidraAnalysisProfile.ts changes since 99db80a reversed, the
old pins hold (169 of 171; the other two assert the new parameters).
@morluto morluto added enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant