Skip to content

feat(apple): project macOS bundle anatomy in application graphs - #922

Merged
kaoru0822-kitauji merged 6 commits into
mainfrom
feat/macos-bundle-anatomy
Oct 7, 2026
Merged

kaoru0822-kitauji merged 6 commits into
mainfrom
feat/macos-bundle-anatomy

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Builds on #921, which this branch includes as its first commit. The DMG case of the new real lane needs that fix. Once #921 merges, this diff shrinks to the feature commit.

Summary

project_apple_application_graph accepted only IPA inventories. A macOS analyst's first question about a .app (what runs out of this bundle?) had no answer: XPC services, app extensions, login items, privileged helpers, system extensions and launchd jobs. The tool now projects macOS .app directories, and ZIP or DMG inventories that contain apps, into that anatomy. It stays execution-free and reads only paths and hashes.

Change and scope

This extends the existing tool rather than adding one, because the intent (project an Apple app inventory) and the result contract are unchanged. The schema change is additive. The domain logic is in the new src/domain/appleBundleAnatomy.ts.

Application roots

Inventory root Application root
IPA Payload/*.app (unchanged)
.app directory .
Directory, ditto ZIP, or DMG Each outermost *.app/Contents

New result fields

  • bundles: every application root and nested bundle, with parent_path, layout (macos-deep, versioned-framework or shallow), a path-convention role, info_plist_path, executable_candidates and signing_paths.
    • Roles: app-extension, xpc-service (including XPC services inside frameworks), framework, login-item, system-extension, driver-extension, plug-in, resource-bundle, bundle, helper-application and nested-application.
  • components.privileged_helpers: Contents/Library/LaunchServices/*.
  • components.launchd_plists: Contents/Library/Launch{Agents,Daemons}/*.plist, each with domain.
  • components.helpers: Contents/Helpers/*.
  • symlinks and platforms.

Behaviour

  • Symlink targets are not inventoried, so versioned frameworks are described through their real Versions/<version>/ directories. If the Info.plist that Versions/Current selects cannot be determined, it is null with a limitation.
  • AppleDouble sidecars (._*, __MACOSX/) are excluded from roles.
  • A DMG whose contents were not inventoried, such as one inventoried off macOS, is partial.
  • APK, ASAR and other formats remain input errors.

Not included: plist or CMS semantics. Roles come from path conventions, and the result points callers to inspect_plist for each info_plist_path. Dylib-load resolution is the planned follow-up.

Contract and boundary impact

  • Semantic owner: src/domain/appleBundleAnatomy.ts and src/domain/appleApplication.ts.
  • CLI and MCP contract: the output schema gains fields; the root_format enum widens from ipa to ipa | directory | zip | dmg. There is a new catalog example for a .app directory, and the descriptions are updated. Input is unchanged.
  • Evidence: the projection subject keeps the inventory subject's format instead of always ipa. projection_id now covers the new fields, so IPA projection IDs differ from earlier versions. No doc promises cross-version ID stability, so this is not marked breaking.
  • Generated metadata: product catalog, MCP tool catalog, skill (version 27) and conformance-manifest digests are regenerated.

Sanitized MCP result for the lane's fixture app, as a directory and trimmed:

{
  "root_format": "directory",
  "platforms": ["macos"],
  "application_roots": ["."],
  "bundles": [
    { "path": ".", "role": "application", "layout": "macos-deep", "parent_path": null,
      "info_plist_path": "Contents/Info.plist", "executable_candidates": ["Contents/MacOS/MacFixture"],
      "signing_paths": ["Contents/_CodeSignature/CodeResources"], "role_basis": "path-convention" },
    { "path": "Contents/Frameworks/Core.framework", "role": "framework", "layout": "versioned-framework",
      "parent_path": ".", "info_plist_path": "Contents/Frameworks/Core.framework/Versions/A/Resources/Info.plist" },
    { "path": "Contents/Frameworks/Core.framework/Versions/A/XPCServices/FwSvc.xpc", "role": "xpc-service",
      "parent_path": "Contents/Frameworks/Core.framework" },
    { "path": "Contents/Library/LoginItems/Login.app", "role": "login-item" },
    { "path": "Contents/PlugIns/Ext.appex", "role": "app-extension" },
    { "path": "Contents/XPCServices/Svc.xpc", "role": "xpc-service" }
  ],
  "components": {
    "privileged_helpers": [{ "path": "Contents/Library/LaunchServices/com.example.rea.helper" }],
    "launchd_plists": [
      { "path": "Contents/Library/LaunchAgents/com.example.rea.agent.plist", "domain": "agent" },
      { "path": "Contents/Library/LaunchDaemons/com.example.rea.helper.plist", "domain": "daemon" }
    ],
    "helpers": [{ "path": "Contents/Helpers/rea-tool" }]
  },
  "symlinks": ["Contents/Frameworks/Core.framework/Versions/Current"]
}

Evidence and regression coverage

  • src/domain/appleApplication.test.ts (new, 8 cases):

    • an .app directory as its own root, plus every role;
    • a non-.app bundle directory that is not an application root;
    • versioned frameworks without Versions/Current, and ambiguous versions;
    • AppleDouble sidecars;
    • a DMG without inventoried contents;
    • IPA shallow and iOS;
    • rejection of ASAR.
  • tests/composition/analysis-sessions/appleApplication.test.ts:

    • a real .app directory inventory through inventory_artifact;
    • a non-application ZIP now reports no roots instead of being rejected;
    • an APK is rejected.
  • Real lane npm run verify:macos-bundle, also added to the macOS CI job. It uses Command Line Tools only:

    • compiles a source-owned app with clang and signs it ad hoc;
    • packs it as a directory, a ditto ZIP, and an APFS DMG;
    • asserts identical anatomy across the three through the CLI, with stdio MCP parity;
    • asserts the DMG is detached afterwards.
  • Real apps in /Applications, on this branch's build:

    App Observed anatomy
    KeepingYouAwake login item; Sparkle Updater.app and two XPC services inside Sparkle.framework/Versions/B
    Raycast ExtensionKit .appex under Contents/Extensions; login item; 9 SwiftPM resource bundles
    Brave Browser SMJobBless UpdaterPrivilegedHelper; 9 helper apps under the framework's Versions/<ver>/Helpers
    OneDrive FinderSync and File Provider extensions; two login items
    Shadowrocket four .appex; a Catalyst bridge plug-in
    Discord Electron helpers as nested applications
  • Remaining proof gaps: roles are path conventions, not plist-verified. ZIP/IPA inventories without directory entries still project, through implied ancestors.

Validation performed

  • npm run check:changed: 289 files passed.
  • npm run test:focused -- tests/composition/analysis-sessions/appleApplication.test.ts tests/boundary/mcp/mobileApplicationGraphMcp.test.ts tests/boundary/cli/productCatalog.test.ts tests/boundary/mcp/toolSchemaValidity.test.ts tests/acceptance/contractPresentation.test.ts: passed.
  • npm run docs:generate && npm run docs:check: passed.
  • npm run verify:macos-bundle: {"ok":true,"mocked":false,"cli":true,"stdio_mcp":true,"containers":["directory","zip","dmg"],"bundles":6,"dmg_detached":true}.

Compatibility, safety, and release

  • Breaking changes: none to the input. The result is additive, but projection_id values change.
  • Real Hopper/Ghidra coverage: not applicable; no provider is touched.
  • Real OS coverage: macOS 26.6.2 arm64 locally, and the macOS 14 CI job.
  • Security and containment: execution-free, with no new process or filesystem effects. The lane's fixtures are built in a temporary directory and removed afterwards.

🤖 Generated with Claude Code

kaoru0822-kitauji and others added 2 commits October 7, 2026 10:06
An APFS disk image attaches as an image disk plus a synthesized APFS
container, and hdiutil reports both as whole disks. Detaching the
container also ejects the image disk, so the reverse-order detach then
failed with "No such file or directory" and every APFS DMG inventory
ended in "DMG detach or mount-root cleanup failed". APFS is the default
format of `hdiutil create` on current macOS.

When a detach fails, ask `hdiutil info -plist` whether the device is
still attached. A device that is gone counts as detached; one that is
still listed, or whose state cannot be read, remains a cleanup failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
project_apple_application_graph accepted only IPA inventories. It now
also projects macOS .app directories and ZIP or DMG inventories that
contain applications. It reports application roots, platforms, and
every nested bundle with its path-convention role, layout, parent,
Info.plist path, executable candidates, and signing paths:
- roles: app extensions, XPC services (including inside frameworks),
  frameworks, login items, system and driver extensions, plug-ins,
  resource bundles, and helper or nested applications;
- privileged helpers in Contents/Library/LaunchServices and launchd
  plists in Contents/Library/LaunchAgents or LaunchDaemons;
- direct files of Contents/Helpers;
- symlinks by path. Their targets are not inventoried, so versioned
  frameworks are described through their real Versions/<version>/
  directories.

AppleDouble sidecars (._* and __MACOSX/) are excluded from roles. A DMG
whose contents could not be inventoried is reported as partial. Other
inventory formats remain input errors. The projection still reads no
plist or CMS semantics; it points callers at inspect_plist.

The result schema is additive. projection_id now covers the new fields,
so IPA projection IDs differ from earlier versions.

verify:macos-bundle compiles a source-owned app with clang (CLT only).
It packs it as a directory, a ditto ZIP, and an APFS DMG, and checks
identical anatomy through the CLI with stdio MCP parity. It runs in the
macOS CI job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

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 ✅ Completed 2026-10-07T10:48:22.509853Z fd552a8 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd3e7aef0d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 220 to 222
frameworks: all.filter(({ path }) => /\.framework\//u.test(path)),
native_libraries: all.filter(({ path }) => /\.(?:dylib|so)$/iu.test(path)),
javascript: all.filter(({ format }) => format === "javascript-bundle"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scope projected components to discovered application roots

When a newly accepted ZIP or DMG contains an application plus sibling content, these filters classify every matching framework, dylib, or JavaScript file in the container, even when it is outside every application_roots entry. The same unscoped all collection feeds runtime-family detection, while unscoped JavaScript and native libraries generate cross-boundary bridge candidates, so unrelated installer or disk-image files are falsely attributed to the application. Filter all component and runtime inputs by withinApp (and sidecar status), as is already done for executables and anatomy components.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. In 5524970, directory, ZIP and DMG projections attribute only components inside an application root, and AppleDouble sidecars are excluded. That scope applies to the component categories, runtime families and bridge candidates. A limitation reports how many inventoried entries were left out. IPA projection is unchanged and still lists archive components such as SwiftSupport/. New domain tests cover a ZIP with sibling Extras/ content, and the IPA SwiftSupport case.

Comment thread src/domain/appleBundleAnatomy.ts Outdated
Comment on lines +86 to +89
if (
/\.app$/iu.test(subjectName) &&
/^Contents\/(?:Info\.plist|MacOS\/[^/]+)$/u.test(path)
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize the selected .app directory without content anchors

When the selected inventory subject itself ends in .app but the supplied inventory is empty, partial, malformed, or simply lacks Contents/Info.plist and a direct Contents/MacOS/* entry, this condition never adds .. The result consequently reports no application root and no platform despite the caller having selected an .app directory; derive the root from the directory subject identity and let coverage/limitations describe missing contents instead of discarding that identity.

AGENTS.md reference: AGENTS.md:L16-L16

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. In 5524970, a directory subject whose name ends in .app is its own root (.) by identity, whatever the inventory contains. Coverage and limitations still describe partial inventories. To avoid a guessed platform, ios is now claimed only for shallow roots with an Info.plist, so an empty .app inventory reports the root with platforms: []. Tests cover the empty and partial .app inventories.

kaoru0822-kitauji and others added 3 commits October 7, 2026 10:28
The inventory snapshot captures reader provenance before close() runs,
so a `hdiutil info -plist` entry recorded during cleanup never reached
CLI or MCP results. Detach entries already share that timing. Record
neither instead of implying the query is observable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tories

Directory, ZIP, and DMG inventories can hold installers, disk-image
extras, and AppleDouble sidecars beside the app. Those components were
classified as the application's frameworks, libraries, JavaScript, and
metadata, and fed runtime families and bridge candidates. For these
formats, components outside every application root are now left out,
with a limitation that counts them. IPA projection is unchanged.

A selected directory whose name ends in .app is now its own root by
identity, so an empty or partial inventory still reports it. iOS is
claimed only for shallow roots that have an Info.plist, so an empty root
reports no platform.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 55249704c5

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +207 to +209
const all = visible.filter(({ path }) =>
roots.some((root) => isWithin(path, root)),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Partition bridge hypotheses by application root

When a ZIP or DMG contains two outer applications, this filter combines components from both roots into one flat all collection, and identifyBridgeCandidates later forms a Cartesian product from it. A JavaScript file in First.app is therefore reported as bridging to every native binary in Second.app, even though the paths identify separate applications; preserve each component's owning root and only pair components within that root.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. In 67743e9, bridge candidates pair a script only with native code owned by the same application root; components outside every root pair only with each other. A new test covers a ZIP with First.app and Second.app and checks that no cross-application pairs remain.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#922 merged before this fix was pushed. The change is now in follow-up #931 against main.

),
)
.filter((path) => tree.files.has(path));
return candidates.length === 1 ? (candidates[0] ?? null) : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep ambiguous framework Info.plist paths unknown

When a versioned framework has both Versions/A and Versions/B but only A contains Resources/Info.plist, this returns A's plist solely because there is one existing candidate. Since the inventory deliberately omits the Versions/Current symlink target, Current may select B, so the bundle's plist is still unknown; base this decision on an unambiguous version selection rather than the number of plist files.

AGENTS.md reference: AGENTS.md:L56-L56

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. In 67743e9, a versioned framework's info_plist_path is chosen only when exactly one real Versions/<v>/ directory exists. With several versions it stays null whether or not each has a plist, because Versions/Current is not inventoried. The limitation text now says this, and a test covers A having a plist while B does not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#922 merged before this fix was pushed. The change is now in follow-up #931 against main.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 88c940b into main Oct 7, 2026
28 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the feat/macos-bundle-anatomy branch October 7, 2026 10:59
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
feat(apple): project macOS bundle anatomy in application graphs
@morluto morluto added the enhancement New feature or request label Oct 14, 2026
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 26, 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.

2 participants