Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(native): retain Mach-O facts when dyld rejects missing UUID

morluto2b263a7fe9e9
diff --git a/src/native/NativeMacOSProvider.ts b/src/native/NativeMacOSProvider.ts
index c97fb01f9..97e859b06 100644
--- a/src/native/NativeMacOSProvider.ts
+++ b/src/native/NativeMacOSProvider.ts
@@ -917,9 +917,10 @@ class NativeMacOSClient implements AnalysisClient {
return inspectNativeMacho({
target: this.target,
...(signal === undefined ? {} : { signal }),
- run: (tool, arguments_, commandSignal) =>
+ run: (tool, arguments_, commandSignal, acceptNonZeroIf) =>
this.#run("inspect_macho", tool, arguments_, {
signal: commandSignal,
+ ...(acceptNonZeroIf === undefined ? {} : { acceptNonZeroIf }),
}),
invocation: (capture) => invocation(capture, this.target.path),
});
@@ -932,6 +933,9 @@ class NativeMacOSClient implements AnalysisClient {
options: {
readonly signal?: AbortSignal | undefined;
readonly acceptNonZero?: boolean;
+ readonly acceptNonZeroIf?:
+ | ((capture: NativeCommandCapture) => boolean)
+ | undefined;
} = {},
): Promise<Result<NativeCommandCapture, AnalysisError>> {
if (this.#closed)
@@ -944,7 +948,8 @@ class NativeMacOSClient implements AnalysisClient {
);
const command = this.runner.run(tool, arguments_, {
...(options.signal === undefined ? {} : { signal: options.signal }),
- acceptNonZero: options.acceptNonZero ?? false,
+ acceptNonZero:
+ options.acceptNonZero ?? options.acceptNonZeroIf !== undefined,
});
this.#pendingCommands.add(command);
let captured: Awaited<typeof command>;
@@ -953,7 +958,40 @@ class NativeMacOSClient implements AnalysisClient {
} finally {
this.#pendingCommands.delete(command);
}
- if (captured.ok) return captured;
+ if (captured.ok) {
+ const hasFailedExit =
+ captured.value.exitCode !== 0 || captured.value.signal !== null;
+ if (
+ hasFailedExit &&
+ options.acceptNonZeroIf !== undefined &&
+ !options.acceptNonZeroIf(captured.value)
+ )
+ return err(
+ translateCommandFailure(
+ operation,
+ new NativeCommandFailure(
+ tool,
+ captured.value.signal !== null ||
+ (captured.value.exitCode !== null &&
+ captured.value.exitCode !== 0)
+ ? "nonzero-exit"
+ : "io",
+ captured.value.exitCode,
+ undefined,
+ {
+ stdout: captured.value.stdout,
+ stderr: captured.value.stderr,
+ stdoutBytes: captured.value.stdoutBytes,
+ stderrBytes: captured.value.stderrBytes,
+ exitCode: captured.value.exitCode,
+ signal: captured.value.signal,
+ truncated: false,
+ },
+ ),
+ ),
+ );
+ return captured;
+ }
return err(translateCommandFailure(operation, captured.error));
}
}
diff --git a/src/native/NativeMachoCommandDiagnostics.ts b/src/native/NativeMachoCommandDiagnostics.ts
new file mode 100644
index 000000000..666ee78f3
--- /dev/null
+++ b/src/native/NativeMachoCommandDiagnostics.ts
@@ -0,0 +1,67 @@
+import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
+import type { NativeCommandCapture } from "./CommandRunner.js";
+import { withoutEchoedPathHeader } from "./parsers/echoedPath.js";
+
+const MISSING_UUID_DIAGNOSTIC = "missing LC_UUID load command";
+
+/** Recognize only dyld_info's target-specific missing-UUID refusal. */
+export const isMissingUuidDyldFailure = (
+ capture: NativeCommandCapture,
+): boolean =>
+ capture.tool === "dyld_info" &&
+ capture.exitCode !== null &&
+ capture.exitCode !== 0 &&
+ capture.signal === null &&
+ withoutEchoedPathHeader(capture.stdout, capture.arguments.at(-1))
+ .split(/\r?\n/u)
+ .some(
+ (line) =>
+ line.trim().replace(/^(?:dyld_info:\s*)/u, "") ===
+ MISSING_UUID_DIAGNOSTIC,
+ );
+
+/** Keep the exact target diagnostic beside the incomplete collection. */
+export const missingUuidLimitation = (mode: "imports" | "exports"): string =>
+ mode === "imports"
+ ? "dyld_info -imports reported 'missing LC_UUID load command'; import observations are unavailable."
+ : "dyld_info -exports reported 'missing LC_UUID load command'; exports include nm symbol-table observations only.";
+
+/** Preserve unrecognized nonzero command output as an inspection failure. */
+export const unusableNativeCommandOutput = (
+ capture: NativeCommandCapture,
+): AnalysisOutputError =>
+ new AnalysisOutputError(
+ "inspect_macho",
+ `${capture.tool} did not produce a usable inspection result`,
+ {
+ capturedOutput: {
+ stdout: capture.stdout,
+ stderr: capture.stderr,
+ truncated: false,
+ stdout_bytes: capture.stdoutBytes,
+ stderr_bytes: capture.stderrBytes,
+ exit_code: capture.exitCode,
+ signal: capture.signal,
+ },
+ },
+ );
+
+/** Refuse a recognized error when the independently parsed load table contradicts it. */
+export const conflictingUuidCommandEvidence = (
+ command: NativeCommandCapture,
+): AnalysisOutputError =>
+ new AnalysisOutputError(
+ "inspect_macho",
+ "dyld_info reported a missing LC_UUID despite an observed LC_UUID load command",
+ {
+ capturedOutput: {
+ stdout: command.stdout,
+ stderr: command.stderr,
+ truncated: false,
+ stdout_bytes: command.stdoutBytes,
+ stderr_bytes: command.stderrBytes,
+ exit_code: command.exitCode,
+ signal: command.signal,
+ },
+ },
+ );
diff --git a/src/native/NativeMachoInspection.ts b/src/native/NativeMachoInspection.ts
index 60da647dc..1151342d7 100644
--- a/src/native/NativeMachoInspection.ts
+++ b/src/native/NativeMachoInspection.ts
@@ -19,6 +19,12 @@ import { withoutEchoedPathHeader } from "./parsers/echoedPath.js";
import { parseOtoolLoadCommands } from "./parsers/otool.js";
import { reconcileMachoUuid } from "./parsers/machoUuid.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
+import {
+ conflictingUuidCommandEvidence,
+ isMissingUuidDyldFailure,
+ missingUuidLimitation,
+ unusableNativeCommandOutput,
+} from "./NativeMachoCommandDiagnostics.js";
interface NativeMachoObservation {
readonly result: JsonValue;
@@ -33,6 +39,7 @@ interface NativeMachoInspectionContext {
tool: string,
arguments_: readonly string[],
signal?: AbortSignal,
+ acceptNonZeroIf?: (capture: NativeCommandCapture) => boolean,
) => Promise<Result<NativeCommandCapture, AnalysisError>>;
readonly invocation: (
capture: NativeCommandCapture,
@@ -100,6 +107,7 @@ export const inspectNativeMacho = async (
context.target.path,
],
context.signal,
+ tool === "dyld_info" ? isMissingUuidDyldFailure : undefined,
);
// vtool knows no variant subtypes, so no spelling selects an arm64e.x1 slice.
const vtoolSelectsSlice =
@@ -109,11 +117,18 @@ export const inspectNativeMacho = async (
// Every launch settles before return; declared order fixes provenance and
// which failure is reported.
const [required, optional] = await Promise.all([
- Promise.all(REQUIRED_SLICE_COMMANDS.map(runSliceCommand)),
+ Promise.all(
+ REQUIRED_SLICE_COMMANDS.map((command) => runSliceCommand(command)),
+ ),
vtoolSelectsSlice ? runSliceCommand(OPTIONAL_VTOOL_COMMAND) : null,
]);
for (const captured of required) {
if (!captured.ok) return err(captured.error);
+ if (
+ (captured.value.exitCode !== 0 || captured.value.signal !== null) &&
+ !isMissingUuidDyldFailure(captured.value)
+ )
+ return err(unusableNativeCommandOutput(captured.value));
captures.push(captured.value);
}
const limitations: string[] = [];
@@ -132,7 +147,10 @@ export const inspectNativeMacho = async (
// A stripped symbol table (strip -T) can omit names the export trie keeps.
// Only then does llvm-nm's dyld-info pass add names, and its exact names
// disambiguate dyld_info rows, so rerun it rather than lose them.
- if (!namesEveryExport(captures[nmIndex]!.stdout, dyldExports)) {
+ if (
+ !isMissingUuidDyldFailure(dyldExports) &&
+ !namesEveryExport(captures[nmIndex]!.stdout, dyldExports)
+ ) {
const withDyldInfo = await runSliceCommand(DYLD_INFO_EXPORTS);
if (!withDyldInfo.ok) return err(withDyldInfo.error);
captures[nmIndex] = withDyldInfo.value;
@@ -162,6 +180,12 @@ export const inspectNativeMacho = async (
),
);
}
+ const uuidlessDyldFailure = captures.find(isMissingUuidDyldFailure);
+ if (
+ uuidlessDyldFailure !== undefined &&
+ load.commands.some(({ kind }) => kind === "LC_UUID")
+ )
+ return err(conflictingUuidCommandEvidence(uuidlessDyldFailure));
const selectedArchitectureName =
selectedArchitecture ??
(architectures.length === 1 ? (architectures[0]?.name ?? null) : null);
@@ -218,21 +242,26 @@ const normalizeMacho = (
},
) => {
const byTool = captureLookup(captures);
- const imports = parseDyldSymbols(
- sliceOutput(byTool("dyld_info", 0)),
- "imports",
- );
+ const dyldImportsCapture = byTool("dyld_info", 0);
+ const dyldExportsCapture = byTool("dyld_info", 1);
+ const missingImportsUuid = isMissingUuidDyldFailure(dyldImportsCapture);
+ const missingExportsUuid = isMissingUuidDyldFailure(dyldExportsCapture);
+ const imports = missingImportsUuid
+ ? []
+ : parseDyldSymbols(sliceOutput(dyldImportsCapture), "imports");
const imageBase =
load.segments.find(
(segment) => segment.file_offset === 0 && (segment.file_size ?? 0) > 0,
)?.vm_address ?? null;
const nmExports = parseNmExports(byTool("nm").stdout);
- const dyldExports = parseDyldSymbols(
- sliceOutput(byTool("dyld_info", 1)),
- "exports",
- imageBase,
- new Set(nmExports.map(({ name }) => name)),
- );
+ const dyldExports = missingExportsUuid
+ ? []
+ : parseDyldSymbols(
+ sliceOutput(dyldExportsCapture),
+ "exports",
+ imageBase,
+ new Set(nmExports.map(({ name }) => name)),
+ );
const exports = uniqueSymbols([...dyldExports, ...nmExports]);
const dwarfdump = byTool("dwarfdump");
const uuid = reconcileMachoUuid(
@@ -268,6 +297,8 @@ const normalizeMacho = (
]
: []),
...additionalLimitations,
+ ...(missingImportsUuid ? [missingUuidLimitation("imports")] : []),
+ ...(missingExportsUuid ? [missingUuidLimitation("exports")] : []),
...uuid.limitations,
...(threadEntrypoint ? [threadEntrypointLimitation] : []),
...(imageBase === null &&
@@ -296,9 +327,14 @@ const normalizeMacho = (
dependencies: covered(load.dependencies, true),
imports: covered(imports, false, [
"dyld_info textual imports may omit chained or toolchain-unsupported metadata.",
+ ...(missingImportsUuid ? [missingUuidLimitation("imports")] : []),
]),
exports: covered(exports, false, [
- "Merged nm/dyld_info results may be incomplete for stripped binaries.",
+ ...(missingExportsUuid
+ ? [missingUuidLimitation("exports")]
+ : [
+ "Merged nm/dyld_info results may be incomplete for stripped binaries.",
+ ]),
...(dyldExports.some(({ sourceSymbol }) => sourceSymbol !== undefined)
? [
"Renamed re-exports are listed under their exported name; the source library's symbol name is not reported.",
diff --git a/tests/boundary/cli/nativeMachoMissingUuidCli.test.ts b/tests/boundary/cli/nativeMachoMissingUuidCli.test.ts
new file mode 100644
index 000000000..71285073c
--- /dev/null
+++ b/tests/boundary/cli/nativeMachoMissingUuidCli.test.ts
@@ -0,0 +1,106 @@
+import { join } from "node:path";
+import { writeFile } from "node:fs/promises";
+
+import { describe, expect } from "vitest";
+
+import { inspectMachoSchema } from "../../../src/domain/native/nativeInspection.js";
+import { parseEvidence } from "../../../src/domain/evidence.js";
+import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
+import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
+import { cliTest } from "../../support/cli/cliFixture.js";
+
+describe.skipIf(process.platform !== "darwin")(
+ "native Mach-O CLI without LC_UUID",
+ () => {
+ cliTest(
+ "returns readable facts with partial dyld coverage and preserves controls",
+ async ({ cli, processes }) => {
+ const directory = await createTestTempDirectory("rea-macho-no-uuid-");
+ const source = join(directory, "probe.c");
+ const probe = join(directory, "probe");
+ const control = join(directory, "control");
+ const object = join(directory, "probe.o");
+ await writeFile(
+ source,
+ "int exported_add(int a, int b) { return a + b; }\nint main(void) { return exported_add(1, 2); }\n",
+ );
+ for (const arguments_ of [
+ ["clang", "-Wl,-no_uuid", "-o", probe, source],
+ ["clang", "-o", control, source],
+ ["clang", "-c", source, "-o", object],
+ ]) {
+ const compiled = await processes.run("/usr/bin/xcrun", arguments_, {
+ timeoutMs: 30_000,
+ });
+ expect(compiled.exitCode, compiled.stderr).toBe(0);
+ }
+
+ const inspect = async (path: string) => {
+ const result = await cli.run({
+ arguments: ["inspect-macho", path, "--json"],
+ environment: { REA_LOG_LEVEL: "silent" },
+ });
+ expect(result.exitCode, result.stdout + result.stderr).toBe(0);
+ return inspectMachoSchema.parse(
+ (result.json as { normalized_result?: unknown }).normalized_result,
+ );
+ };
+
+ const missingUuid = await inspect(probe);
+ expect(missingUuid).toMatchObject({
+ uuid: null,
+ load_commands: { exhaustive: true },
+ imports: {
+ items: [],
+ total: null,
+ exhaustive: false,
+ limitations: expect.arrayContaining([
+ expect.stringContaining(
+ "dyld_info -imports reported 'missing LC_UUID load command'",
+ ),
+ ]),
+ },
+ exports: {
+ items: expect.arrayContaining([
+ expect.objectContaining({ name: "_exported_add", source: "nm" }),
+ expect.objectContaining({ name: "_main", source: "nm" }),
+ ]),
+ total: null,
+ exhaustive: false,
+ },
+ provenance: expect.arrayContaining([
+ expect.objectContaining({
+ tool: "dyld_info",
+ exit: { code: 1, signal: null },
+ }),
+ ]),
+ });
+ expect(missingUuid.limitations).toContain(
+ "dyld_info -exports reported 'missing LC_UUID load command'; exports include nm symbol-table observations only.",
+ );
+
+ const normalControl = await inspect(control);
+ expect(normalControl.uuid).not.toBeNull();
+ expect(normalControl.load_commands.exhaustive).toBe(true);
+
+ const objectControl = await inspect(object);
+ expect(objectControl.uuid).toBeNull();
+ expect(objectControl.load_commands.exhaustive).toBe(true);
+
+ const { call } = await connectLocalToolsMcp({ HOME: directory });
+ const opened = await call("open_binary", { path: probe });
+ expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
+ const mcp = await call("inspect_macho", { detail: "complete" });
+ expect(mcp.isError, JSON.stringify(mcp)).not.toBe(true);
+ const report = inspectMachoSchema.parse(
+ parseEvidence(mcp.structuredContent).normalized_result,
+ );
+ expect(report.uuid).toBeNull();
+ expect(report.imports).toEqual(missingUuid.imports);
+ expect(report.exports).toEqual(missingUuid.exports);
+ expect(report.load_commands).toEqual(missingUuid.load_commands);
+ expect((await call("close_binary", {})).isError).not.toBe(true);
+ },
+ );
+ },
+);
diff --git a/tests/boundary/providers/native/nativeMachoUuidlessInspection.test.ts b/tests/boundary/providers/native/nativeMachoUuidlessInspection.test.ts
new file mode 100644
index 000000000..fb1b4490a
--- /dev/null
+++ b/tests/boundary/providers/native/nativeMachoUuidlessInspection.test.ts
@@ -0,0 +1,269 @@
+import { expect, it } from "vitest";
+import { writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
+
+import { machoImage } from "../../../../src/artifacts/apple/MachoImage.fixture.js";
+import { createServer } from "../../../../src/server/createServer.js";
+import { NativeMacOSProvider } from "../../../../src/native/NativeMacOSProvider.js";
+import {
+ NativeCommandFailure,
+ type NativeCommandCapture,
+ type NativeCommandOptions,
+ type NativeCommandRunner,
+} from "../../../../src/native/CommandRunner.js";
+import { err, ok } from "../../../../src/domain/result.js";
+import { createTestBinarySession } from "../../../fixtures/binarySession.js";
+import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
+import {
+ NativeFixtureRunner,
+ nativeFixture,
+ nativeMachoTarget,
+ withOtoolMachHeader,
+} from "../../../fixtures/nativeCommands.js";
+
+const missingUuidDiagnostic = "missing LC_UUID load command";
+
+const dyldDiagnosticOutput = (path: string, diagnostic: string): string =>
+ `${path} [arm64]:\n ${diagnostic}\n`;
+
+const otoolOutputWithoutUuid = async () => {
+ const otool = await nativeFixture("otool-load.txt");
+ const commandOutput = otool.slice(otool.indexOf("Load command 0\n"));
+ let commandIndex = 0;
+ const withoutUuidCommands = commandOutput
+ .replace(
+ /Load command 1\n\s*cmd LC_UUID\n\s*cmdsize 24\n\s*uuid [^\n]+\n/u,
+ "",
+ )
+ .replace(/^Load command \d+$/gmu, () => `Load command ${commandIndex++}`);
+ return withOtoolMachHeader(withoutUuidCommands);
+};
+
+class UuidlessDyldRunner implements NativeCommandRunner {
+ readonly fixture: NativeFixtureRunner;
+
+ constructor(
+ otool: string,
+ readonly diagnostic = missingUuidDiagnostic,
+ readonly stderr = "",
+ ) {
+ this.fixture = new NativeFixtureRunner({
+ "otool:-h": otool,
+ dwarfdump: "",
+ });
+ }
+
+ async run(
+ tool: string,
+ arguments_: readonly string[],
+ options: NativeCommandOptions,
+ ) {
+ if (tool !== "dyld_info") return this.fixture.run(tool, arguments_);
+ const capture: NativeCommandCapture = {
+ tool,
+ executable: "/usr/bin/dyld_info",
+ executableSha256: "a".repeat(64),
+ toolVersion: null,
+ versionReason: null,
+ arguments: [...arguments_],
+ stdout: dyldDiagnosticOutput(arguments_.at(-1) ?? "", this.diagnostic),
+ stderr: this.stderr,
+ stdoutBytes: Buffer.byteLength(
+ dyldDiagnosticOutput(arguments_.at(-1) ?? "", this.diagnostic),
+ ),
+ stderrBytes: Buffer.byteLength(this.stderr),
+ exitCode: 1,
+ signal: null,
+ };
+ if (options.acceptNonZero) return ok(capture);
+ return err(
+ new NativeCommandFailure(tool, "nonzero-exit", 1, undefined, {
+ stdout: capture.stdout,
+ stderr: capture.stderr,
+ stdoutBytes: capture.stdoutBytes,
+ stderrBytes: capture.stderrBytes,
+ exitCode: capture.exitCode,
+ signal: capture.signal,
+ truncated: false,
+ }),
+ );
+ }
+}
+
+it("returns readable Mach-O Evidence when dyld_info identifies a missing UUID", async () => {
+ const withoutUuid = await otoolOutputWithoutUuid();
+ const runner = new UuidlessDyldRunner(withoutUuid);
+ const result = await new NativeMacOSProvider({}, runner, "darwin")
+ .createClient(nativeMachoTarget("/fixture/no-uuid"))
+ .execute("inspect_macho", {});
+
+ expect(result.ok, JSON.stringify(result.ok ? null : result.error)).toBe(true);
+ if (!result.ok) return;
+ expect(result.value.result).toMatchObject({
+ uuid: null,
+ load_commands: { exhaustive: true },
+ imports: { items: [], total: null, exhaustive: false },
+ exports: {
+ items: expect.arrayContaining([
+ expect.objectContaining({ name: "_main", source: "nm" }),
+ ]),
+ total: null,
+ exhaustive: false,
+ },
+ provenance: expect.arrayContaining([
+ expect.objectContaining({
+ tool: "dyld_info",
+ exit: { code: 1, signal: null },
+ stdout_bytes: Buffer.byteLength(
+ dyldDiagnosticOutput("/fixture/no-uuid", missingUuidDiagnostic),
+ ),
+ }),
+ ]),
+ });
+ expect(result.value.limitations).toContain(
+ "dyld_info -imports reported 'missing LC_UUID load command'; import observations are unavailable.",
+ );
+ expect(result.value.limitations).toContain(
+ "dyld_info -exports reported 'missing LC_UUID load command'; exports include nm symbol-table observations only.",
+ );
+});
+
+it("keeps other dyld_info nonzero exits as command failures", async () => {
+ const runner = new UuidlessDyldRunner(
+ await nativeFixture("otool-load.txt"),
+ "malformed load command table",
+ );
+ const result = await new NativeMacOSProvider({}, runner, "darwin")
+ .createClient(nativeMachoTarget("/fixture/malformed"))
+ .execute("inspect_macho", {});
+
+ expect(result.ok).toBe(false);
+ if (result.ok) return;
+ expect(result.error).toMatchObject({
+ _tag: "ProviderAdapterError",
+ diagnostics: { tool: "dyld_info", reason: "nonzero-exit", exit_code: 1 },
+ capturedOutput: {
+ stdout: dyldDiagnosticOutput(
+ "/fixture/malformed",
+ "malformed load command table",
+ ),
+ exit_code: 1,
+ truncated: false,
+ },
+ });
+});
+
+it("does not treat a newline in the echoed operand path as dyld_info evidence", async () => {
+ const withoutUuid = await otoolOutputWithoutUuid();
+ const path = "/fixture/\nmissing LC_UUID load command\n";
+ const runner = new UuidlessDyldRunner(
+ withoutUuid,
+ "malformed load command table",
+ );
+ const result = await new NativeMacOSProvider({}, runner, "darwin")
+ .createClient(nativeMachoTarget(path))
+ .execute("inspect_macho", {});
+
+ expect(result.ok).toBe(false);
+ if (result.ok) return;
+ expect(result.error).toMatchObject({
+ _tag: "ProviderAdapterError",
+ diagnostics: { tool: "dyld_info", reason: "nonzero-exit", exit_code: 1 },
+ });
+});
+
+it("does not treat a newline in stderr's echoed operand path as dyld_info evidence", async () => {
+ const withoutUuid = await otoolOutputWithoutUuid();
+ const path = "/fixture/\nmissing LC_UUID load command\n";
+ const runner = new UuidlessDyldRunner(
+ withoutUuid,
+ "malformed load command table",
+ `${path}: file not found`,
+ );
+ const result = await new NativeMacOSProvider({}, runner, "darwin")
+ .createClient(nativeMachoTarget(path))
+ .execute("inspect_macho", {});
+
+ expect(result.ok).toBe(false);
+ if (result.ok) return;
+ expect(result.error).toMatchObject({
+ _tag: "ProviderAdapterError",
+ diagnostics: { tool: "dyld_info", reason: "nonzero-exit", exit_code: 1 },
+ capturedOutput: {
+ stderr: `${path}: file not found`,
+ exit_code: 1,
+ },
+ });
+});
+
+it("does not call a target UUID-less when otool observed LC_UUID", async () => {
+ const runner = new UuidlessDyldRunner(await nativeFixture("otool-load.txt"));
+ const result = await new NativeMacOSProvider({}, runner, "darwin")
+ .createClient(nativeMachoTarget("/fixture/conflicting-uuid"))
+ .execute("inspect_macho", {});
+
+ expect(result).toMatchObject({
+ ok: false,
+ error: {
+ _tag: "AnalysisOutputError",
+ reason:
+ "dyld_info reported a missing LC_UUID despite an observed LC_UUID load command",
+ capturedOutput: {
+ stdout: dyldDiagnosticOutput(
+ "/fixture/conflicting-uuid",
+ missingUuidDiagnostic,
+ ),
+ exit_code: 1,
+ signal: null,
+ },
+ },
+ });
+});
+
+it("delivers partial UUID-less inspection Evidence through production MCP", async () => {
+ const directory = await createTestTempDirectory("rea-macho-no-uuid-mcp-");
+ const path = join(directory, "probe");
+ await writeFile(path, machoImage({}));
+ const withoutUuid = await otoolOutputWithoutUuid();
+ const session = createTestBinarySession(
+ new NativeMacOSProvider({}, new UuidlessDyldRunner(withoutUuid), "darwin"),
+ );
+ const server = createServer({ kind: "session", session });
+ const client = new Client({ name: "macho-uuidless-test", version: "1" });
+ const [clientTransport, serverTransport] =
+ InMemoryTransport.createLinkedPair();
+ try {
+ await server.connect(serverTransport);
+ await client.connect(clientTransport);
+ const opened = await client.callTool({
+ name: "open_binary",
+ arguments: { path },
+ });
+ expect(opened.isError, JSON.stringify(opened.content)).not.toBe(true);
+
+ const inspected = await client.callTool({
+ name: "inspect_macho",
+ arguments: {},
+ });
+ expect(inspected.isError, JSON.stringify(inspected.content)).not.toBe(true);
+ expect(inspected.structuredContent).toMatchObject({
+ normalized_result: {
+ uuid: null,
+ imports: { items: [], total: null, exhaustive: false },
+ exports: {
+ items: expect.arrayContaining([
+ expect.objectContaining({ name: "_main", source: "nm" }),
+ ]),
+ total: null,
+ exhaustive: false,
+ },
+ limitations: expect.arrayContaining([
+ "dyld_info -imports reported 'missing LC_UUID load command'; import observations are unavailable.",
+ ]),
+ },
+ });
+ } finally {
+ await Promise.all([client.close(), server.close(), session.close()]);
+ }
+});