Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(plist): ignore processing instructions between container members

morlutofd728f271e7d
diff --git a/src/application/AppBundleExecutable.test.ts b/src/application/AppBundleExecutable.test.ts
index d32e6bdd2..d7ee19830 100644
--- a/src/application/AppBundleExecutable.test.ts
+++ b/src/application/AppBundleExecutable.test.ts
@@ -4,8 +4,35 @@ import { join } from "node:path";
import { describe, expect, it } from "vitest";
+import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import { resolveAppBundleExecutable } from "./AppBundleExecutable.js";
+it.each([
+ ["macOS", ["Contents"], ["Contents", "MacOS"]],
+ ["iOS", [], []],
+] as const)(
+ "resolves the %s bundle layout when Info.plist contains processing instructions",
+ async (_kind, plistDirectory, programDirectory) => {
+ const root = await createTestTempDirectory("rea-app-plist-pi-");
+ const bundle = join(root, "Fixture.app");
+ const plistPath = join(bundle, ...plistDirectory, "Info.plist");
+ const executable = join(bundle, ...programDirectory, "Fixture");
+ await mkdir(join(bundle, ...plistDirectory), { recursive: true });
+ await mkdir(join(bundle, ...programDirectory), { recursive: true });
+ await writeFile(
+ plistPath,
+ '<plist version="1.0"><?rea ignored?><dict><?rea ignored?><key>CFBundleExecutable</key><?rea ignored?><string>Fixture</string><?rea ignored?></dict><?rea ignored?></plist>',
+ );
+ await writeFile(executable, "inert fixture; never executed");
+
+ const result = await resolveAppBundleExecutable(bundle);
+ expect(result).toEqual({
+ ok: true,
+ value: { executable, infoPlist: plistPath },
+ });
+ },
+);
+
describe("app bundle Info.plist magic", () => {
it("does not decode a high-bit fold of bplist as a binary Info.plist", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-bplist-fold-"));
diff --git a/src/domain/propertyListXml.test.ts b/src/domain/propertyListXml.test.ts
index 5fb361563..845211dbb 100644
--- a/src/domain/propertyListXml.test.ts
+++ b/src/domain/propertyListXml.test.ts
@@ -4,6 +4,74 @@ import { projectPlistValue } from "./apple/plistValue.js";
import { UnknownPlistReal } from "./apple/plistNumbers.js";
import { parseXmlPropertyList } from "./propertyListKeys.js";
+it.each([
+ [
+ "plist",
+ "<plist><?dict ignored?><string>demo</string><?rea ignored?></plist>",
+ "demo",
+ ],
+ [
+ "array",
+ "<plist><array><?rea ignored?><string>before</string><?integer 9007199254740993?><integer>42</integer><?rea ignored?></array></plist>",
+ ["before", 42],
+ ],
+ [
+ "dict",
+ "<plist><dict><?key ignored?><key>name</key><?string ignored?><string>demo</string><?rea ignored?><key>count</key><integer>42</integer><?rea ignored?></dict></plist>",
+ { name: "demo", count: 42 },
+ ],
+] as const)(
+ "ignores processing instructions between %s members",
+ (_kind, xml, value) => {
+ const parsed = parseXmlPropertyList(xml);
+ expect(parsed.value).toEqual(value);
+ expect(parsed.numberLiterals.incomplete).toBe(false);
+ expect(parsed.numberLiterals.unsafeIntegerLiterals).toBe(0);
+ },
+);
+
+it("keeps document-level processing instructions outside plist members", () => {
+ const parsed = parseXmlPropertyList(
+ '<?xml version="1.0"?><?rea before?><plist><string>demo</string></plist><?rea after?>',
+ );
+ expect(parsed.value).toBe("demo");
+ expect(parsed.numberLiterals.incomplete).toBe(false);
+});
+
+it.each([
+ ["CDATA", "<![CDATA[before<?rea content?>after]]>"],
+ ["escaped text", "before&lt;?rea content?&gt;after"],
+])(
+ "preserves literal processing-instruction text from %s",
+ (_kind, content) => {
+ expect(
+ parseXmlPropertyList(`<plist><string>${content}</string></plist>`).value,
+ ).toBe("before<?rea content?>after");
+ },
+);
+
+it("keeps processing instructions inside numeric content subject to scalar rules", () => {
+ for (const markup of ["<?rea ignored?>", "<!-- ignored -->"]) {
+ const parsed = parseXmlPropertyList(
+ `<plist><integer>4${markup}2</integer></plist>`,
+ );
+ expect(parsed.value).toBe(4);
+ expect(parsed.numberLiterals.incomplete).toBe(true);
+ }
+});
+
+it("still rejects an unterminated processing instruction", () => {
+ expect(() =>
+ parseXmlPropertyList("<plist><?rea ignored<string>demo</string></plist>"),
+ ).toThrow();
+});
+
+it("still rejects an unsupported element beside a processing instruction", () => {
+ expect(() =>
+ parseXmlPropertyList("<plist><?rea ignored?><unsupported/></plist>"),
+ ).toThrow("Invalid PLIST tag unsupported");
+});
+
it.each([
["0x2A", 42],
["0X2a", 42],
diff --git a/src/domain/propertyListXml.ts b/src/domain/propertyListXml.ts
index f7e123b9c..62db805a3 100644
--- a/src/domain/propertyListXml.ts
+++ b/src/domain/propertyListXml.ts
@@ -45,7 +45,8 @@ export const decodeXmlPropertyList = (document: Document) => {
if (
child.nodeType !== child.TEXT_NODE &&
child.nodeType !== child.CDATA_SECTION_NODE &&
- child.nodeType !== child.COMMENT_NODE
+ child.nodeType !== child.COMMENT_NODE &&
+ child.nodeType !== child.PROCESSING_INSTRUCTION_NODE
)
yield child;
};
diff --git a/tests/acceptance/applications/keyedArchiveXmlNumbers.test.ts b/tests/acceptance/applications/keyedArchiveXmlNumbers.test.ts
index c53ffa252..1a1d501f0 100644
--- a/tests/acceptance/applications/keyedArchiveXmlNumbers.test.ts
+++ b/tests/acceptance/applications/keyedArchiveXmlNumbers.test.ts
@@ -24,6 +24,11 @@ cliTest.for([
expected: 1.25,
},
{ name: "hexadecimal", element: "<integer>0x2A</integer>", expected: 42 },
+ {
+ name: "integer between processing instructions",
+ element: "<?integer 9007199254740993?><integer>42</integer><?rea ignored?>",
+ expected: 42,
+ },
{
name: "unsafe hexadecimal",
element: "<integer>0x20000000000001</integer>",