fix(artifacts): preserve keyed archive integer precision

Integrate the numeric precision correction from #1135 with complete supplemental
metadata handling. Keep decoded numbers with an explicit limitation for mixed XML
content or unclassified integer text, rather than assigning another literal's
exact decimal. Project nonnumeric UID and CF$UID dictionary values recursively
while preserving numeric references, graph identity and original byte digests.

Add filesystem, built CLI and MCP regressions for the review findings, adjacent
XML representations and numeric reference controls. Retain the original native
Foundation qualification fixtures and verifier.

Verification: 84 focused tests; npm run check; npm run docs:check;
npm run verify:test-discovery; npm run verify:keyed-archive (real Foundation,
CLI and stdio MCP). No real Hopper or Ghidra verification was needed or run.

Co-authored-by: Rudy Mizrahi Celekli <47457359+rudycelekli@users.noreply.github.com>
Signed-off-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
morluto
2026-10-09 07:13:32 +08:00
co-authored by Rudy Mizrahi Celekli
parent 1d7115b7b4
commit 4034883e98
14 changed files with 1189 additions and 3 deletions
+27 -1
View File
@@ -4,6 +4,11 @@ import { z } from "zod";
import { AnalysisInputError } from "../../domain/analysisErrorCore.js";
import type { JsonValue } from "../../domain/jsonValue.js";
import { projectPlistValue } from "../../domain/apple/plistValue.js";
import { createPlistNumberProjection } from "../../domain/apple/plistNumbers.js";
import {
binaryPlistNumberLiterals,
xmlPlistNumberLiterals,
} from "./PlistNumberLiterals.js";
import {
omittedPrototypeKeysLimitation,
parseXmlPropertyList,
@@ -32,15 +37,36 @@ export const decodeKeyedArchiveBytes = (
"Selected file is a compiled NIBArchive, not a Foundation plist archive; decode it with decode_interface_builder",
);
const binary = bytes.subarray(0, 8).toString("ascii") === "bplist00";
const xmlText = binary ? undefined : decodeXmlPlistText(bytes);
const parsed = binary
? { value: parseBinary(bytes), omittedPrototypeKeys: 0 }
: parseXmlPropertyList(decodeXmlPlistText(bytes));
: parseXmlPropertyList(xmlText ?? "");
const graph = projectKeyedArchive(normalizePlist(parsed.value), selection);
const numbers = createPlistNumberProjection(
binary
? binaryPlistNumberLiterals(bytes)
: xmlPlistNumberLiterals(xmlText ?? ""),
);
// Classify the serialized graph before projecting values to typed decimals.
// Numeric IDs, node kinds, references and pagination retain their original meaning.
const roots = Object.fromEntries(
Object.entries(graph.roots).map(([name, value]) => [
name,
numbers.project(value),
]),
);
const objects = graph.objects.map((object) => ({
...object,
value: numbers.project(object.value),
}));
return {
archive_format: binary ? ("binary-plist" as const) : ("xml-plist" as const),
...graph,
roots,
objects,
limitations: [
...graph.limitations,
...numbers.limitations(),
...(parsed.omittedPrototypeKeys === 0
? []
: [omittedPrototypeKeysLimitation(parsed.omittedPrototypeKeys)]),