Skip to content

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

Open
cainiao1992 wants to merge 1 commit into
morluto:mainfrom
cainiao1992:feat/ghidra-12.2
Open

cainiao1992 wants to merge 1 commit 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 analysis profile and 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.
  • When a companion stages, GhidraProvider commits its digest in the default analysis profile. Analysis snapshot bindings, Evidence, and checkpoint identity therefore cannot replay results built without those symbols; adding or changing a dSYM starts a separate analysis instead of restoring a Program built without them, and never overwrites the saved Program. Targets without a companion keep the established profile and checkpoint identity.
  • GhidraClient hashes the staged companion and compares it with the profile commitment before launch in both checkpoint and ephemeral modes. A mismatch refuses startup and asks the caller to reopen the target.
  • 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 profile and checkpoint identity change is deliberately additive for no-companion targets so existing profiles, manifests, snapshots, and Evidence remain valid. A companion changes which analysis inputs produced the Program, so it receives its own profile digest and key rather than reusing or overwriting incompatible saved results.

Contract and boundary impact

  • Semantic owner and earliest changed stage: GhidraCompanionDsym owns the digest probe and staging path; GhidraProvider commits the digest in the analysis profile; GhidraCheckpoint consumes the profile digest in the storage key; GhidraClient verifies the staged bytes against the profile commitment.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: sibling dSYM bundles stage under the staged snapshot name; targets without them keep the established profile and checkpoint identity.
  • Evidence, artifact, provenance, or reconstruction contract: the analysis profile gains an optional companion_dsym_sha256 parameter only when a companion stages. Snapshot and Evidence bindings that reference a companion-bearing profile therefore differ, while no-companion profiles, checkpoints, owned_checkpoint, and Evidence remain unchanged. The checkpoint manifest stays at version 2.
  • 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 the profile commits one, and content-bound identity; GhidraProvider.behavior.test.ts proves the dSYM digest changes the profile and invalidates its snapshot binding; ghidraCheckpointLifecycle.test.ts covers companion commitment and late addition in checkpoint and default modes.
  • 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 profile-binding and checkpoint-identity regressions at the staging, profile, storage, and lifecycle owners; 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 — 28 passed.
  • npx vitest run src/ghidra — 1423 passed, 1 skipped.
  • npm run test:focused -- tests/boundary/providers/ghidra/ghidraClient.test.ts tests/boundary/providers/ghidra/ghidraTargetSnapshot.test.ts tests/boundary/providers/ghidra/ghidraCheckpointLifecycle.test.ts — 127 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 profiles, checkpoints, and snapshots without a dSYM are unaffected; a new or changed dSYM intentionally changes the profile and 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 analysis and checkpoint selection for targets with sibling dSYM files.

Fix default-profile identity before merging so saved REA answers cannot hide added or changed debug symbols.

Findings

  1. P1 Saved answers miss new symbols ▶
Fix with agent prompt
### Issue 1
src/ghidra/GhidraTargetSnapshot.ts:134-140
Without checkpoint mode, staging a dSYM changes Ghidra's symbols but leaves the analysis profile unchanged. Save a REA analysis snapshot without the companion, then add it and reopen with that snapshot: the target/profile checks still pass, so symbol-dependent reads can return old names and types without running Ghidra.

Bind the companion digest into the default analysis profile too, and check the staged digest before launch. The repository requires cache keys to cover inputs that affect results.

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

Stages sibling dSYM bytes beside the renamed target and gives companion-bearing checkpoints their own content-bound keys.

  • Ghidra snapshots bring along the matching sibling dSYM.
  • Ghidra checkpoints follow the contents of a sibling dSYM.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Selected target] --> B{Checkpoint mode?}
  B -->|Yes| C[Hash companion into checkpoint key]
  B -->|No| D[Keep existing analysis profile]
  C --> E[Stage target and companion]
  E --> F[Check staged digest before launch]
  D --> G[Look up saved REA answers]
  G -->|Matching target and profile| H[Replay old answer]
Loading

Reviews (4) · Last reviewed commit: "fix(ghidra): keep dSYM key verification ..." · Reviewed by Greptile

Comment thread src/ghidra/GhidraTargetSnapshot.ts Resolved
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!

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

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@cainiao1992 thanks for the PR — there is 1 open review thread here:

Could you address or reply to this? Once it's resolved and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

Comment thread src/ghidra/GhidraTargetSnapshot.ts Resolved
…ysis

Xcode 17 clang emits all DWARF into a sibling <name>.dSYM bundle while the Mach-O keeps no __debug_info. Ghidra's DWARFAnalyzer 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.

Stage the caller-selected sibling dSYM DWARF member beside the snapshot under the staged name with the existing cancellable chunked-copy path, verifying read coverage and source identity. Absent, malformed, or unreadable companions keep the snapshot's unknown-symbol semantics; cancellation propagates.

When a companion stages, commit its content digest in the analysis profile and use that profile in the checkpoint key. Analysis snapshots, Evidence, and checkpoints therefore cannot replay results produced without the companion, and a changed dSYM starts a separate analysis. Targets without a companion keep the established profile and checkpoint identity.

Before launch, hash the staged companion and compare it with the profile commitment in both checkpoint and ephemeral modes. A dSYM that appears, disappears, or changes after profile resolution refuses startup and asks the caller to reopen the target instead of analyzing under a different identity.

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