feat(apple): inspect dyld shared caches and resolve system paths

macOS 11 and later ship system libraries only inside the dyld shared
cache. trace_dylib_resolution therefore left every /usr/lib and /System
load undetermined, and REA had no way to see what a cache contains.

inspect_dyld_shared_cache (CLI inspect-dyld-shared-cache) reads a cache
file set selected by path, without an open target. Its pure TypeScript
reader parses modern and legacy dyld_cache_header layouts and reports:
- UUID, architecture, platform, OS version, Mac Catalyst alternate,
  cache type, shared region, max slide;
- every VM mapping;
- each subcache by file suffix, checked by UUID. A missing or
  mismatched subcache makes coverage partial;
- the complete image list.
For each requested install path it reads that image's load commands
through the cache mappings with the existing Mach-O reader.

trace_dylib_resolution accepts an optional shared_cache. Absolute
candidates found in a cache that serves the process's CPU family resolve
with the new outcome and status `shared-cache`. That status also takes
precedence over later in-bundle fallbacks such as a back-deployed
libswiftCore. The result names the cache UUID and OS version it used.

verify:dyld-shared-cache checks every image in the host cache (3,649 on
macOS 26.6), with dependencies and their re-export, weak, upward and
delay-init attributes, against `dyld_info -all_dyld_cache
-linked_dylibs`. It also checks CLI/MCP parity, and that each
shared-cache edge in the fixture trace is a library dyld actually loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-07 11:43:15 +00:00
co-authored by Claude Opus 5.5
parent a0ec3e2016
commit ade11fa02d
39 changed files with 1911 additions and 176 deletions
+35
View File
@@ -3,6 +3,7 @@ import { Cli, z } from "incur";
import { projectAndroidApplicationEvidence } from "../application/android/AndroidApplicationService.js";
import { projectAppleApplicationEvidence } from "../application/AppleApplicationService.js";
import { inspectDyldSharedCacheEvidence } from "../application/DyldSharedCacheService.js";
import {
compareApplicationVersionsEvidenceValidated,
compareJavaScriptExportShapesEvidenceValidated,
@@ -83,6 +84,7 @@ export const registerApplicationCommands = (
workflow: compareJavaScriptExportShapesEvidenceValidated,
});
registerObligationLedgerCommand(cli, logger);
registerDyldSharedCacheCommand(cli, logger);
registerCoverageCommand(cli, logger);
registerJsonCommand({
cli,
@@ -114,6 +116,39 @@ export const registerApplicationCommands = (
});
};
/** `inspect-dyld-shared-cache <cache> [--image <install path>]...` */
const registerDyldSharedCacheCommand = (
cli: CliInstance,
logger: Logger,
): void => {
cli.command(CLI_COMMANDS.inspectDyldSharedCache, {
description:
"Inspect a dyld shared cache file set and, optionally, cached images",
args: z.object({
cachePath: z.string().describe("Main dyld shared cache file"),
}),
options: z.object({
image: z
.array(z.string())
.optional()
.describe("Install path of a cached image to inspect (repeatable)"),
}),
run: ({ args, options }) =>
logCliCommand(logger, CLI_COMMANDS.inspectDyldSharedCache, async () => {
const result = await inspectDyldSharedCacheEvidence({
cache_path: args.cachePath,
...(options.image === undefined ? {} : { images: options.image }),
});
return result.ok
? jsonValueSchema.parse(result.value)
: {
error: "Application workflow failed",
...projectAnalysisError(result.error),
};
}),
});
};
const registerObligationLedgerCommand = (
cli: CliInstance,
logger: Logger,
+9
View File
@@ -80,6 +80,12 @@ const registerDylibResolutionCommand = (
.enum(["arm64", "arm64e", "x86_64"])
.optional()
.describe("Trace only this slice of each root"),
sharedCache: z
.string()
.optional()
.describe(
"Main dyld shared cache file used to answer system install paths",
),
}),
run: ({ args, options }) =>
logCliCommand(logger, CLI_COMMANDS.traceDylibResolution, () =>
@@ -91,6 +97,9 @@ const registerDylibResolutionCommand = (
...(options.architecture === undefined
? {}
: { architecture: options.architecture }),
...(options.sharedCache === undefined
? {}
: { shared_cache: options.sharedCache }),
},
logger,
),