Skip to content

fix(ghidra): stage sibling dSYM beside target snapshot for DWARF analysis - #10768

Open
cainiao1992 wants to merge 2 commits into
morluto:mainfrom
cainiao1992:feat/ghidra-12.2
Open

cainiao1992 wants to merge 2 commits into
morluto:mainfrom
cainiao1992:feat/ghidra-12.2

Conversation

@cainiao1992

@cainiao1992 cainiao1992 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stage the caller-selected sibling .dSYM beside the Ghidra target snapshot so Xcode 17 clang DWARF is visible to Ghidra, and bind that companion to the checkpoint identity.

  • createGhidraTargetSnapshot copies <source>.dSYM/Contents/Resources/DWARF/<source> to the staged name using the existing cancellable chunked-copy path, then verifies read coverage and source identity. An unstable companion removes the partial bundle and keeps the snapshot's no-companion semantics, matching the digest probe; absent, malformed, or unreadable companions stay optional and cancellation propagates.
  • resolveGhidraCheckpoint hashes the companion and includes its digest in the checkpoint key when present. Adding or changing a dSYM therefore starts a separate analysis instead of restoring a Program built without those symbols, and never overwrites the saved Program. Targets without a companion keep the established two-part key.
  • Product docs state the identity rule.

Per maintainer request, this PR now contains only the dSYM change and is rebased on current main; the 12.2/JDK 25 and Homebrew work already landed separately.

Problem and expected behavior

Xcode 17 clang emits all DWARF into a sibling .dSYM while the Mach-O keeps no debug sections. Ghidra's DWARF analyzer only discovers a bundle named after the staged executable, so a staged target-<hash>.bin lost every DWARF symbol and procedures resolved only by raw Mach-O names. After this change, a matching companion stages under the staged name and its symbols participate in the analysis.

Change and scope

Follow the contribution scope. Not applicable: this uses existing provider and owned-runtime boundaries. It adds no target authority, injection, mutation, or protection-recovery capability.

The checkpoint key change is deliberately additive for no-companion targets so existing manifests and Evidence remain valid. A companion changes which analysis inputs produced the Program, so it receives its own key rather than reusing or overwriting an incompatible saved Program.

Contract and boundary impact

  • Semantic owner and earliest changed stage: GhidraTargetSnapshot owns companion staging and its content digest; GhidraCheckpoint consumes that digest in the storage key; GhidraProvider passes the caller-selected target path.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: macOS sibling dSYM bundles stage under the staged snapshot name; other platforms and target formats are unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: checkpoint directory identity gains a third component only when a companion stages. The manifest stays at version 2 and owned_checkpoint/Evidence shape is unchanged, so no-companion replay is unaffected.
  • Target selection, authority, upstream behavior, and cleanup details: companion bytes are copied into the existing owned runtime root, use the cancellable chunked-copy path, and follow that root's cleanup.
  • Generated metadata, package, or installation impact: none.

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

  • Tests added or updated: GhidraTargetSnapshot.test.ts covers renamed staging, absent/malformed companions, staging cleanup, a source rewritten mid-copy, cancellation during copy, and cancellation while hashing the digest; GhidraCheckpoint.test.ts covers unchanged identity without a companion, a separate checkpoint when one appears with the old manifest untouched, content-bound identity, and malformed-layout fallback.
  • Base reproduction or other evidence: the original PR recorded procedure_not_found: rea_checkpoint_leaf when the staged Mach-O lost DWARF, and restored bare names and struct types after placing a renamed dSYM beside the snapshot. That real-provider observation was made on the earlier branch and was not re-run in this environment.
  • User-visible CLI/MCP output (if applicable): none; doctor output shape is unchanged.
  • Remaining proof gaps: no real Ghidra analysis or verify:ghidra:checkpoints run here because no real Ghidra/JDK is available in this environment.

For boundary fixes, this adds checkpoint-identity regressions at the staging and storage owners plus a focused lifecycle boundary test; real-provider checkpoint replay remains a gap.

For evidence-bearing changes:

  • 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:local -- src/ghidra/GhidraTargetSnapshot.test.ts src/ghidra/GhidraCheckpoint.test.ts — 29 passed.
  • npm run test:local -- src/ghidra/GhidraTargetSnapshot.test.ts with the parent revision's implementation and the current test file — 1 failed, 6 passed, confirming the mid-copy rewrite regression.
  • npx vitest run src/ghidra — 1297 passed, 1 skipped.
  • npm run test:focused -- tests/boundary/providers/ghidra/ghidraCheckpointLifecycle.test.ts — 8 passed.
  • npm run check:fast — passed (typecheck, lint, architecture guards).
  • npm run docs:check — passed.
  • Not run: real Ghidra verifier lanes, bridge compilation, and verify:ghidra:checkpoints (no real Ghidra/JDK in this environment).

Compatibility, safety, and release

  • Breaking changes or migration steps: none for callers. Existing checkpoints and snapshots without a dSYM are unaffected; a new or changed dSYM intentionally selects a different checkpoint.
  • Real Hopper/Ghidra, browser, or OS coverage: source and fixture tests on macOS arm64; no real provider verification in this environment.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the companion copy stays inside the owned runtime root, is cancellable, and is cleaned up with that root. No new authority or external contact.

Author readiness

Human owner: @cainiao1992

  • 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.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T05:16:27.789280Z
We couldn’t complete this review. Comment @codex review to try again.
7eb64f2 PR opened
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects Ghidra snapshot analysis and checkpoint selection for targets with sibling dSYM files.

The PR still needs to check that the staged companion matches the digest used to select its checkpoint.

Findings

  1. P1 Added debug symbols stay missing ▶
Fix with agent prompt
### Issue 1
src/ghidra/GhidraTargetSnapshot.ts:undefined-136
With `REA_GHIDRA_CHECKPOINT_DIR` set, analyze a Mach-O without its dSYM, then add the matching dSYM and reopen it. `resolveGhidraCheckpoint` selects the same saved Program because its key covers only the executable hash and profile. The launcher restores that Program with `-noanalysis`, so the newly staged symbols and types are ignored.

Commit the companion's presence and digest before choosing a checkpoint, and verify the staged copy against that commitment. The repository requires cache keys to cover inputs that affect results.

---

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

Summary

Stages sibling dSYM files beside Ghidra’s renamed target snapshot and includes their content digest in checkpoint selection.

  • Ghidra snapshots now include matching sibling dSYM symbols.
  • Changed dSYM symbols select a separate Ghidra checkpoint.

Source review only; no runtime verification was performed. Checking whether another PR supersedes this one was blocked by unavailable GitHub authentication.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Resolve analysis profile] --> B[Read optional companion digest]
  B --> C[Choose checkpoint key]
  C --> D[Acquire checkpoint]
  D --> E[Create target snapshot]
  E --> F[Read and stage optional companion]
  F --> G{Saved Program exists?}
  G -->|Yes| H[Restore saved Program]
  G -->|No| I[Analyze staged target]
  I --> J[Save Program in selected checkpoint]
Loading

Reviews (3) · Last reviewed commit: "fix(ghidra): verify the companion dSYM c..." · Reviewed by Greptile

Comment thread src/ghidra/GhidraTargetSnapshot.ts Outdated
// staged Mach-O keeps no __debug_info. Ghidra's DWARFAnalyzer only discovers
// a bundle named after the staged executable's path, so stage a renamed copy
// next to the snapshot; the runtime root owner cleans it up with the tree.
await stageCompanionDsym(sourcePath, snapshotPath);

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.

P1 Added debug symbols stay missing

With REA_GHIDRA_CHECKPOINT_DIR set, analyze a Mach-O without its dSYM, then add the matching dSYM and reopen it. resolveGhidraCheckpoint selects the same saved Program because its key covers only the executable hash and profile. The launcher restores that Program with -noanalysis, so the newly staged symbols and types are ignored.

Commit the companion's presence and digest before choosing a checkpoint, and verify the staged copy against that commitment. The repository requires cache keys to cover inputs that affect results.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ghidra/GhidraTargetSnapshot.ts
Line: 136

Comment:
**Added debug symbols stay missing**

With `REA_GHIDRA_CHECKPOINT_DIR` set, analyze a Mach-O without its dSYM, then add the matching dSYM and reopen it. `resolveGhidraCheckpoint` selects the same saved Program because its key covers only the executable hash and profile. The launcher restores that Program with `-noanalysis`, so the newly staged symbols and types are ignored.

Commit the companion's presence and digest before choosing a checkpoint, and verify the staged copy against that commitment. The repository requires cache keys to cover inputs that affect results.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. The checkpoint manifest now records a companion_dsym_sha256 commitment, and resolution verifies the staged companion against it asymmetrically: when companion evidence exists at resolve time and does not match the recorded commitment (added later, changed content, or a rewritten commitment), the checkpoint is not reused and the target is analyzed fresh; when no companion is present there is no new evidence, so an existing Program stays reusable (preserving symbol provenance in the manifest). Wired through an optional targetPath argument at the provider call site.

Comment thread src/ghidra/GhidraTargetSnapshot.ts Resolved
Comment thread docs/reference/ghidra-12.2.md Resolved
Comment thread docs/reference/ghidra-12.2.md Resolved
@cainiao1992
cainiao1992 force-pushed the feat/ghidra-12.2 branch 4 times, most recently from 5f77805 to f2b8c26 Compare November 17, 2026 11:33
Comment thread src/ghidra/GhidraCheckpoint.ts Resolved
Comment thread src/ghidra/GhidraCheckpoint.ts Resolved
@morluto

morluto commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @cainiao1992! Most of this has since landed on main: #12081 made Ghidra 12.2 with JDK 25 the verified build and dropped 12.1.x, and Homebrew Ghidra discovery is already in GhidraInstallation.ts. The dSYM companion staging fix isn't on main yet, though, and we'd like to take it. Could you cut this PR down to just the dSYM change, rebased on current main? Thanks!

…ysis

Xcode 17 clang emits all DWARF into a sibling <name>.dSYM bundle while the
Mach-O keeps no debug sections. Ghidra's DWARF analyzer discovers that bundle
next to the staged executable's path, so the staged target-<hash>.bin lost
every DWARF symbol. Copy the source dSYM's DWARF member beside the snapshot
under the staged name with the existing cancellable chunked-copy path.

Include the companion's content digest in the checkpoint key so a newly
available or changed dSYM starts a fresh analysis instead of restoring a
Program built without its symbols. Targets without a companion keep the
established key, so existing checkpoints and analysis profiles stay reusable.
@cainiao1992 cainiao1992 changed the title feat(ghidra): verify against Ghidra 12.2 and discover Homebrew installs fix(ghidra): stage sibling dSYM beside target snapshot for DWARF analysis Nov 20, 2026
…bytes

The companion staging path copied the source DWARF member without the
coverage and same-regular-file checks its sibling readers already apply,
so a dSYM rewritten during the copy window staged truncated or mixed
bytes and Ghidra analyzed them as symbols with no signal. An unstable
companion now removes the partial staged bundle and keeps the snapshot's
no-companion semantics, matching the digest probe. The new regression
test grows the source mid-copy; reverting the fix fails it. Also correct
the test mock comment, which claimed to hook only the source member
while the pattern also matched the staged copy's open.
@cainiao1992

Copy link
Copy Markdown
Contributor Author

@morluto Done — this PR is now only the dSYM companion staging change, rebased on current main. The 12.2/JDK 25 and Homebrew discovery parts were dropped since they have already landed.

What remains:

  • Stage a caller-selected sibling <target>.dSYM DWARF member beside the staged snapshot under the staged name, using the existing cancellable chunked-copy path and verifying coverage/source identity so an unstable companion cannot stage mixed bytes.
  • Include the companion digest in the checkpoint key so a new or changed dSYM starts fresh analysis instead of restoring a Program analyzed without its symbols. Targets without a companion keep the established key, and the checkpoint manifest stays at version 2, so existing checkpoints and Evidence replay are unaffected.

Verified on macOS arm64 with real Ghidra 12.2 / JDK 25: a stripped arm64 Mach-O cannot resolve rea_dsym_marker without the dSYM, and resolves and decompiles it with the real dSYM present. Source checks: full src/ghidra suite (1297 passed, 1 skipped), checkpoint lifecycle boundary test (8 passed), check:fast and docs:check all pass. PR head is 63612ef.

Thanks!

@morluto morluto added area: evidence Evidence, artifacts, and reconstruction bug Something isn't working provider: ghidra Analysis provider / engine: ghidra labels Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants