Merge remote-tracking branch 'origin/main' into feat/dylib-resolution

# Conflicts:
#	docs/product-catalog.json
#	docs/verification/managed-conformance-manifest.json
#	skills/reverse-engineer-anything/SKILL.md
#	src/generatedMcpToolCatalog.ts
This commit is contained in:
Kaoru0822
2026-10-07 11:04:20 +00:00
10 changed files with 723 additions and 165 deletions
+117 -1
View File
@@ -1,5 +1,5 @@
import { execFile } from "node:child_process";
import { mkdir, realpath, symlink, writeFile } from "node:fs/promises";
import { chmod, mkdir, realpath, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { promisify } from "node:util";
@@ -293,6 +293,122 @@ describe("app executable filename fidelity", () => {
);
});
describe("iOS-style app bundle targets", () => {
const plist = (name: string) =>
`<plist><dict><key>CFBundleExecutable</key><string>${name}</string></dict></plist>`;
it("resolves a flat bundle's program file beside its Info.plist", async () => {
const directory = await createTestTempDirectory("rea-target-");
const app = join(directory, "Flat.app");
await mkdir(app);
await writeFile(join(app, "Info.plist"), plist("Flat"));
await writeFile(join(app, "Flat"), thinMach(0xfeedfacf, 0x0100000c));
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok && result.value).toMatchObject({
path: await realpath(join(app, "Flat")),
bundleInfoPlist: join(await realpath(app), "Info.plist"),
format: "mach-o",
});
});
it.skipIf(process.platform === "win32")(
"keeps the declaring Info.plist for a symlinked program file",
async () => {
const directory = await createTestTempDirectory("rea-target-");
const app = join(directory, "Linked.app");
await mkdir(join(app, "bin"), { recursive: true });
await writeFile(join(app, "Info.plist"), plist("Linked"));
await writeFile(
join(app, "bin", "real"),
thinMach(0xfeedfacf, 0x0100000c),
);
await symlink("bin/real", join(app, "Linked"));
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok && result.value).toMatchObject({
path: await realpath(join(app, "bin", "real")),
bundleInfoPlist: join(await realpath(app), "Info.plist"),
});
},
);
it.skipIf(process.platform === "win32")(
"follows a readable Contents/Info.plist symlink",
async () => {
const directory = await createTestTempDirectory("rea-target-");
const app = join(directory, "Linked.app");
const contents = join(app, "Contents");
await mkdir(join(contents, "MacOS"), { recursive: true });
await writeFile(join(contents, "Real.plist"), plist("Linked"));
await symlink("Real.plist", join(contents, "Info.plist"));
await writeFile(
join(contents, "MacOS", "Linked"),
thinMach(0xfeedfacf, 0x0100000c),
);
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok && result.value).toMatchObject({
path: await realpath(join(contents, "MacOS", "Linked")),
});
},
);
it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
"reports a wrapper it cannot read as a permission denial",
async () => {
const directory = await createTestTempDirectory("rea-target-");
const app = join(directory, "Locked.app");
const wrapper = join(app, "Wrapper");
await mkdir(join(wrapper, "Locked.app"), { recursive: true });
await chmod(wrapper, 0o000);
try {
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected a permission denial");
expect(result.error.message).toContain("permission denied");
} finally {
await chmod(wrapper, 0o755);
}
},
);
it.skipIf(process.platform === "win32")(
"resolves an iOS-on-Mac wrapper through its single Wrapper bundle",
async () => {
const directory = await createTestTempDirectory("rea-target-");
const app = join(directory, "Phone.app");
const wrapped = join(app, "Wrapper", "Phone.app");
await mkdir(wrapped, { recursive: true });
await writeFile(join(wrapped, "Info.plist"), plist("Phone"));
await writeFile(join(wrapped, "Phone"), thinMach(0xfeedfacf, 0x0100000c));
await symlink("Wrapper/Phone.app", join(app, "WrappedBundle"));
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok && result.value).toMatchObject({
path: await realpath(join(wrapped, "Phone")),
format: "mach-o",
});
await mkdir(join(app, "Wrapper", "Second.app"));
expect((await parseBinaryTarget(app, directory, "arm64")).ok).toBe(false);
},
);
it.skipIf(process.platform === "win32")(
"rejects a flat bundle program symlink that leaves the bundle",
async () => {
const directory = await createTestTempDirectory("rea-target-");
const app = join(directory, "Escaping.app");
const outside = join(directory, "outside");
await mkdir(app);
await writeFile(outside, thinMach(0xfeedfacf, 0x0100000c));
await writeFile(join(app, "Info.plist"), plist("Escaping"));
await symlink(outside, join(app, "Escaping"));
const result = await parseBinaryTarget(app, directory, "arm64");
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected an escaping program file");
expect(result.error.message).toContain("leaves the bundle root");
},
);
});
describe("DOS binary target I/O", () => {
it("validates a complete DOS file beyond the initial metadata probe", async () => {
const directory = await createTestTempDirectory("rea-dos-target-");
@@ -164,6 +164,50 @@ describe("compiled Interface Builder bundle reader", () => {
});
});
describe("flat Interface Builder plist values", () => {
it("decodes flat nib archives that hold data and date values", async () => {
const root = await createTestTempDirectory("rea-ib-test-");
const bundle = join(root, "Example.app");
const resources = join(bundle, "Contents", "Resources", "English.lproj");
await mkdir(resources, { recursive: true });
await writeFile(
join(resources, "Binary.nib"),
buildBinary({
$archiver: "NSKeyedArchiver",
$version: 100000,
$objects: [
"$null",
{ $class: { UID: 2 }, title: "Build", NSColor: { UID: 3 } },
{ $classname: "NSButton", $classes: ["NSButton", "NSObject"] },
{ $class: { UID: 4 }, NSWhite: Buffer.from("0.5\0", "ascii") },
{ $classname: "NSColor", $classes: ["NSColor", "NSObject"] },
],
$top: { root: { UID: 1 } },
}),
);
await writeFile(
join(resources, "Xml.nib"),
'<?xml version="1.0"?><plist version="1.0"><dict><key>$archiver</key><string>NSKeyedArchiver</string><key>$objects</key><array><string>$null</string><dict><key>NSWhite</key><data>MC41AA==</data><key>NSDate</key><date>2026-10-07T00:00:00Z</date></dict></array><key>$top</key><dict/></dict></plist>',
);
const analysis = await analyzeInterfaceBuilderBundle({
bundlePath: bundle,
targetSha256: "d".repeat(64),
});
expect(
analysis.documents.map(({ relative_path }) => relative_path).sort(),
).toEqual([
"Contents/Resources/English.lproj/Binary.nib",
"Contents/Resources/English.lproj/Xml.nib",
]);
expect(analysis.graph.coverage).toContainEqual(
expect.objectContaining({ facet: "archive_decode", status: "complete" }),
);
expect(analysis.graph.nodes.map(({ name }) => name)).toContain("Build");
});
});
describe("bounded Interface Builder archive decoding", () => {
it("counts malformed archives against the document limit", async () => {
const root = await createTestTempDirectory("rea-ib-test-");
@@ -296,3 +340,92 @@ describe("bounded Interface Builder archive decoding", () => {
},
);
});
describe("compiled UIKit NIB connections", () => {
it("projects UIKit runtime outlet and event connections", async () => {
const root = await createTestTempDirectory("rea-ib-test-");
const bundle = join(root, "Example.app");
await mkdir(bundle, { recursive: true });
await writeFile(
join(bundle, "Cell.nib"),
encodeNibArchiveFixture({
classes: [
"UIProxyObject",
"UIClassSwapper",
"UIButton",
"UIRuntimeEventConnection",
"UIRuntimeOutletConnection",
"NSString",
],
objects: [
{ classIndex: 0, values: { UIProxiedObjectIdentifier: { ref: 5 } } },
{ classIndex: 1, values: { UIClassName: { ref: 6 } } },
{ classIndex: 2, values: {} },
{
classIndex: 3,
values: {
UISource: { ref: 2 },
UIDestination: { ref: 1 },
UILabel: { ref: 7 },
UIEventMask: 64,
},
},
{
classIndex: 4,
values: {
UISource: { ref: 1 },
UIDestination: { ref: 2 },
UILabel: { ref: 8 },
},
},
{ classIndex: 5, values: { "NS.bytes": "IBFilesOwner" } },
{ classIndex: 5, values: { "NS.bytes": "BuildCell" } },
{ classIndex: 5, values: { "NS.bytes": "buildTapped:" } },
{ classIndex: 5, values: { "NS.bytes": "buildButton" } },
],
}),
);
const analysis = await analyzeInterfaceBuilderBundle({
bundlePath: bundle,
targetSha256: "e".repeat(64),
});
const byId = new Map(analysis.graph.nodes.map((node) => [node.id, node]));
const named = (id: string | null) =>
id === null ? null : (byId.get(id)?.name ?? null);
const action = analysis.graph.nodes.find(({ kind }) => kind === "action");
expect(action).toMatchObject({
name: "buildTapped:",
attributes: { ui_event_mask: 64 },
});
const actionEdges = analysis.graph.edges.filter(
({ relation }) => relation === "target_action",
);
expect(
actionEdges
.filter(({ to }) => to === action?.id)
.map(({ from }) => named(from)),
).toEqual(["UIButton"]);
expect(
actionEdges
.filter(({ from }) => from === action?.id)
.map(({ to }) => named(to)),
).toEqual(expect.arrayContaining(["BuildCell"]));
const outlet = analysis.graph.nodes.find(({ kind }) => kind === "outlet");
expect(outlet?.name).toBe("buildButton");
expect(
analysis.graph.edges
.filter(
({ relation, from }) =>
relation === "outlet_to" && from === outlet?.id,
)
.map(({ to }) => named(to)),
).toEqual(["UIButton"]);
expect(
analysis.graph.nodes.find(({ name }) => name === "IBFilesOwner")?.kind,
).toBe("placeholder");
expect(analysis.graph.nodes.map(({ name }) => name)).not.toContain(
"UIRuntimeEventConnection",
);
});
});
@@ -278,6 +278,29 @@ describe("native macOS provider inspection", () => {
});
});
describe("native plist defaults for iOS-style bundles", () => {
it("defaults to the Info.plist the bundle program was resolved from", async () => {
directory = await createTestTempDirectory("rea-native-flat-");
const app = join(directory, "Flat.app");
const executable = join(app, "Flat");
await mkdir(app, { recursive: true });
await writeFile(executable, "fixture");
await writeFile(join(app, "Info.plist"), "fixture");
const client = new NativeMacOSProvider(
new FixtureRunner(),
"darwin",
).createClient({
...machoTarget(executable, app),
bundleInfoPlist: join(app, "Info.plist"),
});
const plist = await client.execute("inspect_plist", {});
expect(plist.ok && plist.value.result).toMatchObject({
source_path: join(app, "Info.plist"),
});
});
});
/** Emit entitlements whose dictionary also holds a legal `__proto__` key. */
class PrototypeEntitlementsRunner extends FixtureRunner {
override async run(tool: string, arguments_: readonly string[]) {