Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(apple): scan keyed archive root values in context
morluto5a590e61b1f2
diff --git a/src/domain/apple/keyedArchive.test.ts b/src/domain/apple/keyedArchive.test.tsindex 375729afe..30881efbf 100644--- a/src/domain/apple/keyedArchive.test.ts+++ b/src/domain/apple/keyedArchive.test.ts@@ -25,3 +25,71 @@ describe("projectKeyedArchive input bound", () => {expect(error).not.toBeInstanceOf(RangeError);});});++describe("projectKeyedArchive root reference projection", () => {+ it.each(["UID", "CF$UID"])(+ "preserves a sole scalar root named %s as a scalar with or without selection",+ (rootName) => {+ const archive = {+ $archiver: "NSKeyedArchiver",+ $objects: ["$null"],+ $top: { [rootName]: 1 },+ };++ for (const selection of [+ { offset: 0, limit: 1 },+ { root: rootName, offset: 0, limit: 1 },+ ]) {+ const result = projectKeyedArchive(archive, selection);+ expect(result.roots).toEqual({ [rootName]: 1 });+ expect(result.references).toEqual([]);+ expect(result.total_references).toBe(0);+ }+ },+ );++ it("retains real UID references under UID-shaped root names and paths", () => {+ const result = projectKeyedArchive(+ {+ $archiver: "NSKeyedArchiver",+ $objects: ["$null", "target"],+ $top: {+ UID: { CF$UID: 1 },+ CF$UID: { UID: 1 },+ },+ },+ { offset: 0, limit: 2 },+ );++ expect(result.references).toEqual([+ {+ source: null,+ path: ["CF$UID"],+ target: 1,+ raw: { UID: 1 },+ status: "resolved",+ },+ {+ source: null,+ path: ["UID"],+ target: 1,+ raw: { CF$UID: 1 },+ status: "resolved",+ },+ ]);+ });++ it("enforces one traversal budget across root values", () => {+ const values = Array.from({ length: 150_000 }, () => 0);+ expect(() =>+ projectKeyedArchive(+ {+ $archiver: "NSKeyedArchiver",+ $objects: ["$null"],+ $top: { first: values, second: values },+ },+ { offset: 0, limit: 1 },+ ),+ ).toThrow(RangeError);+ });+});diff --git a/src/domain/apple/keyedArchive.ts b/src/domain/apple/keyedArchive.tsindex d2d40951a..a4b335956 100644--- a/src/domain/apple/keyedArchive.ts+++ b/src/domain/apple/keyedArchive.ts@@ -128,10 +128,10 @@ export const projectKeyedArchive = (? top: { [selection.root]: top[selection.root] ?? null };const references: z.infer<typeof linkSchema>[] = [];- const scan = (source: number | null, initial: JsonValue) => {- const pending: { value: JsonValue; path: (string | number)[] }[] = [- { value: initial, path: [] },- ];+ type Pending = { value: JsonValue; path: (string | number)[] };+ // `initial` is popped from the end, so callers list it in reverse order.+ const scan = (source: number | null, initial: Pending[]) => {+ const pending = initial;let visited = 0;while (pending.length > 0) {const item = pending.pop();@@ -177,9 +177,22 @@ export const projectKeyedArchive = (throw new RangeError("Archive exceeds 200000 reference edges");}};- scan(null, roots);+ // Root names belong to the `$top` map, not to the encoded value. Scanning+ // that wrapper makes a sole scalar root named `UID` look like a UID marker.+ // Seed one scan with each value under its key to preserve paths and share+ // the existing aggregate visit budget across every root.+ scan(+ null,+ Object.keys(roots)+ .sort()+ .reverse()+ .flatMap((key) => {+ const value = roots[key];+ return value === undefined ? [] : [{ value, path: [key] }];+ }),+ );const objects = table.map((value, id) => {- scan(id, value);+ scan(id, [{ value, path: [] }]);const fields = record(value);const classUid = uid(fields?.$class);const classId =diff --git a/tests/boundary/filesystem/keyedArchiveSelection.test.ts b/tests/boundary/filesystem/keyedArchiveSelection.test.tsindex 68f24d5b3..710f04e9e 100644--- a/tests/boundary/filesystem/keyedArchiveSelection.test.ts+++ b/tests/boundary/filesystem/keyedArchiveSelection.test.ts@@ -159,6 +159,32 @@ it("reports an absent named root with the archive's available roots", async () =});});+it.each(["UID", "CF$UID"])(+ "keeps a sole scalar %s root free of false references through the file reader",+ async (rootName) => {+ const root = await bundle();+ await writeFile(+ join(root, "Contents", "Resources", "Scalar.plist"),+ Buffer.from(+ build({+ $archiver: "NSKeyedArchiver",+ $version: 100000,+ $objects: ["$null"],+ $top: { [rootName]: 1 },+ }),+ ),+ );++ const result = await inspect(root, {+ path: "Contents/Resources/Scalar.plist",+ });++ expect(result.roots).toEqual({ [rootName]: 1 });+ expect(result.references).toEqual([]);+ expect(result.total_references).toBe(0);+ },+);+it.each([["plain plist",