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): report plist dates the decoder cannot represent as unknown (#3793)
Kaoru08227a6647038563
diff --git a/docs/native-investigation.md b/docs/native-investigation.mdindex b9b42dcb8..ecda41a46 100644--- a/docs/native-investigation.md+++ b/docs/native-investigation.md@@ -570,6 +570,12 @@ Exact and ambiguous value counts describe emitted root/object value instances;a root and an object may contain the same value. Archive digests identify theoriginal bytes.+Dates are reported as `{ "$plist_type": "date", "iso8601": "<timestamp>" }`. A+date the decoder cannot represent, such as an XML date with a year beyond 9999+or a negative year, is reported as `{ "$plist_type": "date", "iso8601": null }`+with a counted limitation; the rest of the plist or archive is still decoded.+`inspect_plist` and Interface Builder decoding use the same projection.+## Locate a byte signatureUse `search_bytes` after opening a target with Ghidra to locate a known constantdiff --git a/src/artifacts/apple/InterfaceBuilderAnalysis.ts b/src/artifacts/apple/InterfaceBuilderAnalysis.tsindex 00db7f03c..32760e082 100644--- a/src/artifacts/apple/InterfaceBuilderAnalysis.ts+++ b/src/artifacts/apple/InterfaceBuilderAnalysis.ts@@ -7,7 +7,10 @@ import {isUIKitRuntimeConnectionClass,} from "../../domain/apple/interfaceBuilderKeyedArchive.js";import { DirectoryArtifactReader } from "../DirectoryArtifactReader.js";-import { projectPlistValue } from "../../domain/apple/plistValue.js";+import {+ projectPlistValue,+ unknownDateLimitation,+} from "../../domain/apple/plistValue.js";import {omittedPrototypeKeysLimitation,parseXmlPropertyList,@@ -58,6 +61,7 @@ export const analyzeInterfaceBuilderBundle = async (input: {const incompleteHierarchies = new Map<string, number>();const unresolvedConnections = new Map<string, number>();const prototypeKeyOmissions = new Map<string, number | null>();+ const unknownDates = new Map<string, number>();let omitted = 0;let attempted = 0;let aggregateInputBytes = 0;@@ -131,16 +135,21 @@ export const analyzeInterfaceBuilderBundle = async (input: {binaryPrototypeKeyObserved =decodedReservation.binaryPrototypeKeyObserved;}- const { value: raw, omittedPrototypeKeys } =- nib === null- ? decodePlist(bytes, xmlText, binaryPrototypeKeyObserved)- : { value: nib.raw, omittedPrototypeKeys: 0 };+ const {+ value: raw,+ omittedPrototypeKeys,+ unknownDateCount,+ } = nib === null+ ? decodePlist(bytes, xmlText, binaryPrototypeKeyObserved)+ : { value: nib.raw, omittedPrototypeKeys: 0, unknownDateCount: 0 };if (nib !== null && nib.omitted > 0)incompleteHierarchies.set(entry.path, nib.omitted);if (nib !== null && nib.unresolvedConnections > 0)unresolvedConnections.set(entry.path, nib.unresolvedConnections);if (omittedPrototypeKeys !== 0)prototypeKeyOmissions.set(entry.path, omittedPrototypeKeys);+ if (unknownDateCount !== 0)+ unknownDates.set(entry.path, unknownDateCount);const documentHash = createHash("sha256").update(bytes).digest("hex");documents.push({relativePath: entry.path,@@ -178,6 +187,7 @@ export const analyzeInterfaceBuilderBundle = async (input: {incompleteHierarchies,unresolvedConnections,prototypeKeyOmissions,+ unknownDates,invalid,omittedArchives,unreportedOmittedArchives,@@ -246,6 +256,7 @@ const finalizeHierarchyCoverage = (incompleteHierarchies: ReadonlyMap<string, number>;unresolvedConnections: ReadonlyMap<string, number>;prototypeKeyOmissions: ReadonlyMap<string, number | null>;+ unknownDates: ReadonlyMap<string, number>;invalid: readonly string[];omittedArchives: readonly { path: string; reason: string }[];unreportedOmittedArchives: number;@@ -257,6 +268,7 @@ const finalizeHierarchyCoverage = (incompleteHierarchies,unresolvedConnections,prototypeKeyOmissions,+ unknownDates,invalid,omittedArchives,unreportedOmittedArchives,@@ -342,6 +354,9 @@ const finalizeHierarchyCoverage = (...[...prototypeKeyOmissions].map(([path, count]) => `${path}: ${omittedPrototypeKeysLimitation(count)}`,),+ ...[...unknownDates].map(+ ([path, count]) => `${path}: ${unknownDateLimitation(count)}`,+ ),...omittedArchives.map(({ path, reason }) =>`${path}: omitted because ${reason.replaceAll("_", " ")}.`,@@ -693,6 +708,7 @@ const decodePlist = (): {readonly value: JsonValue;readonly omittedPrototypeKeys: number | null;+ readonly unknownDateCount: number;} => {const binary = hasBinaryPlistSignature(bytes);const { value, omittedPrototypeKeys } = binary@@ -701,5 +717,10 @@ const decodePlist = (omittedPrototypeKeys: binaryPrototypeKeyObserved ? null : 0,}: parseXmlPropertyList(xmlText ?? decodeXmlPlistText(bytes));- return { value: projectPlistValue(value).value, omittedPrototypeKeys };+ const projected = projectPlistValue(value);+ return {+ value: projected.value,+ omittedPrototypeKeys,+ unknownDateCount: projected.unknownDateCount,+ };};diff --git a/src/artifacts/apple/KeyedArchiveReader.ts b/src/artifacts/apple/KeyedArchiveReader.tsindex 7bd64511e..ff1bdf99c 100644--- a/src/artifacts/apple/KeyedArchiveReader.ts+++ b/src/artifacts/apple/KeyedArchiveReader.ts@@ -6,7 +6,10 @@ import {AnalysisInputError,AnalysisUnsupportedTargetError,} from "../../domain/analysisErrorCore.js";-import { projectPlistValue } from "../../domain/apple/plistValue.js";+import {+ projectPlistValue,+ unknownDateLimitation,+} from "../../domain/apple/plistValue.js";import { createPlistNumberProjection } from "../../domain/apple/plistNumbers.js";import {binaryPlistNumberLiterals,@@ -75,9 +78,11 @@ export const decodeKeyedArchiveBytes = (: 0,}: parseXmlPropertyList(xmlText ?? "");- const { value: plistValue, unknownRealCount } = projectPlistValue(- parsed.value,- );+ const {+ value: plistValue,+ unknownRealCount,+ unknownDateCount,+ } = projectPlistValue(parsed.value);const graph = projectKeyedArchive(plistValue, selection);const numbers = createPlistNumberProjection(binary@@ -112,6 +117,9 @@ export const decodeKeyedArchiveBytes = (: [`${String(unknownRealCount)} non-finite real value(s) are reported as { "$plist_type": "real", "value": null } because JSON evidence cannot preserve NaN vs infinity.`,]),+ ...(unknownDateCount === 0+ ? []+ : [unknownDateLimitation(unknownDateCount)]),],};};diff --git a/src/domain/apple/plistValue.test.ts b/src/domain/apple/plistValue.test.tsindex 4a3465a15..65ce87ba9 100644--- a/src/domain/apple/plistValue.test.ts+++ b/src/domain/apple/plistValue.test.ts@@ -2,6 +2,20 @@ import { expect, it } from "vitest";import { projectPlistValue } from "./plistValue.js";+// Binary decoders build dates from seconds; beyond the Date range they are invalid.+it("projects an unrepresentable date as unknown and counts it", () => {+ expect(+ projectPlistValue({ far: new Date(Number.NaN), near: new Date(0) }),+ ).toEqual({+ value: {+ far: { $plist_type: "date", iso8601: null },+ near: { $plist_type: "date", iso8601: "1970-01-01T00:00:00.000Z" },+ },+ unknownRealCount: 0,+ unknownDateCount: 1,+ });+});+it("rejects excessive plist nesting without exhausting the stack", () => {const deep: unknown[] = [];let cursor = deep;diff --git a/src/domain/apple/plistValue.ts b/src/domain/apple/plistValue.tsindex 418688dd7..3ea0c8733 100644--- a/src/domain/apple/plistValue.ts+++ b/src/domain/apple/plistValue.ts@@ -14,8 +14,14 @@ export interface ProjectedPlistValue {readonly value: JsonValue;/** Reals decoded as NaN, which the decoder also uses for ±infinity. */readonly unknownRealCount: number;+ /** Dates the decoder could not represent, reported without a timestamp. */+ readonly unknownDateCount: number;}+/** Limitation for results whose plist held dates the decoder could not represent. */+export const unknownDateLimitation = (count: number): string =>+ `${String(count)} date value(s) are reported as { "$plist_type": "date", "iso8601": null } because the decoder could not represent them, such as XML dates with years beyond 9999 or negative years, or dates outside the JavaScript date range.`;+/*** Project a decoded plist into JSON. Data and dates become explicit* `$plist_type` objects; a non-finite real becomes an explicit unknown@@ -23,6 +29,7 @@ export interface ProjectedPlistValue {*/export const projectPlistValue = (value: unknown): ProjectedPlistValue => {let unknownRealCount = 0;+ let unknownDateCount = 0;const project = (item: unknown, depth: number): JsonValue => {if (depth > MAX_PLIST_DEPTH)throw new RangeError(@@ -33,8 +40,12 @@ export const projectPlistValue = (value: unknown): ProjectedPlistValue => {$plist_type: "data",base64: Buffer.from(item).toString("base64"),};- if (item instanceof Date)- return { $plist_type: "date", iso8601: item.toISOString() };+ if (item instanceof Date) {+ if (!Number.isNaN(item.getTime()))+ return { $plist_type: "date", iso8601: item.toISOString() };+ unknownDateCount += 1;+ return { $plist_type: "date", iso8601: null };+ }if (typeof item === "number" && !Number.isFinite(item)) {unknownRealCount += 1;return { $plist_type: "real", value: null };@@ -51,5 +62,5 @@ export const projectPlistValue = (value: unknown): ProjectedPlistValue => {return z.union([z.string(), z.number(), z.boolean(), z.null()]).parse(item);};const projected = project(value, 0);- return { value: projected, unknownRealCount };+ return { value: projected, unknownRealCount, unknownDateCount };};diff --git a/src/native/parsers/plist.ts b/src/native/parsers/plist.tsindex b27f67b1e..a3b6c4fa5 100644--- a/src/native/parsers/plist.ts+++ b/src/native/parsers/plist.ts@@ -4,6 +4,7 @@ import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";import type { JsonValue } from "../../domain/jsonValue.js";import {projectPlistValue,+ unknownDateLimitation,type ProjectedPlistValue,} from "../../domain/apple/plistValue.js";import {@@ -178,6 +179,9 @@ export const parsePlistXml = (: [`${String(projected.unknownRealCount)} non-finite real value(s) are reported as { "$plist_type": "real", "value": null } because the XML decoder does not distinguish NaN from infinity.`,]),+ ...(projected.unknownDateCount === 0+ ? []+ : [unknownDateLimitation(projected.unknownDateCount)]),...numberLimitations(exactIntegerCount, ambiguousNumberCount),...prototypeKeyLimitations(omittedPrototypeKeys),],diff --git a/tests/boundary/cli/nativePlistCli.test.ts b/tests/boundary/cli/nativePlistCli.test.tsindex 324d4e20c..62ec9ce98 100644--- a/tests/boundary/cli/nativePlistCli.test.ts+++ b/tests/boundary/cli/nativePlistCli.test.ts@@ -96,6 +96,8 @@ describe.skipIf(process.platform !== "darwin")("<key>CFBundleIdentifier</key><string>com.example.types</string>","<key>Blob</key><data>AAEC</data>","<key>Built</key><date>2020-01-01T00:00:00Z</date>",+ // plutil writes years past 9999 unsigned, which the decoder rejects.+ "<key>Far</key><date>11507-08-17T05:20:00Z</date>","<key>Ratio</key><real>nan</real>","<key>Nested</key><array><dict>","<key>Ratio</key><real>0.5</real>",@@ -130,6 +132,7 @@ describe.skipIf(process.platform !== "darwin")($plist_type: "date",iso8601: "2020-01-01T00:00:00.000Z",},+ Far: { $plist_type: "date", iso8601: null },Ratio: { $plist_type: "real", value: null },Nested: [{@@ -148,6 +151,7 @@ describe.skipIf(process.platform !== "darwin")(limitations: [expect.stringContaining("XML conversion"),expect.stringContaining("2 non-finite real"),+ expect.stringContaining("1 date value(s)"),],},});diff --git a/tests/boundary/filesystem/interfaceBuilderBundle.test.ts b/tests/boundary/filesystem/interfaceBuilderBundle.test.tsindex 543248e63..1b2954b7b 100644--- a/tests/boundary/filesystem/interfaceBuilderBundle.test.ts+++ b/tests/boundary/filesystem/interfaceBuilderBundle.test.ts@@ -961,6 +961,33 @@ describe("bounded Interface Builder archive decoding", () => {);});+ it("decodes an archive whose date the decoder cannot represent", async () => {+ const root = await createTestTempDirectory("rea-ib-test-");+ const bundle = join(root, "Example.app");+ const resources = join(bundle, "Contents", "Resources");+ await mkdir(resources, { recursive: true });+ // plutil writes years past 9999 unsigned, which the decoder rejects.+ await writeFile(+ join(resources, "Far.nib"),+ '<?xml version="1.0"?><plist version="1.0"><dict><key>$archiver</key><string>NSKeyedArchiver</string><key>$objects</key><array><string>$null</string><date>11507-08-17T05:20:00Z</date></array><key>$top</key><dict/></dict></plist>',+ );++ const result = await analyzeInterfaceBuilderBundle({+ bundlePath: bundle,+ targetSha256: "f".repeat(64),+ });++ expect(result.documents).toHaveLength(1);+ expect(result.limitations).toContainEqual(+ expect.stringMatching(+ /^Contents\/Resources\/Far\.nib: 1 date value\(s\)/u,+ ),+ );+ expect(result.limitations).not.toContainEqual(+ expect.stringContaining("could not be decoded"),+ );+ });+it.skipIf(!xcodeIbtoolAvailable)("decodes an Xcode-compiled storyboard NIB and recovers its UI routes",async () => {diff --git a/tests/boundary/filesystem/keyedArchiveDateRange.test.ts b/tests/boundary/filesystem/keyedArchiveDateRange.test.tsnew file mode 100644index 000000000..9a45bbaa6--- /dev/null+++ b/tests/boundary/filesystem/keyedArchiveDateRange.test.ts@@ -0,0 +1,48 @@+import { writeFile } from "node:fs/promises";+import { join } from "node:path";++import { build } from "plist";+import { expect } from "vitest";++import { keyedArchiveResultSchema } from "../../../src/domain/apple/keyedArchive.js";+import { parseEvidence } from "../../../src/domain/evidence.js";+import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";+import { cliTest } from "../../support/cli/cliFixture.js";++cliTest(+ "built CLI reports a date the decoder cannot represent as unknown",+ async ({ cli }) => {+ const root = await createTestTempDirectory("rea-keyed-archive-date-");+ const path = join(root, "archive.plist");+ // plutil writes years past 9999 unsigned, which the decoder rejects.+ const xml = build({+ $archiver: "NSKeyedArchiver",+ $version: 100000,+ $objects: ["$null", "__FAR__", new Date("2020-01-01T00:00:00Z")],+ $top: { far: { CF$UID: 1 }, near: { CF$UID: 2 } },+ }).replace(+ "<string>__FAR__</string>",+ "<date>11507-08-17T05:20:00Z</date>",+ );+ await writeFile(path, xml);+ const output = await cli.run({+ arguments: ["inspect-keyed-archive", path, "--json"],+ environment: { REA_LOG_LEVEL: "silent", REA_ANALYSIS_PROVIDER: "auto" },+ });+ expect(output.exitCode).toBe(0);+ const result = keyedArchiveResultSchema.parse(+ parseEvidence(output.json).normalized_result,+ );+ expect(result.objects.map(({ id, value }) => ({ id, value }))).toEqual([+ { id: 0, value: "$null" },+ { id: 1, value: { $plist_type: "date", iso8601: null } },+ {+ id: 2,+ value: { $plist_type: "date", iso8601: "2020-01-01T00:00:00.000Z" },+ },+ ]);+ expect(result.limitations).toContainEqual(+ expect.stringContaining("1 date value(s)"),+ );+ },+);