Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(apple): keep Interface Builder objects whose archived class is unresolved (#4118)

Kaoru0822a90c9eac6a43
diff --git a/src/domain/apple/interfaceBuilderGraph.test.ts b/src/domain/apple/interfaceBuilderGraph.test.ts
index 84a8ea493..cffcd8db9 100644
--- a/src/domain/apple/interfaceBuilderGraph.test.ts
+++ b/src/domain/apple/interfaceBuilderGraph.test.ts
@@ -156,6 +156,90 @@ describe("compiled Interface Builder graph projection", () => {
});
});
+describe("keyed archive objects with unresolved classes", () => {
+ it("keeps an archived object whose class reference cannot be resolved", () => {
+ const parsed = parseInterfaceBuilderRecords({
+ $archiver: "NSKeyedArchiver",
+ $version: 100000,
+ $objects: [
+ "$null",
+ { $class: { UID: 99 }, label: "Unresolved object" },
+ { $classname: "UIView", $classes: ["UIView", "NSObject"] },
+ { $class: { UID: 2 }, "NS.string": "ok" },
+ "plain scalar",
+ ],
+ $top: { root: { UID: 3 } },
+ });
+ // The class descriptor and the scalar are not archived objects.
+ expect(parsed.objects).toMatchObject([
+ {
+ id: "1",
+ kind: "other",
+ class_name: null,
+ name: "Unresolved object",
+ attributes: { label: "Unresolved object", $class: { UID: 99 } },
+ },
+ { id: "3", kind: "view", class_name: "UIView" },
+ ]);
+ expect(parsed.objects[1]?.attributes).not.toHaveProperty("$class");
+ expect(parsed.objectCount).toBe(2);
+ });
+
+ it("keeps an unresolved hierarchy root's label and coverage in the graph", () => {
+ const result = buildInterfaceBuilderAnalysis({
+ targetSha256: hash,
+ toolVersion: "test",
+ documents: [
+ {
+ relativePath: "Main.nib",
+ archiveSha256: hash,
+ documentKind: "nib",
+ raw: {
+ $archiver: "NSKeyedArchiver",
+ $version: 100000,
+ $objects: [
+ "$null",
+ { $class: { UID: 99 }, label: "Unresolved object" },
+ { $classname: "UIView", $classes: ["UIView", "NSObject"] },
+ { $class: { UID: 2 }, "NS.string": "ok" },
+ ],
+ $top: { root: { UID: 1 } },
+ },
+ },
+ ],
+ limits: interfaceBuilderLimitsSchema.parse({}),
+ });
+ const objectNodes = result.graph.nodes.filter(
+ ({ attributes }) => attributes.interface_builder_object_id !== undefined,
+ );
+ expect(objectNodes).toMatchObject([
+ {
+ kind: "unknown",
+ name: "Unresolved object",
+ attributes: { interface_builder_object_id: "1", class_name: null },
+ },
+ { kind: "view", attributes: { interface_builder_object_id: "3" } },
+ ]);
+ expect(result.documents[0]?.object_count).toBe(2);
+ expect(
+ result.graph.edges.some(
+ ({ relation, to, resolution }) =>
+ relation === "contains" &&
+ to === objectNodes[0]?.id &&
+ resolution === "observed",
+ ),
+ ).toBe(true);
+ expect(result.graph.coverage).toContainEqual(
+ expect.objectContaining({
+ facet: "objects:Main.nib",
+ status: "complete",
+ examined: 2,
+ omitted: 0,
+ }),
+ );
+ });
+});
+
describe("Interface Builder parser bounds", () => {
it("reports connections discarded by the parser's hard ceiling", () => {
const connections = Array.from({ length: 40_001 }, (_, index) => ({
diff --git a/src/domain/apple/interfaceBuilderKeyedArchive.ts b/src/domain/apple/interfaceBuilderKeyedArchive.ts
index 3c0e97749..e6145a0d2 100644
--- a/src/domain/apple/interfaceBuilderKeyedArchive.ts
+++ b/src/domain/apple/interfaceBuilderKeyedArchive.ts
@@ -327,11 +327,16 @@ const parseKeyedArchive = (
if (index === 0) continue;
const resolved = record(resolve(raw));
const className = firstString(resolved.className);
- if (className === null) continue;
+ // An archived object names its class with its own `$class` reference;
+ // when that reference cannot be resolved the object is still observed,
+ // with an unknown class. Scalars and class descriptors are not objects.
+ if (className === null && !Object.hasOwn(record(raw), "$class")) continue;
objectCount += 1;
const fields = Object.fromEntries(
Object.entries(resolved).filter(([key]) => key !== "className"),
);
+ // Keep the unresolvable class reference itself, e.g. a dangling UID.
+ if (className === null) fields.$class = record(raw).$class;
const authoredId = firstString(fields.objectID, fields["object-id"]);
const objectId =
authoredId ??
@@ -357,6 +362,7 @@ const parseKeyedArchive = (
}),
);
if (
+ className !== null &&
/(?:Outlet|Connection|Segue|ActionConnection|ControlConnector)/iu.test(
className,
)