Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(native): decode the Objective-C word-alignment sentinel

morluto74afb04f3289
diff --git a/src/native/AppleDispatchMetadata.test.ts b/src/native/AppleDispatchMetadata.test.ts
index f715c3c4e..4509e2373 100644
--- a/src/native/AppleDispatchMetadata.test.ts
+++ b/src/native/AppleDispatchMetadata.test.ts
@@ -323,6 +323,19 @@ describe("Apple dispatch binary metadata", () => {
});
},
);
+
+ it.each([
+ [0xffffffff, 8],
+ [3, 8],
+ [0xfffffffe, null],
+ ])("decodes ivar alignment raw value %i as %s", (raw, alignment) => {
+ const bytes = fixture();
+ bytes.writeUInt32LE(raw, 0x520);
+ const result = decodeAppleDispatchMetadata(bytes, 100, provenance);
+ expect(result.objc_ivars).toMatchObject([
+ { name: "state", alignment, decode: { status: "decoded" } },
+ ]);
+ });
});
describe("Apple dispatch coverage ownership", () => {
diff --git a/src/native/AppleObjcDispatchFacets.ts b/src/native/AppleObjcDispatchFacets.ts
index 955fb956e..21cda550f 100644
--- a/src/native/AppleObjcDispatchFacets.ts
+++ b/src/native/AppleObjcDispatchFacets.ts
@@ -292,14 +292,20 @@ export const decodeObjcDispatchFacets = (input: {
void cause;
failures.push(`Unresolved ivar offset pointer ${hex(encodedOffset)}`);
}
+ const alignment = read.u32(entry + 24n);
result.objc_ivars.push({
class_name: name,
name: read.string(read.pointer(entry + 8n)),
type_encoding: read.string(read.pointer(entry + 16n)),
offset: value,
size: read.u32(entry + 28n),
+ // objc4 ivar_t::alignment(): ~0 means word alignment (8 for 32-byte entries).
alignment:
- read.u32(entry + 24n) < 31 ? 2 ** read.u32(entry + 24n) : null,
+ alignment === 0xffffffff
+ ? 8
+ : alignment < 31
+ ? 2 ** alignment
+ : null,
location: read.location(entry),
decode:
value === null