Repository navigation
feat(artifacts): trace Mach-O dylib resolution in bundles - #927
Conversation
Add trace_dylib_resolution (CLI trace-dylib-resolution) to the artifact family. For the active Mach-O, or every executable in the active .app (the main app, XPC services, extensions, login items, helpers), it reports which file each dylib load reaches and how. A pure TypeScript reader decodes FAT and Mach-O load commands: LC_LOAD/WEAK/REEXPORT/LAZY/UPWARD_DYLIB, including the newer dylib_use_command encoding with weak, re-export, upward and delayed-init flags, plus LC_ID_DYLIB, LC_RPATH, LC_DYLD_ENVIRONMENT and code-signature presence. Malformed tables are reported with the failing command instead of being guessed. Resolution follows dyld: - @executable_path comes from each process root; - @loader_path comes from the loading image, or from the owner of the LC_RPATH entry being expanded; - @rpath searches the loader's rpaths first, then up the load chain; - dependencies load dependents-first in load-command order, once per process, and a matching install name reuses an already loaded image; - symlinks are followed inside the analyzed root, and escapes stop. Every candidate path is reported with its outcome. Each edge resolves to resolved, conditional (an outside-root candidate such as /usr/lib/swift precedes), unresolved, or undetermined. Absolute and shared-cache system paths are never checked against the host. Derived findings cover unresolved required or weak loads, absent earlier @rpath candidates (with library validation left unknown), and LC_DYLD_ENVIRONMENT. verify:macos-bundle now also: - checks every traced image against otool -l; - asserts each resolution status on a clang-built fixture that adds a missing Overrides rpath, an absolute rpath, and a delay-init library; - compares the predicted load order of two process roots with what dyld loads under DYLD_PRINT_LIBRARIES. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 11b7f918c2
ℹ️ 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".
| : facts.slices.some( | ||
| ({ architecture }) => architecture === context.architecture, | ||
| ) |
There was a problem hiding this comment.
Match dyld-compatible CPU subtypes
When an x86_64h process root loads a dylib containing only a generic x86_64 slice, dyld can use that compatible fallback, but this strict label comparison reports architecture-missing. The parser explicitly distinguishes x86_64h, so affected bundles receive false unresolved edges and potentially false required-load-unresolved findings; match Mach-O CPU subtype compatibility rather than requiring identical display names.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In a0ec3e2, slices are chosen by dyld's graded architectures. An x86_64h process prefers x86_64h and falls back to x86_64; other architectures match exactly. The same selection drives candidate outcomes, install_name_matches, and the slice used to continue loading. A limitation states that the arm64e keys-off fallback to arm64 is not modeled. A new domain test covers x86_64h loading x86_64, and arm64e not loading arm64.
| const magic = view.getUint32(0, false); | ||
| if (magic === FAT_MAGIC || magic === FAT_MAGIC_64) { |
There was a problem hiding this comment.
Parse swapped FAT headers accepted during target opening
For a valid FAT_CIGAM or FAT_CIGAM_64 image, parseExecutableHeader already recognizes the byte-swapped magics 0xbebafeca and 0xbfbafeca, so the target can be opened successfully, but this reader recognizes only FAT_MAGIC variants and subsequently rejects the active root as not Mach-O. Add the swapped FAT constants and read their architecture table using the corresponding byte order.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In a0ec3e2, FAT_CIGAM and FAT_CIGAM_64 (0xbebafeca and 0xbfbafeca) are recognized, and their architecture tables are read little-endian. The reader test now covers FAT and FAT_64 in both byte orders.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 71e5cb1640
ℹ️ 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".
| minimumOffset: number, | ||
| index: number, | ||
| ): string => { | ||
| const offset = viewOf(body).getUint32(8, true); |
There was a problem hiding this comment.
Guard short string-bearing load commands
When an LC_ID_DYLIB, LC_RPATH, or LC_DYLD_ENVIRONMENT command has cmdsize == 8, the generic command-table validation accepts it, but this read at offset 8 throws a native RangeError. Because readMachoImage only converts MachoFormatIssue, tracing that malformed image fails as a generic I/O error instead of reporting its malformed parse status; validate the command body length before reading the string offset.
AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In a0ec3e2, a string-bearing command shorter than 12 bytes is reported as malformed ("load command N is too short to hold a string offset") before its offset is read. A regression test covers an LC_RPATH with cmdsize 8.
| : facts.status !== "parsed" | ||
| ? "malformed" |
There was a problem hiding this comment.
Retain unsupported candidates as unsupported
When a candidate is a recognized but unsupported Mach-O, such as a big-endian image or one exceeding the load-command resource limit, this branch labels it malformed. The same result can therefore report the image's parse_status as unsupported while its candidate outcome says malformed, erasing the distinction callers need to determine whether the bytes are invalid or merely outside parser coverage; add and preserve an unsupported outcome.
AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In a0ec3e2, candidates have an unsupported outcome, mirroring the image's parse_status. Because dyld may still load such an image, it is treated like an outside-root candidate: the edge becomes undetermined, or conditional when a later in-root candidate resolves. It is not unresolved. A test covers a big-endian dependency.
| const facts = await view.image(entry.path); | ||
| if ( | ||
| facts.status === "parsed" && | ||
| facts.slices.some(({ file_type: type }) => type === "execute") |
There was a problem hiding this comment.
Mark skipped unparsed root candidates as partial
When auto-enumerating a .app, every Mach-O-magic file whose parser result is malformed or unsupported is silently omitted here. Since those facts are not transferred into traceDylibLoading's image map, the final coverage can still be complete even though the tool could not determine whether such a file is an executable process root—for example, a valid big-endian executable is skipped without any limitation. Preserve these candidates as coverage unknowns so the advertised all-executable traversal does not overstate completeness.
AGENTS.md reference: AGENTS.md:L62-L62
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In a0ec3e2, root enumeration returns Mach-O files that are malformed or unsupported as unclassified. The trace reports them in images with their reason and in coverage.unparsed_images, so coverage becomes partial. A CLI boundary test adds a broken helper to a bundle and checks partial coverage.
# Conflicts: # docs/product-catalog.json # docs/verification/managed-conformance-manifest.json # skills/reverse-engineer-anything/SKILL.md # src/generatedMcpToolCatalog.ts
Address review findings in trace_dylib_resolution: - Choose child slices by dyld's graded architectures, so an x86_64h process loads a generic x86_64 slice instead of reporting architecture-missing. - Read FAT containers with the byte-swapped FAT_CIGAM and FAT_CIGAM_64 magics, which target opening already accepts. - Report string-bearing load commands too short to hold their string offset as malformed instead of failing with a RangeError. - Keep recognized but unsupported images as an `unsupported` candidate outcome. It is undeterminable like an outside-root path, not malformed. - List Mach-O files that do not parse during root enumeration as unparsed images, so coverage is partial rather than silently complete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0ec3e2016
ℹ️ 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".
| const current = context.loaded.get(loader); | ||
| if (current === undefined) continue; | ||
| const created: string[] = []; | ||
| for (const dependency of current.slice.dependencies) { |
There was a problem hiding this comment.
Do not eagerly traverse lazy-load commands
When an image contains LC_LAZY_LOAD_DYLIB, this loop resolves and enqueues it exactly like an eager dependency. Apple defines that command as delaying the load until first use in loader.h, so an unused missing lazy library must not produce a required-load-unresolved finding claiming the process would fail to launch, nor should its transitive dependencies appear in the launch-time graph. Preserve the deferred state and avoid traversing it unconditionally.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In 9128039, LC_LAZY_LOAD_DYLIB edges are still resolved and reported with their candidates, but the image is not loaded or traversed, since dyld loads it on first use. An unresolved lazy load now yields a lazy-load-unresolved finding that describes a first-use failure, not required-load-unresolved. A limitation states the deferral, and a domain test covers both a resolved and a missing lazy load.
| if (count === 0 || count >= MAX_FAT_ARCHITECTURES) | ||
| return { status: "not-mach-o" }; |
There was a problem hiding this comment.
Classify accepted FAT architecture counts consistently
For a FAT image with 20–128 architecture records, the target-opening parser accepts the count through 128 in src/domain/binaryTarget.ts, but this branch returns not-mach-o before reading any slices. Consequently the same valid active target can be opened successfully and then rejected by trace_dylib_resolution as non-Mach-O, while such a file inside a bundle is silently omitted from coverage; align the limits, or preserve the recognized image as explicitly unsupported rather than changing its format identity.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In 9128039, the reader accepts FAT counts up to 128, as parseFatMachO does when opening targets. A table that names no known Mach-O CPU type (x86, x86_64, arm, arm64, arm64_32, ppc, ppc64), or that does not fit in the file, is classified not-mach-o; this is the Java class-file case. A test covers a 24-slice FAT.
| ); | ||
| const command = view.getUint32(offset, true); | ||
| const size = view.getUint32(offset + 4, true); | ||
| if (size < 8 || size % 4 !== 0 || offset + size > bytes.byteLength) |
There was a problem hiding this comment.
Enforce 8-byte command alignment for 64-bit slices
For a 64-bit Mach-O whose load command has a cmdsize divisible by 4 but not 8, this validation accepts the command and can report the image as parsed even though the Mach-O contract requires 64-bit load commands to be 8-byte aligned, as documented in Apple's loader.h. Pass the slice width into command decoding and validate % 8 for 64-bit images so malformed inputs cannot yield trusted resolution facts.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In 9128039, command decoding takes the slice width and requires cmdsize % 8 === 0 for 64-bit images and % 4 for 32-bit ones. I re-ran the otool -l conformance over 1,508 real slices in 767 images; all parse with no mismatches. Tests cover a 12-byte command in a 64-bit image (malformed) and in a 32-bit image (accepted).
| "Dylib resolution was cancelled", | ||
| { cause }, | ||
| ); | ||
| throw cause; |
There was a problem hiding this comment.
Preserve filesystem permission diagnostics
When probing a root or dependency fails with EACCES or EPERM, this rethrows the raw Node error, after which ArtifactProvider.translateFailure converts it to a detail-free generic io failure. The CLI/MCP caller therefore loses both the permission-denial reason and the affected path, making the documented recovery guidance unactionable; translate filesystem failures here into a typed failure that retains the error code and candidate path.
AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In 9128039, EACCES/EPERM from any probe, header read, hash or enumeration becomes an unavailable ArtifactReaderFailure whose detail names the code and the path relative to the analyzed root, for example Permission denied (EACCES) reading libsecret.dylib. It no longer falls through as generic io. A CLI boundary test covers an unreadable dependency; it is skipped when running as root.
Address review findings in trace_dylib_resolution: - Resolve LC_LAZY_LOAD_DYLIB dependencies without traversing them, since dyld loads them on first use. An unresolved one becomes `lazy-load-unresolved`, not a launch failure. - Accept FAT tables up to 128 records, as target opening does. A table that names no Mach-O CPU type, such as a Java class file, is not Mach-O. - Require 8-byte load-command alignment in 64-bit images. 1,508 real slices still match otool. - Report EACCES/EPERM while probing, reading, or hashing as an `unavailable` failure naming the code and path, rather than generic io. Findings and limitations move to dylibResolutionFindings.ts to keep the resolver under the module size limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91280393cd
ℹ️ 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".
| : compatibleSlice(facts.slices, context.architecture) === undefined | ||
| ? "architecture-missing" | ||
| : "resolved"; |
There was a problem hiding this comment.
Reject candidates with incompatible dylib versions
When an in-root candidate has the requested architecture but its LC_ID_DYLIB version is older than the version required by the loader's LC_LOAD_* command, dyld rejects the launch as an incompatible library version, as documented by Apple's linker manual. This branch nevertheless marks the candidate resolved solely from architecture, while the parser discards the ID command's version fields, so the trace can omit a required-load failure and traverse a graph that cannot run; preserve those fields and validate compatibility before returning resolved.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I checked this against real dyld before changing anything, and I am keeping the resolution as is, with a stated limitation.
The test on macOS 26 (Darwin 25.6, arm64):
- I built
libc1.dylibwith-compatibility_version 2.0and linked an app against it through@rpath.otool -Lshowscompatibility version 2.0.0. - I then replaced the dylib with one built with
-compatibility_version 1.0and re-signed it ad hoc. - The app launched and exited 0. The result was the same with
-mmacosx-version-min=10.13.
So current dyld does not reject this case. Marking such a candidate unresolved would contradict the observed runtime. Since ef245c0, the limitations say that compatibility versions are not compared. They also say that the linker documentation describes a load-time rejection while dyld on macOS 26 was observed to load the image, so analysts targeting older macOS know to check otool -L themselves.
| const bundle = this.target.sourcePath?.toLowerCase().endsWith(".app") | ||
| ? this.target.sourcePath | ||
| : undefined; |
There was a problem hiding this comment.
Detect app bundles from resolved bundle metadata
When a standalone Mach-O file merely has a name ending in .app, BinaryTargetResolver accepts it as a regular file and leaves bundleInfoPlist unset, but this suffix check treats that file as a bundle directory. The trace then sets rootPath to the file and enables root enumeration, causing DirectoryArtifactReader to fail with ENOTDIR instead of tracing the standalone image; use the target's resolved bundle metadata rather than the source-path suffix.
AGENTS.md reference: AGENTS.md:L54-L54
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Since ef245c0, the trace treats the target as a bundle only when open_binary resolved it from an app bundle directory, which is when the target carries bundleInfoPlist. A regular Mach-O file whose name ends in .app is traced from its parent directory. A new MCP boundary test opens a Tool.app file with an @loader_path dependency. Without the fix it failed on enumerating the file as a directory; with the fix it resolves.
| const count = view.getUint32(4, littleEndian); | ||
| const wide = magic === FAT_MAGIC_64 || magic === FAT_CIGAM_64; | ||
| if ( | ||
| count === 0 || |
There was a problem hiding this comment.
Preserve zero-slice FAT files as malformed
Fresh evidence after the earlier root-coverage fix is the count === 0 arm of this condition: a file with recognized FAT magic and zero architecture records is returned as not-mach-o. During bundle enumeration it has already passed hasMachoMagic, but executableRoots adds only malformed or unsupported results to unclassified, so this malformed image disappears and coverage can still be reported as complete; classify the zero-record FAT header as malformed so it remains visible in coverage and diagnostics.
AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Since ef245c0, a FAT header with zero architecture records is reported as malformed ("FAT header declares no architectures"), so it lands in unclassified and makes coverage partial. A Java class file cannot produce a zero count because its major version, which reads as the count, is nonzero. The reader test covers the big-endian and swapped FAT_64 magics.
# Conflicts: # docs/product-catalog.json # docs/verification/managed-conformance-manifest.json # skills/reverse-engineer-anything/SKILL.md # src/generatedMcpToolCatalog.ts
…tables - Treat the target as a bundle only when it was opened from an app bundle directory (it carries the bundle's Info.plist); a regular Mach-O file whose name ends in .app is traced from its parent directory. - Classify a FAT header with zero architecture records as malformed, so it stays visible in unclassified roots and coverage. - State that dylib compatibility versions are not compared. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef245c0bd0
ℹ️ 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".
| const image = edge.resolution.image; | ||
| if (image === null || context.loaded.has(image)) continue; |
There was a problem hiding this comment.
Stop traversing a merely conditional image
When an outside-target or unsupported candidate precedes an in-root fallback, the edge is correctly marked conditional, but this code still enqueues the fallback and treats its install name as loaded. If the unknown earlier candidate actually wins, the bundled image is never loaded, so its transitive edges, install-name reuse, and required-load-unresolved findings describe the wrong graph; either avoid traversing conditional resolutions or propagate that uncertainty through every descendant.
AGENTS.md reference: AGENTS.md:L56-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Since 5e334a0, the in-root fallback of a conditional edge is still traced, because it is the image the bundle supplies, but its uncertainty propagates:
- every edge below it has
loader_conditional: true; - a later request that reuses it by install name resolves as
conditional, notresolved; required-load-unresolvedfindings on those edges say that the loader "loads only conditionally; if it loads, dyld would fail…".
The load-order limitation also says that conditionality, like the rpath stack, comes from the first chain that reached an image. A domain test covers the descendant edge, the reuse and the finding text.
| for (const { path } of trace.images) | ||
| digests.set(path, await fileSha256(join(root, path), options.signal)); |
There was a problem hiding this comment.
Bind each image digest to the bytes that were parsed
When any traced dependency changes after readImage closes its handle but before this digest pass reopens it, the returned sha256 describes the new bytes while the slices and edges describe the old bytes. Only the active target digest is checked against a prior value, so changes to other images go undetected; hash from the parsing handle or verify a stable file identity/content snapshot before returning the evidence.
AGENTS.md reference: AGENTS.md:L16-L16
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Since 5e334a0, the header read records the parsed file's device, inode, size, and mtime/ctime in nanoseconds. Before returning a digest, the hash pass compares that identity with fstat on its own handle before and after reading. A mismatch fails with integrity (" changed while its dyld load commands were traced"), so a returned sha256 always belongs to the file whose load commands were reported. I did not add a racing filesystem test for this, because it would be timing-dependent.
| if (command === LC_CODE_SIGNATURE) { | ||
| slice.code_signature_present = true; |
There was a problem hiding this comment.
Validate the full LC_CODE_SIGNATURE command body
When LC_CODE_SIGNATURE has cmdsize == 8, it passes the generic alignment checks and is marked present here even though the command is a 16-byte linkedit_data_command. A dependency containing this truncated command can consequently be classified as parsed and resolved although dyld rejects its malformed load-command table; require at least the complete command body before setting the flag.
AGENTS.md reference: AGENTS.md:L54-L54
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Since 5e334a0, LC_CODE_SIGNATURE must hold the complete 16-byte linkedit_data_command. A shorter one makes the image malformed ("load command N is too short for LC_CODE_SIGNATURE"). The reader test covers the 8-byte case, and the alignment test now uses a command the reader does not decode.
# Conflicts: # docs/product-catalog.json # docs/verification/managed-conformance-manifest.json # skills/reverse-engineer-anything/SKILL.md # src/generatedMcpToolCatalog.ts
…d images - Edges below a conditional fallback now carry loader_conditional, reuse of a conditional image by install name is conditional, and their findings say they apply only if that image loads. - Hash each traced image only if it is still the file whose headers were parsed (device, inode, size and change times), before and after hashing. - Resolve explicit roots segment by segment, so a root below a symlinked directory that points outside the analyzed root is rejected. - Require a complete 16-byte LC_CODE_SIGNATURE command. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e334a0e12
ℹ️ 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".
| ): Promise<MachoImageFacts> => { | ||
| try { | ||
| const head = await readAt(0, Math.min(size, 8)); | ||
| if (head.byteLength < 8) return { status: "not-mach-o" }; |
There was a problem hiding this comment.
Classify truncated thin Mach-O headers as malformed
A remaining case after the unparsed-root fix is a thin file containing a recognized Mach-O magic but only 4–7 bytes: startsWithMachoMagic selects it during bundle enumeration, but this early return labels it not-mach-o. executableRoots retains only malformed or unsupported results, so the file disappears and coverage can incorrectly remain complete; an explicitly selected root likewise receives the misleading “not a Mach-O image” error. Inspect the magic once four bytes are available and classify a recognized but truncated thin header as malformed.
AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Since 9a487a4, a file with a recognized Mach-O or FAT magic but fewer than 8 bytes is malformed ("Mach-O header is truncated"), not not-mach-o. It now stays in unclassified, so coverage is partial, and an explicit root gets a format diagnostic. The reader test covers a 6-byte MH_MAGIC_64 file.
| const root = await realpath(options.rootPath); | ||
| const target = relative(root, await realpath(options.targetPath)) |
There was a problem hiding this comment.
Translate permission failures during path canonicalization
A remaining gap after the permission-handling fix is that both realpath calls execute before the protected try. If access to the bundle or target is revoked after open_binary, an EACCES/EPERM here bypasses permissionDenied and is reduced by ArtifactProvider.translateFailure to a detail-free io error, losing both the denial reason and affected path. Move canonicalization into the translated region so these filesystem failures retain the same diagnostics as later probes.
AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Since 9a487a4, realpath of the analyzed root and the target runs inside the translated region. An EACCES/EPERM raised there becomes unavailable with "Permission denied (EACCES) reading ", and the path is shown absolute when it lies outside the root. An MCP boundary test opens a bundle, revokes its parent directory's permissions, and expects that diagnostic. (This round also merges main and moves these modules under src/artifacts/apple/ and src/domain/apple/, following #952.)
Follow #952's Apple ownership: the Mach-O load-command reader, dylib resolution adapter and fixture move to src/artifacts/apple/, the resolver, dyld path semantics and findings to src/domain/apple/, and the dylib lane helper to scripts/verify/apple/. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on denials - A file with a recognized Mach-O or FAT magic but fewer than 8 bytes is a malformed image, so it stays visible in coverage and root diagnostics. - Canonicalize the analyzed root and target inside the translated region, so a permission revoked after open_binary keeps its reason and path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Weak and lazy unresolved-load findings on edges whose loader loads only conditionally now say that they apply only if that loader loads, as the required-load finding already did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 002503d0c0
ℹ️ 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".
| : compatibleSlice(facts.slices, context.architecture) === undefined | ||
| ? "architecture-missing" | ||
| : "resolved"; |
There was a problem hiding this comment.
Check platform compatibility before resolving candidates
When a process root and an in-root candidate have the same CPU architecture but different Mach-O platforms—for example, a macOS arm64 executable loading an iOS arm64 dylib—this branch marks the first candidate resolved and stops searching. Dyld's validMachOForArchAndPlatform also requires loadableIntoProcess, so dyld rejects that candidate and may select a later rpath candidate or fail the required load; parse the platform load commands and include platform compatibility in candidate evaluation. Apple's Mach-O validation documents the additional check.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
| : compatibleSlice(facts.slices, context.architecture) === undefined | ||
| ? "architecture-missing" | ||
| : "resolved"; |
There was a problem hiding this comment.
Reject non-loadable Mach-O file types as candidates
When a dependency path contains a matching-architecture MH_OBJECT, MH_DYLIB_STUB, or another non-loadable Mach-O type, its slice is represented as file_type: "other", but this branch still returns resolved. Dyld permits only its loadable file types and rejects these inputs, so the trace can suppress a required-load failure or stop before a later usable rpath candidate; make file-type loadability part of this decision. Apple's validMachOForArchAndPlatform performs this validation.
AGENTS.md reference: AGENTS.md:L54-L54
Useful? React with 👍 / 👎.
| "malformed", | ||
| `FAT architecture ${index} extends beyond the file`, | ||
| ); | ||
| slices.push(await readSlice(readAt, offset, length)); |
There was a problem hiding this comment.
Validate FAT CPU records against embedded slice headers
For a FAT entry whose table advertises one CPU type or subtype but whose embedded Mach-O header declares another, this line trusts the embedded header and exposes that architecture as loadable. Dyld instead rejects a FAT slice when its embedded CPU metadata does not match the table, so the trace can resolve an edge to an image dyld will refuse; retain each table record and compare it with the decoded slice before returning parsed facts. Apple's FatFile::isValidSlice performs these equality checks.
AGENTS.md reference: AGENTS.md:L54-L54
Useful? React with 👍 / 👎.
| edge_index: index, | ||
| image: edge.loader, | ||
| basis: "derived", | ||
| explanation: `dyld searches ${earlier.join(", ")} before ${edge.resolution.image ?? edge.install_name}. A Mach-O placed at an earlier path would load first unless code-signing library validation rejects it; library validation is not evaluated here (see inspect_signature).`, |
There was a problem hiding this comment.
Qualify rpath findings below conditional loaders
When edge.loader_conditional is true, an unknown earlier candidate may win before this loader is ever loaded, but this finding still states unconditionally that placing a Mach-O at the absent rpath would load it first. This leaves the derived finding claiming an effect in executions where the loader and its dependency search never occur; qualify the explanation as applying only if the conditional loader loads, as the unresolved-load findings already do.
AGENTS.md reference: AGENTS.md:L9-L9
Useful? React with 👍 / 👎.
# Conflicts: # docs/product-catalog.json # docs/verification/managed-conformance-manifest.json # skills/reverse-engineer-anything/SKILL.md # src/generatedMcpToolCatalog.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d889dc934
ℹ️ 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".
| readonly identity: FileIdentity; | ||
| }> => { | ||
| cancelled(signal); | ||
| const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW); |
There was a problem hiding this comment.
Anchor file opens beneath the validated root
If an analyzed bundle is modified concurrently, an ancestor directory can be replaced with a symlink after resolveTreePath() validates its components but before this open. O_NOFOLLOW protects only the final component, so readImage() can parse an outside-root file; the later hash follows the same path and accepts that file's identity, while the result still reports an in-root path. Use descriptor-relative/anchored traversal or revalidate the resolved path and ancestors when opening.
AGENTS.md reference: AGENTS.md:L16-L16
Useful? React with 👍 / 👎.
| const length = wide | ||
| ? safeNumber(view.getBigUint64(base + 16, littleEndian)) | ||
| : view.getUint32(base + 12, littleEndian); | ||
| if (offset + length > size) |
There was a problem hiding this comment.
Reject misaligned FAT slices before resolving them
When a FAT entry points to an otherwise parseable Mach-O at a non-page-aligned offset, this is the only structural check performed before the slice is accepted. Dyld's FatFile::isValidSlice rejects slices whose offsets are not aligned to the page size required by the embedded image, so such a dependency can be reported as resolved even though dyld refuses it and may continue to another rpath candidate or fail the load. Validate the FAT entry's alignment before decoding the slice.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
| if (cpuType === (CPU_TYPE_X86 | CPU_ARCH_ABI64)) | ||
| return subtype === CPU_SUBTYPE_X86_64_H ? "x86_64h" : "x86_64"; | ||
| if (cpuType === CPU_TYPE_X86) return "i386"; | ||
| if (cpuType === CPU_TYPE_ARM) return "arm"; |
There was a problem hiding this comment.
Preserve ARM CPU subtypes during slice matching
For a universal legacy image containing distinct ARM slices such as armv7 and armv7s, this maps every slice to the same "arm" identity. traceDylibLoading() therefore emits indistinguishable process roots, and compatibleSlice() selects the first "arm" dependency slice even while tracing a different root subtype, potentially using the wrong load commands and reporting incompatible candidates as resolved. Retain subtype identity and apply dyld's subtype grading instead of collapsing all 32-bit ARM slices.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6fc77206e4
ℹ️ 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".
| const name = DEPENDENCY_COMMANDS.get(command); | ||
| if (name !== undefined) | ||
| slice.dependencies.push(decodeDependency(name, body, index)); |
There was a problem hiding this comment.
Reject unknown required load commands
When a slice contains an unrecognized command with LC_REQ_DYLD set, such as 0x8000ffff, this fallthrough silently accepts the slice as parsed. Apple specifies that dyld refuses an image when it does not understand a command carrying this bit (loader.h), so a dependency containing one can be reported as resolved and suppress a required-load failure even though dyld cannot load it; whitelist known ignorable commands and classify any other required command as unsupported.
AGENTS.md reference: AGENTS.md:L54-L56
Useful? React with 👍 / 👎.
| facts?.status === "parsed" | ||
| ? (facts.slices.find((slice) => slice.architecture === architecture) | ||
| ?.dyld_environment ?? []) |
There was a problem hiding this comment.
Skip environment findings for non-executable roots
When the caller explicitly selects an MH_DYLIB or bundle as a root, this reads its LC_DYLD_ENVIRONMENT entries and claims that the image sets process environment variables. Dyld applies these entries from process.mainExecutableHdr, not arbitrary library roots (DyldProcessConfig.cpp), so this produces a false process-effect finding for the supported library-root workflow; gate the finding on file_type === "execute".
AGENTS.md reference: AGENTS.md:L9-L9
Useful? React with 👍 / 👎.
Resolve conflicts against main: - README.md: take main's simplified English README, which no longer has the tool-family table. - README_ja.md: take main's reworded table and count trace_dylib_resolution in the artifact graph row (5 -> 6). - Skill: the references gain the trace_dylib_resolution paragraph, so the version moves to 29 (main already uses 28). - Regenerate the product catalog, conformance manifest, skill digest and package metadata (135 tools). The MCP tool catalog is now built rather than committed (#997), so it is removed here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring in #927's merge of main and resolve conflicts: - README.md: main's simplified English README has no tool-family table. - README_ja/ar/ko/zh: keep main's reworded tables and count inspect_dyld_shared_cache in application workflows (13 -> 14). - Skill: #927 now uses version 29, so this branch moves to 30. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (136 tools). The MCP tool catalog is now built rather than committed (#997), so it is removed here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now carries #964 (skill version 29, macOS native row 7 -> 8): - README_ja/ar/ko/zh: take main's tables and count trace_dylib_resolution in the artifact graph row (5 -> 6). - Skill: move to version 30. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (136 tools). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring in #927's merge of main (#964 at skill version 29): - README_ja/ar/ko/zh: keep the merged tables and count inspect_dyld_shared_cache in application workflows (13 -> 14). - Skill: #927 now uses version 30, so this branch moves to 31. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (137 tools). Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now carries #1037 (skill version 30, reworded native binary row): - README_ja/ar/ko/zh: take main's tables and count trace_dylib_resolution in the artifact graph row (5 -> 6). - Skill: move to version 31. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (137 tools). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring in #927's merge of main (#1037 at skill version 30): - README_ja/ar/ko/zh: keep the merged tables and count inspect_dyld_shared_cache in application workflows (13 -> 14). - Skill: #927 now uses version 31, so this branch moves to 32. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (138 tools). Co-Authored-By: Claude Opus 5.5 <[email protected]>
feat(artifacts): trace Mach-O dylib resolution in bundles
Bring in morluto#927's merge of main and resolve conflicts: - README.md: main's simplified English README has no tool-family table. - README_ja/ar/ko/zh: keep main's reworded tables and count inspect_dyld_shared_cache in application workflows (13 -> 14). - Skill: morluto#927 now uses version 29, so this branch moves to 30. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (136 tools). The MCP tool catalog is now built rather than committed (morluto#997), so it is removed here.
Bring in morluto#927's merge of main (morluto#964 at skill version 29): - README_ja/ar/ko/zh: keep the merged tables and count inspect_dyld_shared_cache in application workflows (13 -> 14). - Skill: morluto#927 now uses version 30, so this branch moves to 31. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (137 tools).
Bring in morluto#927's merge of main (morluto#1037 at skill version 30): - README_ja/ar/ko/zh: keep the merged tables and count inspect_dyld_shared_cache in application workflows (13 -> 14). - Skill: morluto#927 now uses version 31, so this branch moves to 32. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (138 tools).
Builds on #922, which itself builds on #921; this branch contains both. Once they merge, the diff here shrinks to the last commit.
Summary
REA could list a Mach-O's raw dependencies through
inspect_macho, but nothing resolved@rpath,@loader_pathor@executable_path. So it could not answer which file each dylib load actually reaches, or which loads are missing, weak, or depend on search order.The new
trace_dylib_resolution(CLItrace-dylib-resolution) answers that for the active Mach-O, or for every executable in the active.app: the main app, XPC services, extensions, login items, privileged helpers and helper tools. Each executable is a separate process root with its own@executable_path.Change and scope
New tool. It lives in the artifact family because it is a distinct relationship question with no existing contract. It is execution-free and needs no subprocess or Apple tool, so it also runs off macOS.
Parser (
src/artifacts/MachoLoadCommandReader.ts). Pure TypeScript with bounded reads of the FAT header, the Mach-O header andsizeofcmds.LC_LOAD/WEAK/REEXPORT/LAZY/UPWARD_DYLIB. This includes the newerdylib_use_commandencoding frommach-o/loader.h, with its weak, re-export, upward and delayed-init flags, which the currentldemits for-delay_library.LC_ID_DYLIB,LC_RPATH,LC_DYLD_ENVIRONMENTand code-signature presence.Resolution (
src/domain/dylibResolution.ts,src/domain/dyldPaths.ts). Pure logic over a lazily probed tree view.@executable_pathcomes from the process root.@loader_pathcomes from the loading image, or from the owner of theLC_RPATHentry being expanded.@rpathsearches the loading image's rpaths first, then up the load chain.Versions/Currentare followed inside the analyzed root, and..or absolute escapes stop.~/Downloadsstays cheap.Result. Each edge lists every candidate path with an outcome (
resolved,absent,not-mach-o,malformed,architecture-missing,outside-target,escapes-target,undetermined) and a resolution:resolvedconditional/usr/lib/swiftprecedes it.unresolvedundeterminedAbsolute and shared-cache system paths are never checked against the host.
Derived findings:
required-load-unresolvedandweak-load-unresolved.earlier-rpath-candidate-absent: library validation is reported as unknown and points toinspect_signature.dyld-environment-present.Not included: library-validation and hardened-runtime evaluation (planned with the
inspect_signatureCodeDirectory work), dyld shared-cache contents, and DMG/ZIP containers as trace targets. Those are inventoried by #922.Contract and boundary impact
roots?(normalized root-relative paths, as a JSON-Schemapattern) andarchitecture?(arm64,arm64eorx86_64).--root(repeatable) and--architecture.evidence, with no process launch.integrity. A non-Mach-O target fails withunavailable. A non-normalized or non-Mach-O root fails withpathorformat.Sanitized MCP result for the lane fixture (trimmed):
{ "roots": [{ "image": "Contents/MacOS/MacFixture", "architecture": "arm64" }, "…6 more"], "edges": [ { "root": "Contents/MacOS/MacFixture", "loader": "Contents/MacOS/MacFixture", "command": "LC_LOAD_DYLIB", "encoding": "dylib_command", "install_name": "@rpath/Core.framework/Versions/A/Core", "candidates": [ { "source": "rpath", "rpath": "@executable_path/../Overrides", "path": "Contents/MacOS/../Overrides/Core.framework/Versions/A/Core", "outcome": "absent" }, { "source": "rpath", "rpath": "@executable_path/../Frameworks", "path": "Contents/MacOS/../Frameworks/Core.framework/Versions/A/Core", "outcome": "resolved", "resolved_path": "Contents/Frameworks/Core.framework/Versions/A/Core" } ], "resolution": { "status": "resolved", "image": "Contents/Frameworks/Core.framework/Versions/A/Core" } }, { "install_name": "@rpath/libdelay.dylib", "encoding": "dylib_use_command", "delayed_init": true, "resolution": { "status": "resolved", "image": "Contents/Frameworks/libdelay.dylib" } }, { "root": "Contents/XPCServices/Svc.xpc/Contents/MacOS/Svc", "install_name": "@rpath/Core.framework/Versions/A/Core", "candidates": [{ "path": "/opt/rea-fixture-absent/lib/Core.framework/Versions/A/Core", "outcome": "outside-target" }, "…"], "resolution": { "status": "conditional", "image": "Contents/Frameworks/Core.framework/Versions/A/Core" } }, { "install_name": "/usr/lib/libSystem.B.dylib", "resolution": { "status": "undetermined", "image": null } } ], "findings": [ { "kind": "earlier-rpath-candidate-absent", "basis": "derived", "edge_index": 0 }, { "kind": "weak-load-unresolved", "basis": "derived" } ], "coverage": { "status": "complete", "unparsed_images": [], "roots_without_architecture": [] } }Evidence and regression coverage
Unit tests
src/artifacts/MachoLoadCommandReader.test.ts(8 cases):dylib_use_commandflags;cmdsizeandncmds;src/domain/dylibResolution.test.ts(10 cases):@loader_pathin an rpath relative to its owner;@executable_pathper root,Versions/Current, and escaping links;outside-targetversusconditional, and leaf names;not-mach-o,malformedandarchitecture-missingcandidates;Boundary tests
tests/boundary/cli/dylibResolutionCli.test.ts):--root/--architecture, and rejection of../and non-Mach-O roots;tests/boundary/mcp/dylibResolutionMcp.test.ts):open_binarythen the trace, an escaping root, a changed target (integrity), and a non-Mach-O target.Real lane
verify:macos-bundle, extended and run in the macOS CI job:Overridesrpath, an absolute rpath in the XPC service, and a delay-init library.otool -l.DYLD_PRINT_LIBRARIES, which confirms the loader-first rpath rule.Parser conformance outside the lane. Against
otool -lthere were 0 mismatches across 1,654 slices in 853 images. The images came from Brave, OneDrive, Raycast, Discord, Telegram,/usr/bin(arm64e), Calculator, TextEdit, and the universal Command Line Tools binaries.Real apps
earlier-rpath-candidate-absent: Electron Framework searches its own absentLibraries/before the helper's rpathFrameworks//usr/lib/swiftprecedes bundled frameworks, givingconditionalRemaining proof gaps
Validation performed
npm run check:changed: 291 files passed.npm run test:focused -- tests/boundary/cli/dylibResolutionCli.test.ts tests/boundary/mcp/dylibResolutionMcp.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,npx oxfmt --check .,npm run lint: no new errors.npm run verify:macos-bundle:{"ok":true,…,"dylib_resolution":{"roots":7,"edges":22,"otool_slices":11,"dyld_runtime_roots":2}}.Compatibility, safety, and release
O_NOFOLLOW, symlinks are resolved without leaving the analyzed root, and the lane only runs its own fixture binaries.🤖 Generated with Claude Code