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(plist)!: preserve unknown XML scalar identities
morluto3537e58c1ab2
diff --git a/docs/native-investigation.md b/docs/native-investigation.mdindex dee54059d..61f199654 100644--- a/docs/native-investigation.md+++ b/docs/native-investigation.md@@ -604,9 +604,11 @@ digests identify the original serialized bytes.The archive reader observes XML number element types and binary number markers.XML values and their number facts are interpreted together from the validated-DOM. Hexadecimal `<integer>` text, including an optional sign, retains its value;+DOM and its original scalar source spans. Hexadecimal `<integer>` text, including+an optional sign, retains its value;`<real>` text and CDATA segments are combined without inferring text from nested-elements. The XML path does not serialize or reparse character references.+elements. Real character references expand outside CDATA; integer and date+literals use raw source text.Integers beyond the exact range of a JSON number are reported with the originaldecimal text as `{ "$plist_type": "integer", "decimal": "<exact digits>" }` whenthat source value can be associated unambiguously. Integral real values remain@@ -615,9 +617,9 @@ markers remain decoded with an explicit precision limitation. The limitationalso counts observed unsafe integer literals, including observations outside theselected object page. Incomplete supplemental metadata produces an explicitprecision note without rejecting an archive accepted by the byte decoder.-Mixed XML number content (comments, CDATA, processing instructions or child-elements) and integer text the supplemental reader cannot classify disable exact-association and retain decoded numbers with that precision note. Nonnumeric+Malformed XML scalar content becomes an explicit unknown rather than a prefix+number, guessed timestamp, or tag-only boolean. These unknowns do not disable+exact association for unrelated observed numbers. Nonnumeric`UID` and `CF$UID` dictionary values remain ordinary data and are projectedrecursively; numeric reference markers retain their original representation.@@ -638,11 +640,15 @@ decode budget reserves estimated room for number metadata and attributeprojection; these estimates are not a hard process-memory bound. NativeNIBArchive decoding is unchanged by this plist-specific representation.-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.+Dates are reported as `{ "$plist_type": "date", "iso8601": "<timestamp>" }`.+XML dates require a complete UTC spelling with fixed two-digit month, day and+time fields; short, negative and extended years are interpreted as UTC year+fields within JavaScript's date range. Unsupported calendar fields (including+leap seconds) and out-of-range dates remain explicit unknowns. REA does not+emulate CoreFoundation's normalization of overflowing calendar fields. Invalid+dates returned by other decoders retain `{ "$plist_type": "date", "iso8601": null }`+with a counted limitation. `inspect_plist` and Interface Builder decoding use+the same projection.A negative-zero real is reported as `{ "$plist_type": "real", "value": "-0" }`because a JSON number cannot carry the sign of zero. `inspect_plist` and@@ -659,14 +665,20 @@ for those details. XML CFPropertyList literals (`nan`, `+infinity`, `-infinity`,`infinity`, `inf`, `+inf`, `-inf`, case-insensitively) decode to the same knownvalues. Case and aliases normalize; original archive bytes retain source text.-XML numeric text whose identity the decoder cannot establish, including-unrecognized non-finite text and finite literals that overflow the numeric-representation, remains `{ "$plist_type": "real", "value": null }` with a-counted limitation. The XML decoder marks these values explicitly before shared-projection, so they cannot be confused with known binary IEEE values.-Incomplete numeric markup retains its existing compatibility behavior described-above. Known non-finite and unresolved numeric values have separate counts.-Native `inspect_plist` uses these same labels for plutil's XML conversion.+XML scalars whose identity cannot be established use+`{ "$plist_type": "unknown", "element": "integer" | "real" | "date" | "true" | "false", "literal": "<original content>", "reason": "invalid-literal" | "unsupported-markup" | "unrepresentable" }`.+A counted limitation accompanies these wrappers. Literal content retains its+original entity spelling, markup and line endings. Whole XML documents must+still pass strict well-formedness checks. Empty integer, real and date elements+are unknown scalars; boolean elements must be empty. Complete decimal/exponent+reals and signed decimal/hexadecimal integers accept their respective native+leading whitespace but reject trailing text. Arbitrary-precision integers+remain an intentional REA extension beyond CoreFoundation's integer range.+Finite real spellings that overflow the numeric representation remain unknown,+rather than becoming observed infinities. Known non-finite and unresolved scalar+values have separate counts. This replaces the former prefix-number and+incomplete-metadata fallback for malformed XML numeric content. Native+`inspect_plist` uses the same projection for plutil's XML conversion.## Locate a byte signaturediff --git a/src/artifacts/apple/InterfaceBuilderAnalysis.ts b/src/artifacts/apple/InterfaceBuilderAnalysis.tsindex d48fba88d..5d65e59e4 100644--- a/src/artifacts/apple/InterfaceBuilderAnalysis.ts+++ b/src/artifacts/apple/InterfaceBuilderAnalysis.ts@@ -10,6 +10,7 @@ import { DirectoryArtifactReader } from "../DirectoryArtifactReader.js";import {projectPlistValue,unknownDateLimitation,+ unknownScalarLimitation,} from "../../domain/apple/plistValue.js";import {omittedPrototypeKeysLimitation,@@ -67,6 +68,7 @@ export const analyzeInterfaceBuilderBundle = async (input: {const unresolvedConnections = new Map<string, number>();const prototypeKeyOmissions = new Map<string, number | null>();const unknownDates = new Map<string, number>();+ const unknownScalars = new Map<string, number>();let omitted = 0;let attempted = 0;let aggregateInputBytes = 0;@@ -148,6 +150,7 @@ export const analyzeInterfaceBuilderBundle = async (input: {value: raw,omittedPrototypeKeys,unknownDateCount,+ unknownScalarCount,numberLiterals,} = nib === null? decodePlist(bytes, xmlText, binaryPrototypeKeyObserved)@@ -155,6 +158,7 @@ export const analyzeInterfaceBuilderBundle = async (input: {value: nib.raw,omittedPrototypeKeys: 0,unknownDateCount: 0,+ unknownScalarCount: 0,numberLiterals: undefined,};if (nib !== null && nib.omitted > 0)@@ -165,6 +169,8 @@ export const analyzeInterfaceBuilderBundle = async (input: {prototypeKeyOmissions.set(entry.path, omittedPrototypeKeys);if (unknownDateCount !== 0)unknownDates.set(entry.path, unknownDateCount);+ if (unknownScalarCount !== 0)+ unknownScalars.set(entry.path, unknownScalarCount);const documentHash = createHash("sha256").update(bytes).digest("hex");documents.push({relativePath: entry.path,@@ -207,6 +213,7 @@ export const analyzeInterfaceBuilderBundle = async (input: {unresolvedConnections,prototypeKeyOmissions,unknownDates,+ unknownScalars,invalid,omittedArchives,unreportedOmittedArchives,@@ -276,6 +283,7 @@ const finalizeHierarchyCoverage = (unresolvedConnections: ReadonlyMap<string, number>;prototypeKeyOmissions: ReadonlyMap<string, number | null>;unknownDates: ReadonlyMap<string, number>;+ unknownScalars: ReadonlyMap<string, number>;invalid: readonly string[];omittedArchives: readonly { path: string; reason: string }[];unreportedOmittedArchives: number;@@ -288,6 +296,7 @@ const finalizeHierarchyCoverage = (unresolvedConnections,prototypeKeyOmissions,unknownDates,+ unknownScalars,invalid,omittedArchives,unreportedOmittedArchives,@@ -376,6 +385,9 @@ const finalizeHierarchyCoverage = (...[...unknownDates].map(([path, count]) => `${path}: ${unknownDateLimitation(count)}`,),+ ...[...unknownScalars].map(+ ([path, count]) => `${path}: ${unknownScalarLimitation(count)}`,+ ),...omittedArchives.map(({ path, reason }) =>`${path}: omitted because ${reason.replaceAll("_", " ")}.`,@@ -746,6 +758,7 @@ const decodePlist = (readonly value: JsonValue;readonly omittedPrototypeKeys: number | null;readonly unknownDateCount: number;+ readonly unknownScalarCount: number;readonly numberLiterals: PlistNumberLiterals;} => {const binary = hasBinaryPlistSignature(bytes);@@ -766,6 +779,7 @@ const decodePlist = (value: projected.value,omittedPrototypeKeys,unknownDateCount: projected.unknownDateCount,+ unknownScalarCount: projected.unknownScalarCount,numberLiterals,};};diff --git a/src/artifacts/apple/KeyedArchiveReader.ts b/src/artifacts/apple/KeyedArchiveReader.tsindex 79bb6ecc5..5081bdf01 100644--- a/src/artifacts/apple/KeyedArchiveReader.ts+++ b/src/artifacts/apple/KeyedArchiveReader.ts@@ -10,7 +10,7 @@ import {negativeZeroRealLimitation,nonFiniteRealLimitation,unknownDateLimitation,- unknownRealLimitation,+ unknownScalarLimitation,} from "../../domain/apple/plistValue.js";import { createPlistNumberProjection } from "../../domain/apple/plistNumbers.js";import {@@ -89,9 +89,9 @@ export const decodeKeyedArchiveBytes = (: parseXmlPropertyList(xmlText ?? "");const {nonFiniteRealCount,- unknownRealCount,negativeZeroRealCount,unknownDateCount,+ unknownScalarCount,...graph} = projectKeyedArchive(parsed.value, selection);const numbers = createPlistNumberProjection(parsed.numberLiterals);@@ -121,15 +121,15 @@ export const decodeKeyedArchiveBytes = (...(nonFiniteRealCount === 0? []: [nonFiniteRealLimitation(nonFiniteRealCount)]),- ...(unknownRealCount === 0- ? []- : [unknownRealLimitation(unknownRealCount)]),...(negativeZeroRealCount === 0? []: [negativeZeroRealLimitation(negativeZeroRealCount)]),...(unknownDateCount === 0? []: [unknownDateLimitation(unknownDateCount)]),+ ...(unknownScalarCount === 0+ ? []+ : [unknownScalarLimitation(unknownScalarCount)]),],};};diff --git a/src/domain/apple/keyedArchive.test.ts b/src/domain/apple/keyedArchive.test.tsindex 2610ff911..abf02e7aa 100644--- a/src/domain/apple/keyedArchive.test.ts+++ b/src/domain/apple/keyedArchive.test.ts@@ -1,6 +1,7 @@import { describe, expect, it } from "vitest";import { MAX_PLIST_DEPTH } from "./plistValue.js";import { projectKeyedArchive } from "./keyedArchive.js";+import { UnknownPlistScalar } from "./unknownPlistScalar.js";const deepValue = (depth: number): unknown => {let value: unknown = 1;@@ -86,3 +87,43 @@ describe("projectKeyedArchive root reference projection", () => {).toThrow(RangeError);});});++it("keeps generated unknown scalar wrappers scalar and lookalike dictionaries ordinary", () => {+ const result = projectKeyedArchive(+ {+ $archiver: "NSKeyedArchiver",+ $objects: [+ "$null",+ new UnknownPlistScalar(+ "false",+ "false<!-- value -->",+ "unsupported-markup",+ ),+ {+ $plist_type: "unknown",+ element: "false",+ literal: "false<!-- value -->",+ reason: "unsupported-markup",+ },+ ],+ $top: { root: { UID: 1 } },+ },+ { offset: 0, limit: 3 },+ );+ expect(result.unknownScalarCount).toBe(1);+ expect(result.objects[1]).toMatchObject({+ kind: "scalar",+ status: "observed",+ value: {+ $plist_type: "unknown",+ element: "false",+ literal: "false<!-- value -->",+ reason: "unsupported-markup",+ },+ });+ expect(result.objects[2]).toMatchObject({+ kind: "dictionary",+ status: "observed",+ value: { $plist_type: "unknown" },+ });+});diff --git a/src/domain/apple/keyedArchive.ts b/src/domain/apple/keyedArchive.tsindex 5ab26c85f..32d0fbf29 100644--- a/src/domain/apple/keyedArchive.ts+++ b/src/domain/apple/keyedArchive.ts@@ -248,9 +248,9 @@ export const projectKeyedArchive = (const ids = new Set(page.map(({ id }) => id));return {nonFiniteRealCount: projected.nonFiniteRealCount,- unknownRealCount: projected.unknownRealCount,negativeZeroRealCount: projected.negativeZeroRealCount,unknownDateCount: projected.unknownDateCount,+ unknownScalarCount: projected.unknownScalarCount,roots,objects: page,references: references.filter(diff --git a/src/domain/apple/plistNumbers.ts b/src/domain/apple/plistNumbers.tsindex 18302e5a3..9aee0b80c 100644--- a/src/domain/apple/plistNumbers.ts+++ b/src/domain/apple/plistNumbers.ts@@ -1,18 +1,5 @@import type { JsonValue } from "../jsonValue.js";-/** XML numeric decoding could not establish a representable value identity. */-export class UnknownPlistReal {}--/** Exact decimal or signed hexadecimal XML integer text. */-export const parsePlistIntegerLiteral = (text: string): bigint | undefined => {- const match = /^([+-]?)(?:0[xX]([\da-fA-F]+)|(\d+))$/u.exec(text.trim());- if (match === null) return undefined;- const magnitude = BigInt(- match[2] === undefined ? match[3]! : `0x${match[2]}`,- );- return match[1] === "-" ? -magnitude : magnitude;-};-/** Source element types needed to distinguish large integers from integral reals. */export interface PlistNumberLiterals {readonly integers: ReadonlyMap<number, ReadonlySet<string>>;@@ -31,7 +18,6 @@ export const createPlistNumberCollector = () => {const integers = new Map<number, Set<string>>();const reals = new Set<number>();let unsafeIntegerLiterals = 0;- let incompleteMetadata = false;return {integer: (exact: bigint) => {if (@@ -49,14 +35,11 @@ export const createPlistNumberCollector = () => {real: (value: number) => {reals.add(value);},- markIncomplete: () => {- incompleteMetadata = true;- },result: (incomplete = false): PlistNumberLiterals => ({integers,reals,unsafeIntegerLiterals,- incomplete: incomplete || incompleteMetadata,+ incomplete,}),};};@@ -136,30 +119,3 @@ export const createPlistNumberProjection = (literals: PlistNumberLiterals) => {],};};--/**- * Read a whole `<real>` text as one of CFPropertyList's non-finite spellings.- * Its parser compares the complete text case-insensitively and also accepts- * `infinity`, `inf`, `+inf` and `-inf`; its writer emits `nan`, `+infinity`- * and `-infinity`. Any other text, including surrounding whitespace, is not- * a spelled non-finite real.- */-export const parsePlistNonFiniteRealLiteral = (- text: string,-): number | undefined => {- if (text.length < 3 || text.length > 9) return undefined;- switch (text.toLowerCase()) {- case "nan":- return Number.NaN;- case "+infinity":- case "infinity":- case "+inf":- case "inf":- return Number.POSITIVE_INFINITY;- case "-infinity":- case "-inf":- return Number.NEGATIVE_INFINITY;- default:- return undefined;- }-};diff --git a/src/domain/apple/plistValue.test.ts b/src/domain/apple/plistValue.test.tsindex 91a772eaf..a06899531 100644--- a/src/domain/apple/plistValue.test.ts+++ b/src/domain/apple/plistValue.test.ts@@ -2,7 +2,7 @@ import { expect, it } from "vitest";import { parseBinary } from "plist";import { projectPlistValue } from "./plistValue.js";-import { UnknownPlistReal } from "./plistNumbers.js";+import { UnknownPlistScalar } from "./unknownPlistScalar.js";// Binary decoders build dates from seconds; beyond the Date range they are invalid.it("projects an unrepresentable date as unknown and counts it", () => {@@ -14,9 +14,9 @@ it("projects an unrepresentable date as unknown and counts it", () => {near: { $plist_type: "date", iso8601: "1970-01-01T00:00:00.000Z" },},nonFiniteRealCount: 0,- unknownRealCount: 0,negativeZeroRealCount: 0,unknownDateCount: 1,+ unknownScalarCount: 0,});});@@ -27,7 +27,6 @@ it("keeps a negative-zero real distinct from positive zero and counts it", () =>(wrapper) => observed.push(wrapper),);expect(projected.negativeZeroRealCount).toBe(1);- expect(projected.unknownRealCount).toBe(0);expect(Array.isArray(projected.value)).toBe(true);if (!Array.isArray(projected.value)) throw new Error("Expected array");expect(projected.value[0]).toEqual({ $plist_type: "real", value: "-0" });@@ -120,7 +119,6 @@ it("keeps retained integer scalars distinct from lookalike dictionaries", () =>[BigInt(decimal), { $plist_type: "integer", decimal }],(value) => observed.push(value),);- expect(projected.unknownRealCount).toBe(0);expect(projected.unknownDateCount).toBe(0);expect(Array.isArray(projected.value)).toBe(true);if (!Array.isArray(projected.value)) throw new Error("Expected array");@@ -130,30 +128,41 @@ it("keeps retained integer scalars distinct from lookalike dictionaries", () =>expect(observed[0]).not.toBe(projected.value[1]);});-it("projects known non-finite numbers while retaining explicit XML unknowns", () => {+it("projects known non-finite and unknown XML scalars without wrapping lookalikes", () => {const observed: object[] = [];const projected = projectPlistValue([Infinity,-Infinity,NaN,- new UnknownPlistReal(),- new UnknownPlistReal(),+ new UnknownPlistScalar("real", "1e999", "unrepresentable"),+ new UnknownPlistScalar(+ "integer",+ "12<!-- gap -->3",+ "unsupported-markup",+ ),{ $plist_type: "real", value: "nan" },+ {+ $plist_type: "unknown",+ element: "integer",+ literal: "12<!-- gap -->3",+ reason: "unsupported-markup",+ },],(wrapper) => observed.push(wrapper),);expect(projected.nonFiniteRealCount).toBe(3);- expect(projected.unknownRealCount).toBe(2);+ expect(projected.unknownScalarCount).toBe(2);expect(projected.negativeZeroRealCount).toBe(0);expect(JSON.stringify(projected.value)).toBe(- '[{"$plist_type":"real","value":"+infinity"},{"$plist_type":"real","value":"-infinity"},{"$plist_type":"real","value":"nan"},{"$plist_type":"real","value":null},{"$plist_type":"real","value":null},{"$plist_type":"real","value":"nan"}]',+ '[{"$plist_type":"real","value":"+infinity"},{"$plist_type":"real","value":"-infinity"},{"$plist_type":"real","value":"nan"},{"$plist_type":"unknown","element":"real","literal":"1e999","reason":"unrepresentable"},{"$plist_type":"unknown","element":"integer","literal":"12<!-- gap -->3","reason":"unsupported-markup"},{"$plist_type":"real","value":"nan"},{"$plist_type":"unknown","element":"integer","literal":"12<!-- gap -->3","reason":"unsupported-markup"}]',);expect(Array.isArray(projected.value)).toBe(true);if (!Array.isArray(projected.value)) throw new Error("Expected array");// Only generated wrappers are reported; the lookalike stays a dictionary.expect(observed).toEqual(projected.value.slice(0, 5));expect(observed).not.toContain(projected.value[5]);+ expect(observed).not.toContain(projected.value[6]);});it.each([@@ -226,7 +235,6 @@ it.each([]);expect(projected.nonFiniteRealCount).toBe(4);expect(projected.negativeZeroRealCount).toBe(1);- expect(projected.unknownRealCount).toBe(0);expect(observed).toHaveLength(5);expect(bytes).toEqual(original);});diff --git a/src/domain/apple/plistValue.ts b/src/domain/apple/plistValue.tsindex fb7b3feb2..6f406cc83 100644--- a/src/domain/apple/plistValue.ts+++ b/src/domain/apple/plistValue.ts@@ -2,7 +2,7 @@ import { types } from "node:util";import { z } from "zod";import type { JsonValue } from "../jsonValue.js";-import { UnknownPlistReal } from "./plistNumbers.js";+import { UnknownPlistScalar } from "./unknownPlistScalar.js";/*** Maximum plist value nesting the JSON projection supports. The XML decode@@ -16,26 +16,26 @@ export interface ProjectedPlistValue {readonly value: JsonValue;/** Known non-finite values, rendered with canonical numeric labels. */readonly nonFiniteRealCount: number;- /** XML numeric values whose identity could not be established. */- readonly unknownRealCount: number;/** Negative-zero reals, which a JSON number would report as positive zero. */readonly negativeZeroRealCount: number;/** Dates the decoder could not represent, reported without a timestamp. */readonly unknownDateCount: number;+ /** XML scalar literals retained explicitly because their values are unknown. */+ readonly unknownScalarCount: 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.`;+ `${String(count)} date value(s) are reported as { "$plist_type": "date", "iso8601": null } because the decoder could not represent their timestamps.`;++/** Limitation for XML scalar literals whose values were not established. */+export const unknownScalarLimitation = (count: number): string =>+ `${String(count)} XML scalar value(s) could not be established; their exact literals and reasons are retained in { "$plist_type": "unknown", "element": ..., "literal": ..., "reason": ... } wrappers.`;/** Limitation for known non-finite values; the labels do not imply XML provenance. */export const nonFiniteRealLimitation = (count: number): string =>`${String(count)} non-finite real value(s) are reported as { "$plist_type": "real", "value": "<spelling>" } using canonical numeric labels nan, +infinity or -infinity because a JSON number cannot carry them.`;-/** Limitation for XML numeric values the decoder could not establish. */-export const unknownRealLimitation = (count: number): string =>- `${String(count)} numeric value(s) are reported as { "$plist_type": "real", "value": null } because XML numeric decoding could not establish their value identity.`;-/** The typed scalar that keeps a negative-zero real distinct from positive zero. */export const negativeZeroReal = (): Record<string, JsonValue> => ({$plist_type: "real",@@ -58,9 +58,9 @@ export const projectPlistValue = (onWrappedScalar?: (value: Record<string, JsonValue>) => void,): ProjectedPlistValue => {let nonFiniteRealCount = 0;- let unknownRealCount = 0;let negativeZeroRealCount = 0;let unknownDateCount = 0;+ let unknownScalarCount = 0;const scalar = (value: Record<string, JsonValue>): JsonValue => {onWrappedScalar?.(value);return value;@@ -77,9 +77,14 @@ export const projectPlistValue = ($plist_type: "data",base64: Buffer.from(item).toString("base64"),});- if (item instanceof UnknownPlistReal) {- unknownRealCount += 1;- return scalar({ $plist_type: "real", value: null });+ if (item instanceof UnknownPlistScalar) {+ unknownScalarCount += 1;+ return scalar({+ $plist_type: "unknown",+ element: item.element,+ literal: item.rawLiteral,+ reason: item.reason,+ });}if (item instanceof Date) {if (!Number.isNaN(Date.prototype.getTime.call(item)))@@ -137,8 +142,8 @@ export const projectPlistValue = (return {value: projected,nonFiniteRealCount,- unknownRealCount,negativeZeroRealCount,unknownDateCount,+ unknownScalarCount,};};diff --git a/src/domain/apple/unknownPlistScalar.ts b/src/domain/apple/unknownPlistScalar.tsnew file mode 100644index 000000000..15166f1c4--- /dev/null+++ b/src/domain/apple/unknownPlistScalar.ts@@ -0,0 +1,11 @@+/** An XML plist scalar whose value cannot be established without guessing. */+export class UnknownPlistScalar {+ constructor(+ readonly element: "integer" | "real" | "date" | "true" | "false",+ readonly rawLiteral: string,+ readonly reason:+ | "invalid-literal"+ | "unsupported-markup"+ | "unrepresentable",+ ) {}+}diff --git a/src/domain/propertyListKeys.test.ts b/src/domain/propertyListKeys.test.tsindex c8898b859..f29fc1c30 100644--- a/src/domain/propertyListKeys.test.ts+++ b/src/domain/propertyListKeys.test.ts@@ -2,20 +2,10 @@ import { describe, expect, it } from "vitest";import { parse } from "plist";import {- decodeXmlText,omitPrototypeKeys,parseXmlPropertyList as parseWithNumbers,} from "./propertyListKeys.js";-it("preserves unknown named entities that collide with object prototype properties", () => {- expect(- decodeXmlText("&constructor; &toString; &valueOf; &hasOwnProperty;"),- ).toBe("&constructor; &toString; &valueOf; &hasOwnProperty;");- expect(decodeXmlText("&<>"'AB")).toBe(- "&<>\"'AB",- );-});-// Existing key/omission controls assert those facts exactly; numeric facts// have separate source-type and ambiguity controls below.const parseXmlPropertyList = (text: string) => {diff --git a/src/domain/propertyListKeys.ts b/src/domain/propertyListKeys.tsindex d1c5cbcf3..310020a9c 100644--- a/src/domain/propertyListKeys.ts+++ b/src/domain/propertyListKeys.ts@@ -2,10 +2,10 @@ import { parseOpenStep } from "plist";import { decodeXmlPropertyList } from "./propertyListXml.js";import {- UnknownPlistReal,createPlistNumberCollector,type PlistNumberLiterals,} from "./apple/plistNumbers.js";+import { UnknownPlistScalar } from "./apple/unknownPlistScalar.js";import { MAX_PLIST_DEPTH } from "./apple/plistValue.js";@@ -41,7 +41,7 @@ export const omitPrototypeKeys = (typeof item !== "object" ||item instanceof Date ||item instanceof Uint8Array ||- item instanceof UnknownPlistReal+ item instanceof UnknownPlistScalar)return item;return Object.fromEntries(@@ -56,37 +56,6 @@ export const omitPrototypeKeys = (return { value: stripped, omittedPrototypeKeys: omitted };};-const XML_ENTITIES: Readonly<Record<string, string>> = {- amp: "&",- apos: "'",- gt: ">",- lt: "<",- quot: '"',-};--/**- * Expand XML character and predefined entity references. A reference beyond- * Unicode stays as written: comments and CDATA may hold such text literally,- * and the XML decoder rejects it anywhere else.- */-export const decodeXmlText = (text: string): string =>- text.replace(- /&(?:#x([\da-f]+)|#(\d+)|([a-z]+));/giu,- (entity, hex?: string, decimal?: string, name?: string) => {- const codePoint =- hex !== undefined- ? parseInt(hex, 16)- : decimal !== undefined- ? parseInt(decimal, 10)- : undefined;- if (codePoint !== undefined)- return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : entity;- return name !== undefined && Object.hasOwn(XML_ENTITIES, name)- ? XML_ENTITIES[name]!- : entity;- },- );-/*** Decode one validated XML DOM into values and numeric source facts.* Entries keyed `__proto__` are omitted and counted at the same boundary.diff --git a/src/domain/propertyListXml.test.ts b/src/domain/propertyListXml.test.tsindex fa08815a2..b349cec11 100644--- a/src/domain/propertyListXml.test.ts+++ b/src/domain/propertyListXml.test.ts@@ -1,7 +1,7 @@import { expect, it } from "vitest";import { projectPlistValue } from "./apple/plistValue.js";-import { UnknownPlistReal } from "./apple/plistNumbers.js";+import { UnknownPlistScalar } from "./apple/unknownPlistScalar.js";import { parseXmlPropertyList } from "./propertyListKeys.js";it.each([@@ -55,8 +55,10 @@ it("keeps processing instructions inside numeric content subject to scalar rulesconst parsed = parseXmlPropertyList(`<plist><integer>4${markup}2</integer></plist>`,);- expect(parsed.value).toBe(4);- expect(parsed.numberLiterals.incomplete).toBe(true);+ expect(parsed.value).toEqual(+ new UnknownPlistScalar("integer", `4${markup}2`, "unsupported-markup"),+ );+ expect(parsed.numberLiterals.incomplete).toBe(false);}});@@ -77,8 +79,7 @@ it.each([["0X2a", 42],["+0x2A", 42],["-0x2A", -42],- ["0x2A", 42],- ["\n0x2A\n", 42],+ ["\n0x2A", 42],["42", 42],])("decodes exact integer text %s at the shared boundary",@@ -129,12 +130,24 @@ it("does not invent numeric facts from ignored scalar markup", () => {expect(parsed.numberLiterals.incomplete).toBe(false);});-it("retains partial numeric values with explicit incomplete metadata for unsupported markup", () => {+it("keeps unsupported numeric markup out of numeric source facts", () => {const parsed = parseXmlPropertyList("<plist><array><integer>0x2A<!-- unsupported --></integer><real>1<string>ignored</string>.25</real></array></plist>",);- expect(parsed.value).toEqual([0, 1.25]);- expect(parsed.numberLiterals.incomplete).toBe(true);+ expect(parsed.value).toEqual([+ new UnknownPlistScalar(+ "integer",+ "0x2A<!-- unsupported -->",+ "unsupported-markup",+ ),+ new UnknownPlistScalar(+ "real",+ "1<string>ignored</string>.25",+ "unsupported-markup",+ ),+ ]);+ expect(parsed.numberLiterals.incomplete).toBe(false);+ expect(parsed.numberLiterals.reals.size).toBe(0);});it("decodes a signed integer zero as zero and a negative-zero real with its sign", () => {@@ -149,7 +162,16 @@ it("decodes a signed integer zero as zero and a negative-zero real with its signtrue,false,]);- expect(parsed.value).toEqual([0, 0, -0, 0]);+ expect(parsed.value).toEqual([+ 0,+ new UnknownPlistScalar(+ "integer",+ "-0<!-- partial -->",+ "unsupported-markup",+ ),+ -0,+ 0,+ ]);});it("interprets failures in omitted entries before reporting partial evidence", () => {@@ -192,38 +214,106 @@ it.each([},);-it("keeps XML numeric overflow and unreadable text explicitly unknown", () => {- const parsed = parseXmlPropertyList(- "<plist><array><real>1e999</real><real>-1e999</real><real> nan </real><real>-nan</real><real>infinite</real></array></plist>",- );- expect(parsed.value).toEqual(- Array.from({ length: 5 }, () => new UnknownPlistReal()),- );- expect(parsed.numberLiterals.incomplete).toBe(false);-});+it.each([+ ["integer", "unreadable", "invalid-literal"],+ ["integer", `${"9".repeat(400)}invalid`, "invalid-literal"],+ ["integer", "0x2A", "invalid-literal"],+ ["integer", "42\n", "invalid-literal"],+ ["integer", "", "invalid-literal"],+ ["real", "", "invalid-literal"],+ ["real", "1e999", "unrepresentable"],+ ["real", "-1e999", "unrepresentable"],+ ["real", " nan ", "invalid-literal"],+ ["real", "-nan", "invalid-literal"],+ ["real", "infinite", "invalid-literal"],+ ["real", "Infinitysuffix", "invalid-literal"],+ ["real", "nan<!-- unsupported -->", "unsupported-markup"],+ ["date", "2026-10-17T12:00:00+02:00", "invalid-literal"],+ ["date", "2026-10-17T12:00:00.5Z", "invalid-literal"],+ ["date", "2026-10-17T12:00:00", "invalid-literal"],+ ["date", "2026-13-17T12:00:00Z", "unrepresentable"],+ ["date", "2026-02-31T12:00:00Z", "unrepresentable"],+ ["date", "<![CDATA[2026-10-17T12:00:00Z]]>", "unsupported-markup"],+ ["true", "x", "invalid-literal"],+ ["false", " ", "invalid-literal"],+ ["true", "<!-- empty -->", "unsupported-markup"],+] as const)(+ "keeps unresolved <%s> %j identity explicit",+ (element, literal, reason) => {+ const parsed = parseXmlPropertyList(+ `<plist><${element}>${literal}</${element}></plist>`,+ );+ expect(parsed.value).toEqual(+ new UnknownPlistScalar(element, literal, reason),+ );+ const projected = projectPlistValue(parsed.value);+ expect(projected.value).toEqual({+ $plist_type: "unknown",+ element,+ literal,+ reason,+ });+ expect(projected.unknownScalarCount).toBe(1);+ expect(projected.nonFiniteRealCount).toBe(0);+ expect(parsed.numberLiterals.incomplete).toBe(false);+ },+);-it("does not infer a spelled real from incomplete numeric markup", () => {+it.each([+ "4<!-- </integer> -->2",+ "4<?rea </integer> ?>2",+ "4<![CDATA[</integer>]]>2",+ '4<integer note=">">2<integer/></integer>3',+])(+ "retains complete source markup %j without treating apparent closing tags as structure",+ (literal) => {+ expect(+ parseXmlPropertyList(`<plist><integer>${literal}</integer></plist>`)+ .value,+ ).toEqual(new UnknownPlistScalar("integer", literal, "unsupported-markup"));+ },+);++it("binds raw literals to their nodes across normalized line endings and UTF-16 columns", () => {const parsed = parseXmlPropertyList(- "<plist><real>-inf<!-- unsupported --></real></plist>",+ '<plist><array><string>💡</string>\r\n<integer note=">">42\r\nabc</integer>\u0085<date>2026-10-17T12:00:00Z</date>\u2028<false>\r\n</false></array></plist>',);- expect(parsed.value).toBeInstanceOf(UnknownPlistReal);- expect(parsed.numberLiterals.incomplete).toBe(true);+ expect(parsed.value).toEqual([+ "💡",+ new UnknownPlistScalar("integer", "42\r\nabc", "invalid-literal"),+ new UnknownPlistScalar(+ "date",+ "2026-10-17T12:00:00Z",+ "invalid-literal",+ ),+ new UnknownPlistScalar("false", "\r\n", "invalid-literal"),+ ]);});-it.each([- ["integer", "unreadable"],- ["integer", `${"9".repeat(400)}invalid`],- ["real", "1e999"],- ["real", "-1e999"],- ["real", "Infinitysuffix"],- ["real", "nan<!-- unsupported -->"],-])("keeps unresolved <%s> numeric identity explicit", (tag, text) => {- const parsed = parseXmlPropertyList(- `<plist><${tag}>${text}</${tag}></plist>`,- );- expect(parsed.value).toBeInstanceOf(UnknownPlistReal);- const projected = projectPlistValue(parsed.value);- expect(projected.value).toEqual({ $plist_type: "real", value: null });- expect(projected.unknownRealCount).toBe(1);- expect(projected.nonFiniteRealCount).toBe(0);+it.each(["\u0085", "\u2028", "\u2029"])(+ "does not normalize unsupported leading whitespace %j into an observed scalar",+ (prefix) => {+ const parsed = parseXmlPropertyList(+ `<plist><array><integer>${prefix}42</integer><real>${prefix}1.5</real></array></plist>`,+ );+ expect(parsed.value).toEqual([+ new UnknownPlistScalar("integer", `${prefix}42`, "invalid-literal"),+ prefix === "\u0085"+ ? 1.5+ : new UnknownPlistScalar("real", `${prefix}1.5`, "invalid-literal"),+ ]);+ },+);++it("expands real references outside CDATA without changing scalar source policy", () => {+ expect(+ parseXmlPropertyList(+ "<plist><array><real>1<![CDATA[.5]]></real><real><![CDATA[1.5]]></real><true/><false></false></array></plist>",+ ).value,+ ).toEqual([+ 1.5,+ new UnknownPlistScalar("real", "<![CDATA[1.5]]>", "invalid-literal"),+ true,+ false,+ ]);});diff --git a/src/domain/propertyListXml.ts b/src/domain/propertyListXml.tsindex 6ebf462d9..757f3602c 100644--- a/src/domain/propertyListXml.ts+++ b/src/domain/propertyListXml.ts@@ -2,12 +2,13 @@ import type { Node } from "@xmldom/xmldom";import { readXmlPlistSource } from "./propertyListXmlSource.js";+import { createPlistNumberCollector } from "./apple/plistNumbers.js";+import { UnknownPlistScalar } from "./apple/unknownPlistScalar.js";import {- UnknownPlistReal,- createPlistNumberCollector,- parsePlistIntegerLiteral,- parsePlistNonFiniteRealLiteral,-} from "./apple/plistNumbers.js";+ decodeXmlPlistDateLiteral,+ parseXmlPlistIntegerLiteral,+ parseXmlPlistRealLiteral,+} from "./propertyListXmlScalar.js";/** Own source interpretation, depth, values and numeric facts together. */export const decodeXmlPropertyList = (text: string) => {@@ -17,32 +18,33 @@ export const decodeXmlPropertyList = (text: string) => {if (root?.nodeName !== "plist")throw new TypeError("malformed document. First element should be <plist>");const numbers = createPlistNumberCollector();- const requireContent = (node: Node): Node => {- if (node.firstChild === null)- throw new TypeError(`Cannot parse "" as ${node.nodeName}`);- return node.firstChild;- };const textNode = (node: Node) => node.nodeType === node.TEXT_NODE;const characterNode = (node: Node) =>textNode(node) || node.nodeType === node.CDATA_SECTION_NODE;const content = (node: Node, accepts: (child: Node) => boolean) => {let text = "";- let complete = true;for (let child = node.firstChild;child !== null;child = child.nextSibling) {if (accepts(child)) text += child.nodeValue ?? "";- else complete = false;}- return { text, complete };+ return text;+ };+ const hasUnsupportedMarkup = (+ node: Node,+ accepts: (child: Node) => boolean,+ ): boolean => {+ for (let child = node.firstChild; child !== null; child = child.nextSibling)+ if (!accepts(child)) return true;+ return false;};const dictionaryKey = (node: Node): string => {for (let child = node.firstChild; child !== null; child = child.nextSibling)if (child.nodeType === child.ELEMENT_NODE)return String(node.firstChild?.nodeValue ?? null);- return content(node, characterNode).text;+ return content(node, characterNode);};const members = function* (node: Node) {for (let child = node.firstChild; child !== null; child = child.nextSibling)@@ -96,46 +98,39 @@ export const decodeXmlPropertyList = (text: string) => {return value;}case "string":- return content(node, characterNode).text;+ return content(node, characterNode);case "integer": {- const first = requireContent(node);- const literal = content(node, textNode);- const exact = literal.complete- ? parsePlistIntegerLiteral(literal.text)+ const raw = source.scalarLiteral(node);+ if (!raw.ok) throw raw.error;+ const unsupportedMarkup = hasUnsupportedMarkup(node, textNode);+ const exact = !unsupportedMarkup+ ? parseXmlPlistIntegerLiteral(raw.value): undefined;- if (exact === undefined) {- numbers.markIncomplete();- const partial = Number.parseInt(first.nodeValue ?? "", 10);- // An integer has no signed zero; keep -0 from reading as a real.- return !Number.isFinite(partial)- ? new UnknownPlistReal()- : partial === 0- ? 0- : partial;- }+ if (exact === undefined)+ return new UnknownPlistScalar(+ "integer",+ raw.value,+ unsupportedMarkup ? "unsupported-markup" : "invalid-literal",+ );numbers.integer(exact);const decoded = Number(exact);- // Keep a finite integer's identity when it cannot fit even a Number- // approximation; otherwise it would be mislabeled as a non-finite real.+ // Arbitrary-precision integers are a REA extension to CF's range.return Number.isFinite(decoded) ? decoded : exact;}case "real": {- requireContent(node);- const literal = content(node, characterNode);- if (!literal.complete) numbers.markIncomplete();- // CFPropertyList spells NaN and the infinities; parseFloat would read- // the lowercase spellings as NaN and lose the kind and sign.- const known = literal.complete- ? parsePlistNonFiniteRealLiteral(literal.text)- : undefined;- if (known !== undefined) {- numbers.real(known);- return known;- }- const value = Number.parseFloat(literal.text);- if (!Number.isFinite(value)) return new UnknownPlistReal();- if (literal.complete) numbers.real(value);- return value;+ const raw = source.scalarLiteral(node);+ if (!raw.ok) throw raw.error;+ if (hasUnsupportedMarkup(node, characterNode))+ return new UnknownPlistScalar(+ "real",+ raw.value,+ "unsupported-markup",+ );+ const value = parseXmlPlistRealLiteral(raw.value);+ if (!value.ok)+ return new UnknownPlistScalar("real", raw.value, value.error);+ numbers.real(value.value);+ return value.value;}case "data": {const value = source.dataValue(node);@@ -143,15 +138,35 @@ export const decodeXmlPropertyList = (text: string) => {return value.value;}case "date": {- const value = requireContent(node).nodeValue;- return new Date(value === null ? 0 : value);+ const raw = source.scalarLiteral(node);+ if (!raw.ok) throw raw.error;+ if (hasUnsupportedMarkup(node, textNode))+ return new UnknownPlistScalar(+ "date",+ raw.value,+ "unsupported-markup",+ );+ const date = decodeXmlPlistDateLiteral(raw.value);+ return date.ok+ ? date.value+ : new UnknownPlistScalar("date", raw.value, date.error);}case "null":return null;case "true":- return true;- case "false":- return false;+ case "false": {+ const raw = source.scalarLiteral(node);+ if (!raw.ok) throw raw.error;+ return raw.value === ""+ ? node.nodeName === "true"+ : new UnknownPlistScalar(+ node.nodeName,+ raw.value,+ hasUnsupportedMarkup(node, textNode)+ ? "unsupported-markup"+ : "invalid-literal",+ );+ }default:throw new TypeError(`Invalid PLIST tag ${node.nodeName}`);}diff --git a/src/domain/propertyListXmlScalar.test.ts b/src/domain/propertyListXmlScalar.test.tsnew file mode 100644index 000000000..6ff6603f2--- /dev/null+++ b/src/domain/propertyListXmlScalar.test.ts@@ -0,0 +1,139 @@+import { expect, it } from "vitest";++import {+ decodeXmlPlistDateLiteral,+ parseXmlPlistIntegerLiteral,+ parseXmlPlistRealLiteral,+} from "./propertyListXmlScalar.js";++it.each([+ ["42", 42n],+ [" + 42", 42n],+ ["\n- 0x2a", -42n],+ ["+0XAF", 175n],+ [`${"9".repeat(80)}`, BigInt("9".repeat(80))],+])("parses complete XML plist integer text %j", (raw, expected) => {+ expect(parseXmlPlistIntegerLiteral(raw)).toBe(expected);+});++it.each(["", "42 ", "42\n", "+", "0x", "0 x2a", "42.0", "42&foo;"])(+ "rejects incomplete or trailing XML plist integer text %j",+ (raw) => {+ expect(parseXmlPlistIntegerLiteral(raw)).toBeUndefined();+ },+);++it.each([+ [" 42.5", 42.5],+ ["\t-1.25e2", -125],+ [".5", 0.5],+ ["1.", 1],+ ["NaN", Number.NaN],+ ["+inf", Infinity],+ ["-infinity", -Infinity],+])("parses complete XML plist real text %j", (raw, expected) => {+ expect(parseXmlPlistRealLiteral(raw)).toEqual({ ok: true, value: expected });+});++it.each([+ "",+ "42.5 ",+ "42.5\n",+ "1e",+ "0x1p2",+ "1,25",+ "1suffix",+ "nan ",+ "infinite",+ "-NaN",+])("rejects incomplete or unsupported XML plist real text %j", (raw) => {+ expect(parseXmlPlistRealLiteral(raw)).toEqual({+ ok: false,+ error: "invalid-literal",+ });+});++it.each([+ ["2001-02-03T04:05:06Z", Date.UTC(2001, 1, 3, 4, 5, 6)],+ ["0000-02-29T00:00:00Z", -62162121600000],+])("decodes XML plist date text %s", (raw, expected) => {+ const date = decodeXmlPlistDateLiteral(raw);+ expect(date).toEqual({ ok: true, value: new Date(expected) });+});++it.each([+ "2001-2-03T04:05:06Z",+ "2001-02-03t04:05:06Z",+ "2001-02-03T04:05:06+00:00",+ " 2001-02-03T04:05:06Z",+ "2001-02-03T04:05:06Z ",+ "2001-02-03T04:05:06Z&",+])("rejects malformed XML plist date text %j", (raw) => {+ expect(decodeXmlPlistDateLiteral(raw)).toEqual({+ ok: false,+ error: "invalid-literal",+ });+});++it.each([+ "2001-02-29T04:05:06Z",+ "2000-13-01T00:00:00Z",+ "2000-01-01T24:00:00Z",+ "2000-01-01T00:00:60Z",+ "275761-01-01T00:00:00Z",+])(+ "keeps unsupported XML plist date %s distinct from malformed text",+ (raw) => {+ const date = decodeXmlPlistDateLiteral(raw);+ expect(date).toEqual({ ok: false, error: "unrepresentable" });+ },+);++it("distinguishes finite-spelling overflow from a known infinity", () => {+ expect(parseXmlPlistRealLiteral("1e999")).toEqual({+ ok: false,+ error: "unrepresentable",+ });+ expect(parseXmlPlistRealLiteral("-1e999")).toEqual({+ ok: false,+ error: "unrepresentable",+ });+});++it.each([+ ["\u0085", false, true],+ ["\u00a0", false, true],+ ["\u1680", false, false],+ ["\u2003", true, true],+ ["\u200b", true, true],+ ["\u2028", false, false],+ ["\u202f", false, false],+ ["\u205f", true, false],+ ["\ufeff", false, true],+] as const)(+ "preserves distinct integer and real leading whitespace rules for %j",+ (prefix, integerAccepted, realAccepted) => {+ expect(parseXmlPlistIntegerLiteral(`${prefix}42`)).toBe(+ integerAccepted ? 42n : undefined,+ );+ expect(parseXmlPlistRealLiteral(`${prefix}42`)).toEqual(+ realAccepted+ ? { ok: true, value: 42 }+ : { ok: false, error: "invalid-literal" },+ );+ },+);++it.each([+ ["1-01-01T00:00:00Z", "0001-01-01T00:00:00.000Z"],+ ["-0001-01-01T00:00:00Z", "-000001-01-01T00:00:00.000Z"],+ ["10000-01-01T00:00:00Z", "+010000-01-01T00:00:00.000Z"],+])(+ "interprets year fields as UTC without host string-date inference: %s",+ (literal, iso8601) => {+ expect(decodeXmlPlistDateLiteral(literal)).toEqual({+ ok: true,+ value: new Date(iso8601),+ });+ },+);diff --git a/src/domain/propertyListXmlScalar.ts b/src/domain/propertyListXmlScalar.tsnew file mode 100644index 000000000..f6896b059--- /dev/null+++ b/src/domain/propertyListXmlScalar.ts@@ -0,0 +1,139 @@+import { err, ok, type Result } from "./result.js";++// Integer parsing examines UTF-8 bytes; real scanning examines CFString+// characters. Native plutil controls distinguish their leading-whitespace sets;+// notably, this host rejects U+202F despite its inclusion in older CF source.+const INTEGER_WHITESPACE =+ "[\\u0000-\\u0020\\u007f\\u2000-\\u200b\\u205f\\u3000]*";+const REAL_WHITESPACE =+ "[\\u0000-\\u0020\\u007f-\\u00a0\\u2000-\\u200b\\u3000\\ufeff]*";+const INTEGER_LITERAL = new RegExp(+ `^${INTEGER_WHITESPACE}(?:([+-])${INTEGER_WHITESPACE})?(?:0[xX]([\\da-fA-F]+)|(\\d+))$`,+ "u",+);+const REAL_LEADING_WHITESPACE = new RegExp(`^${REAL_WHITESPACE}`, "u");++/** Parse CF-style decimal or hexadecimal integer text without losing precision. */+export const parseXmlPlistIntegerLiteral = (+ raw: string,+): bigint | undefined => {+ const match = INTEGER_LITERAL.exec(raw);+ if (match === null) return undefined;++ const magnitude = BigInt(+ match[2] === undefined ? match[3]! : `0x${match[2]}`,+ );+ return match[1] === "-" ? -magnitude : magnitude;+};++/**+ * Parse UTC fields without JavaScript string-date parsing or calendar rollover.+ * Syntax failures and unsupported date representations retain distinct reasons.+ */+export const decodeXmlPlistDateLiteral = (+ raw: string,+): Result<Date, "invalid-literal" | "unrepresentable"> => {+ const match = /^(-?)(\d+)-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/u.exec(+ raw,+ );+ if (match === null) return err("invalid-literal");++ const yearMagnitude = Number(match[2]);+ const year = match[1] === "-" ? -yearMagnitude : yearMagnitude;+ const month = Number(match[3]);+ const day = Number(match[4]);+ const hour = Number(match[5]);+ const minute = Number(match[6]);+ const second = Number(match[7]);++ if (+ !Number.isSafeInteger(year) ||+ month < 1 ||+ month > 12 ||+ hour > 23 ||+ minute > 59 ||+ second > 59+ )+ return err("unrepresentable");++ const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);+ const daysInMonth = [+ 31,+ leapYear ? 29 : 28,+ 31,+ 30,+ 31,+ 30,+ 31,+ 31,+ 30,+ 31,+ 30,+ 31,+ ][month - 1]!;+ if (day < 1 || day > daysInMonth) return err("unrepresentable");++ const date = new Date(0);+ date.setUTCFullYear(year, month - 1, day);+ date.setUTCHours(hour, minute, second, 0);+ return Number.isNaN(date.getTime()) ? err("unrepresentable") : ok(date);+};++/** Parse a complete decimal or CF-spelled non-finite real literal. */+export const parseXmlPlistRealLiteral = (+ raw: string,+): Result<number, "invalid-literal" | "unrepresentable"> => {+ // This content has passed XML well-formedness and character-node checks.+ // Expand references only outside CDATA; retain original line endings, which+ // the DOM's compatibility normalization would otherwise erase.+ const text = raw.replace(+ /<!\[CDATA\[([\s\S]*?)\]\]>|&#(?:x([\da-fA-F]+)|(\d+));|&(amp|lt|gt|apos|quot);/gu,+ (+ _token,+ cdata: string | undefined,+ hex: string | undefined,+ decimal: string | undefined,+ name: string | undefined,+ ) => {+ if (cdata !== undefined) return cdata;+ if (hex !== undefined)+ return String.fromCodePoint(Number.parseInt(hex, 16));+ if (decimal !== undefined)+ return String.fromCodePoint(Number.parseInt(decimal, 10));+ return name === "amp"+ ? "&"+ : name === "lt"+ ? "<"+ : name === "gt"+ ? ">"+ : name === "apos"+ ? "'"+ : '"';+ },+ );+ // CF compares complete non-finite spellings before scanning a decimal.+ if (text.length <= 9) {+ switch (text.toLowerCase()) {+ case "nan":+ return ok(Number.NaN);+ case "+infinity":+ case "infinity":+ case "+inf":+ case "inf":+ return ok(Number.POSITIVE_INFINITY);+ case "-infinity":+ case "-inf":+ return ok(Number.NEGATIVE_INFINITY);+ }+ }++ const numericText = text.replace(REAL_LEADING_WHITESPACE, "");+ if (+ !/^[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?$/u.test(+ numericText,+ )+ )+ return err("invalid-literal");+ const value = Number(numericText);+ return Number.isFinite(value) ? ok(value) : err("unrepresentable");+};diff --git a/src/domain/propertyListXmlSource.ts b/src/domain/propertyListXmlSource.tsindex 6f180d27e..26e29ab92 100644--- a/src/domain/propertyListXmlSource.ts+++ b/src/domain/propertyListXmlSource.ts@@ -7,15 +7,23 @@ import {XmlPlistDataError,} from "./propertyListXmlData.js";-// Preserve the established XML decoder normalization; keep raw data separately.+// Preserve DOM compatibility normalization while retaining raw scalar spans.const LINE_ENDING = /\r[\n\u0085]|[\r\n\u0085\u2028\u2029]/gu;-interface DataSpan {+interface ScalarSpan {readonly start: number;readonly end: number;+ readonly selfClosing: boolean;}-/** One source owner binds lexical data values to their validated DOM nodes. */+export class XmlPlistSourceError extends TypeError {+ readonly _tag = "XmlPlistSourceError";+ constructor() {+ super("Cannot locate XML plist scalar in its original source");+ }+}++/** One source owner binds lexical scalar values to their validated DOM nodes. */export const readXmlPlistSource = (text: string) => {const normalized = text.replace(LINE_ENDING, "\n");const parsed = parseXmlDocument(normalized, {@@ -29,9 +37,7 @@ export const readXmlPlistSource = (text: string) => {let lineStart = 0;// The depth walk visits elements in source order, so location lookup is// linear without an index entry for every line in a potentially large value.- const readData = (- node: Node,- ): Result<DataSpan, XmlPlistDataError["reason"]> => {+ const readSpan = (node: Node): Result<ScalarSpan, "source-location"> => {if (node.lineNumber === undefined || node.columnNumber === undefined)return err("source-location");while (line < node.lineNumber) {@@ -41,31 +47,46 @@ export const readXmlPlistSource = (text: string) => {line += 1;}if (line !== node.lineNumber) return err("source-location");- for (let child = node.firstChild; child !== null; child = child.nextSibling)- if (child.nodeType !== child.TEXT_NODE) return err("markup");const start = lineStart + node.columnNumber - 1;const openingEnd = openingTagEnd(text, start);- if (openingEnd < 0) return err("source-location");- if (text[openingEnd - 1] === "/") return err("empty-element");- const end = text.indexOf("<", openingEnd + 1);- if (end < 0) return err("source-location");- return ok({ start: openingEnd + 1, end });+ if (openingEnd < 0 || text[start] !== "<") return err("source-location");+ const selfClosing = text[openingEnd - 1] === "/";+ const end = selfClosing+ ? openingEnd + 1+ : closingTagStart(text, openingEnd + 1);+ return end < 0+ ? err("source-location")+ : ok({ start: openingEnd + 1, end, selfClosing });};- const data = collectXmlPlistDataSpans(document, readData);+ const spans = collectXmlPlistScalarSpans(document, readSpan);return {document,+ scalarLiteral(node: Node): Result<string, XmlPlistSourceError> {+ const span = spans.get(node);+ return span?.ok === true+ ? ok(text.slice(span.value.start, span.value.end))+ : err(new XmlPlistSourceError());+ },dataValue(node: Node): Result<Uint8Array, XmlPlistDataError> {- const span = data.get(node);- if (span === undefined)+ const span = spans.get(node);+ if (node.nodeName !== "data" || span === undefined)return err(new XmlPlistDataError("source-location"));- return span.ok- ? decodeXmlPlistData(text.slice(span.value.start, span.value.end))- : err(new XmlPlistDataError(span.error));+ if (!span.ok) return err(new XmlPlistDataError(span.error));+ for (+ let child = node.firstChild;+ child !== null;+ child = child.nextSibling+ )+ if (child.nodeType !== child.TEXT_NODE)+ return err(new XmlPlistDataError("markup"));+ if (span.value.selfClosing)+ return err(new XmlPlistDataError("empty-element"));+ return decodeXmlPlistData(text.slice(span.value.start, span.value.end));},};};-/** The validated DOM omits the distinction between <data/> and <data></data>. */+/** Scan validated tag syntax without treating a quoted > as its end. */const openingTagEnd = (source: string, start: number): number => {let quote: string | undefined;for (let cursor = start; cursor < source.length; cursor += 1) {@@ -78,6 +99,50 @@ const openingTagEnd = (source: string, start: number): number => {return -1;};+/**+ * Locate an element's closing tag in validated XML. Comments, CDATA and PIs+ * can contain apparent tags; nested markup is retained as source, not decoded+ * or recursively interpreted as additional plist values.+ */+const closingTagStart = (source: string, contentStart: number): number => {+ let depth = 1;+ let cursor = contentStart;+ while (cursor < source.length) {+ const start = source.indexOf("<", cursor);+ if (start < 0) return -1;+ const delimiter = source.startsWith("<!--", start)+ ? "-->"+ : source.startsWith("<![CDATA[", start)+ ? "]]>"+ : source.startsWith("<?", start)+ ? "?>"+ : undefined;+ if (delimiter !== undefined) {+ const end = source.indexOf(delimiter, start + 2);+ if (end < 0) return -1;+ cursor = end + delimiter.length;+ continue;+ }+ const end = openingTagEnd(source, start);+ if (end < 0) return -1;+ if (source[start + 1] === "/") {+ depth -= 1;+ if (depth === 0) return start;+ } else if (source[end - 1] !== "/") depth += 1;+ cursor = end + 1;+ }+ return -1;+};++const PLIST_LEXICAL_SCALARS = new Set([+ "data",+ "integer",+ "real",+ "date",+ "true",+ "false",+]);+/** Elements whose children the plist value decoder visits recursively. */const PLIST_CONTAINER_ELEMENTS = new Set(["plist", "dict", "array"]);@@ -94,16 +159,13 @@ const PLIST_CONTAINER_ELEMENTS = new Set(["plist", "dict", "array"]);* its own level. The outer plist envelope is unwrapped by the decoder;* nested plist elements decode as arrays and must count toward the bound.*/-const collectXmlPlistDataSpans = (+const collectXmlPlistScalarSpans = (document: Document,- readData: (node: Node) => Result<DataSpan, XmlPlistDataError["reason"]>,-): WeakMap<Node, Result<DataSpan, XmlPlistDataError["reason"]>> => {- const data = new WeakMap<- Node,- Result<DataSpan, XmlPlistDataError["reason"]>- >();+ readSpan: (node: Node) => Result<ScalarSpan, "source-location">,+): WeakMap<Node, Result<ScalarSpan, "source-location">> => {+ const spans = new WeakMap<Node, Result<ScalarSpan, "source-location">>();const root = document.documentElement;- if (root === null) return data;+ if (root === null) return spans;const pending: Array<{ node: Node; depth: number }> = [{ node: root, depth: -1 },];@@ -120,9 +182,10 @@ const collectXmlPlistDataSpans = (throw new RangeError(`Plist exceeds ${String(MAX_PLIST_DEPTH)} nesting levels`,);- if (node.nodeName === "data") data.set(node, readData(node));+ if (PLIST_LEXICAL_SCALARS.has(node.nodeName))+ spans.set(node, readSpan(node));if (PLIST_CONTAINER_ELEMENTS.has(node.nodeName) && node.firstChild !== null)pending.push({ node: node.firstChild, depth: depth + 1 });}- return data;+ return spans;};diff --git a/src/native/NativeMacOSProvider.ts b/src/native/NativeMacOSProvider.tsindex bc9db41b0..a2e024ecd 100644--- a/src/native/NativeMacOSProvider.ts+++ b/src/native/NativeMacOSProvider.ts@@ -64,9 +64,9 @@ import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";import {projectPlistValue,nonFiniteRealLimitation,- unknownRealLimitation,negativeZeroRealLimitation,unknownDateLimitation,+ unknownScalarLimitation,} from "../domain/apple/plistValue.js";import { createPlistNumberProjection } from "../domain/apple/plistNumbers.js";import type { NativeUiObservationResult } from "../domain/native/nativeUiObservation.js";@@ -1244,15 +1244,15 @@ const parseEntitlements = (...(projected.nonFiniteRealCount === 0? []: [nonFiniteRealLimitation(projected.nonFiniteRealCount)]),- ...(projected.unknownRealCount === 0- ? []- : [unknownRealLimitation(projected.unknownRealCount)]),...(projected.negativeZeroRealCount === 0? []: [negativeZeroRealLimitation(projected.negativeZeroRealCount)]),...(projected.unknownDateCount === 0? []: [unknownDateLimitation(projected.unknownDateCount)]),+ ...(projected.unknownScalarCount === 0+ ? []+ : [unknownScalarLimitation(projected.unknownScalarCount)]),],};};diff --git a/src/native/parsers/plist.test.ts b/src/native/parsers/plist.test.tsindex a23f87e2d..6cfde85b7 100644--- a/src/native/parsers/plist.test.ts+++ b/src/native/parsers/plist.test.ts@@ -190,11 +190,11 @@ it("keeps CFPropertyList's non-finite real spellings in XML evidence", () => {);if (!parsed.ok) throw parsed.error;expect(JSON.stringify(parsed.value.value)).toBe(- '{"Up":{"$plist_type":"real","value":"+infinity"},"Down":{"$plist_type":"real","value":"-infinity"},"Missing":{"$plist_type":"real","value":"nan"},"Overflow":{"$plist_type":"real","value":null},"Ratio":1.25}',+ '{"Up":{"$plist_type":"real","value":"+infinity"},"Down":{"$plist_type":"real","value":"-infinity"},"Missing":{"$plist_type":"real","value":"nan"},"Overflow":{"$plist_type":"unknown","element":"real","literal":"1e999","reason":"unrepresentable"},"Ratio":1.25}',);expect(parsed.value.limitations).toEqual([expect.stringContaining("XML conversion"),'3 non-finite real value(s) are reported as { "$plist_type": "real", "value": "<spelling>" } using canonical numeric labels nan, +infinity or -infinity because a JSON number cannot carry them.',- '1 numeric value(s) are reported as { "$plist_type": "real", "value": null } because XML numeric decoding could not establish their value identity.',+ expect.stringContaining("1 XML scalar value(s) could not be established"),]);});diff --git a/src/native/parsers/plist.ts b/src/native/parsers/plist.tsindex 0b4fddea4..0ee5fa3d3 100644--- a/src/native/parsers/plist.ts+++ b/src/native/parsers/plist.ts@@ -8,7 +8,7 @@ import {nonFiniteRealLimitation,projectPlistValue,unknownDateLimitation,- unknownRealLimitation,+ unknownScalarLimitation,type ProjectedPlistValue,} from "../../domain/apple/plistValue.js";import {@@ -207,13 +207,13 @@ export const parsePlistXml = (...(projected.nonFiniteRealCount === 0? []: [nonFiniteRealLimitation(projected.nonFiniteRealCount)]),- ...(projected.unknownRealCount === 0- ? []- : [unknownRealLimitation(projected.unknownRealCount)]),...negativeZeroLimitations(projected.negativeZeroRealCount),...(projected.unknownDateCount === 0? []: [unknownDateLimitation(projected.unknownDateCount)]),+ ...(projected.unknownScalarCount === 0+ ? []+ : [unknownScalarLimitation(projected.unknownScalarCount)]),...(literals.incomplete ? [incompletePlistNumberLimitation] : []),...numberLimitations(exactIntegerCount, ambiguousNumberCount),...prototypeKeyLimitations(omittedPrototypeKeys),diff --git a/tests/acceptance/applications/interfaceBuilderPlistNumbers.test.ts b/tests/acceptance/applications/interfaceBuilderPlistNumbers.test.tsindex b8e839597..be23ba248 100644--- a/tests/acceptance/applications/interfaceBuilderPlistNumbers.test.ts+++ b/tests/acceptance/applications/interfaceBuilderPlistNumbers.test.ts@@ -11,6 +11,13 @@ import { parseEvidence } from "../../../src/domain/evidence.js";import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";import { cliTest } from "../../support/cli/cliFixture.js";+const unknownMixedInteger = {+ $plist_type: "unknown",+ element: "integer",+ literal: "9007199254740992<!-- split -->3",+ reason: "unsupported-markup",+};+const scenarios = ["XML","binary",@@ -131,7 +138,9 @@ cliTest.for(scenarios)(scenario === "hexadecimal" ||scenario === "segmented keys"? { $plist_type: "integer", decimal: "9007199254740993" }- : 9007199254740992,+ : scenario === "mixed XML"+ ? unknownMixedInteger+ : 9007199254740992,safe: 42,children: [{ archiveUID: 2, className: "UIView" }],interface_builder_object_id: "1",@@ -155,18 +164,20 @@ cliTest.for(scenarios)(expect(result.limitations).toContainEqual(expect.stringContaining("1 unambiguous integer value"),);- else if (scenario !== "real" && scenario !== "CDATA real")+ else if (scenario.includes("collision"))expect(result.limitations).toContainEqual(expect.stringContaining("integer precision loss remains possible"),);+ else if (scenario === "mixed XML")+ expect(result.limitations).toContainEqual(+ expect.stringContaining(+ "1 XML scalar value(s) could not be established",+ ),+ );elseexpect(result.limitations.some((note) => note.includes("integer precision")),).toBe(false);- if (scenario === "mixed XML")- expect(result.limitations).toContainEqual(- expect.stringContaining("could not be completely observed"),- );expect(result.graph.truncated).toBe(false);},);diff --git a/tests/acceptance/applications/keyedArchiveXmlScalars.test.ts b/tests/acceptance/applications/keyedArchiveXmlScalars.test.tsnew file mode 100644index 000000000..301bfb158--- /dev/null+++ b/tests/acceptance/applications/keyedArchiveXmlScalars.test.ts@@ -0,0 +1,110 @@+import { createHash } from "node:crypto";+import { readFile, writeFile } from "node:fs/promises";+import { join } from "node:path";++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 { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";+import { cliTest } from "../../support/cli/cliFixture.js";++cliTest(+ "preserves malformed XML scalars as explicit unknowns through CLI and MCP",+ async ({ cli }) => {+ const root = await createTestTempDirectory("rea-keyed-xml-scalars-");+ const invalid = [+ ["integer", " 42 "],+ ["integer", "42abc"],+ ["integer", "\u202f42"],+ ["integer", "4.2"],+ ["integer", "1e3"],+ ["integer", "42"],+ ["integer", "4<!-- </integer> -->2"],+ ["integer", "<![CDATA[42]]>"],+ ["real", " 1.5 "],+ ["real", "1.5abc"],+ ["real", "1,5"],+ ["real", "\u202f1.5"],+ ["real", "\u205f1.5"],+ ["real", "0x1p3"],+ ["real", '1<real note=">">2</real>.5'],+ ["date", "2026-10-17T12:00:00+02:00"],+ ["date", "2026-10-17T12:00:00.5Z"],+ ["date", "2026-10-17T12:00:00"],+ ["true", "x"],+ ["false", " "],+ ] as const;+ const controls =+ "<integer>+ 42</integer><real>1<![CDATA[.5]]></real><date>2026-10-17T12:00:00Z</date><true/><false></false><integer>9007199254740993</integer>";+ const bytes = Buffer.from(+ `<?xml version="1.0"?><plist><dict><key>$archiver</key><string>NSKeyedArchiver</string><key>$version</key><integer>100000</integer><key>$objects</key><array><string>$null</string>${invalid.map(([tag, literal]) => `<${tag}>${literal}</${tag}>`).join("")}${controls}</array><key>$top</key><dict><key>root</key><dict><key>CF$UID</key><integer>1</integer></dict></dict></dict></plist>`,+ );+ const path = join(root, "archive.plist");+ await writeFile(path, bytes);+ const digest = createHash("sha256").update(bytes).digest("hex");+ const run = async (TZ: string) => {+ const output = await cli.run({+ arguments: ["inspect-keyed-archive", path, "--json"],+ environment: {+ HOME: root,+ USERPROFILE: root,+ TZ,+ REA_LOG_LEVEL: "silent",+ },+ });+ expect(output.exitCode, output.stderr).toBe(0);+ return keyedArchiveResultSchema.parse(+ parseEvidence(output.json).normalized_result,+ );+ };+ const result = await run("UTC");+ expect(await run("Etc/GMT-2")).toEqual(result);+ expect(result.archive_sha256).toBe(digest);+ expect(+ result.objects+ .slice(1, invalid.length + 1)+ .map(({ kind, value }) => ({ kind, value })),+ ).toEqual(+ invalid.map(([element, literal]) => ({+ kind: "scalar",+ value: {+ $plist_type: "unknown",+ element,+ literal,+ reason: literal.includes("<")+ ? "unsupported-markup"+ : "invalid-literal",+ },+ })),+ );+ expect(+ result.objects.slice(invalid.length + 1).map(({ value }) => value),+ ).toEqual([+ 42,+ 1.5,+ { $plist_type: "date", iso8601: "2026-10-17T12:00:00.000Z" },+ true,+ false,+ { $plist_type: "integer", decimal: "9007199254740993" },+ ]);+ expect(result.limitations).toContainEqual(+ expect.stringContaining(`${String(invalid.length)} XML scalar value(s)`),+ );+ expect(result.references).toHaveLength(1);+ const { call } = await connectLocalToolsMcp({+ HOME: root,+ USERPROFILE: root,+ });+ expect((await call("open_binary", { path })).isError).not.toBe(true);+ const reply = await call("inspect_keyed_archive", {});+ expect(reply.isError, JSON.stringify(reply)).not.toBe(true);+ expect(+ keyedArchiveResultSchema.parse(+ parseEvidence(reply.structuredContent).normalized_result,+ ),+ ).toEqual(result);+ expect(await readFile(path)).toEqual(bytes);+ },+);diff --git a/tests/boundary/cli/nativePlistCli.test.ts b/tests/boundary/cli/nativePlistCli.test.tsindex 88952029a..3c6f69dff 100644--- a/tests/boundary/cli/nativePlistCli.test.ts+++ b/tests/boundary/cli/nativePlistCli.test.ts@@ -229,7 +229,7 @@ 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.+ // Parse the unsigned extended year as a UTC field, without JS string-date inference."<key>Far</key><date>11507-08-17T05:20:00Z</date>","<key>Ratio</key><real>nan</real>","<key>Nested</key><array><dict>",@@ -265,7 +265,10 @@ describe.skipIf(process.platform !== "darwin")($plist_type: "date",iso8601: "2020-01-01T00:00:00.000Z",},- Far: { $plist_type: "date", iso8601: null },+ Far: {+ $plist_type: "date",+ iso8601: "+011507-08-17T05:20:00.000Z",+ },Ratio: { $plist_type: "real", value: "nan" },Nested: [{@@ -284,7 +287,6 @@ describe.skipIf(process.platform !== "darwin")(limitations: [expect.stringContaining("XML conversion"),expect.stringContaining("2 non-finite real"),- expect.stringContaining("1 date value(s)"),],},});