fix(il2cpp): preserve loader ownership and ABI field boundaries

Resolve pointer and scalar facts through their shared loader-aware owners before registration search or type rendering. Preserve unresolved names and attributes, read count fields at their declared width, and admit declared zero-fill registration tails without accepting unmapped bytes.

Cover relocation overlap and adjacency, loader-bound fields, ABI padding, nullable names, and CLI/MCP behavior; document format and verification limits.

Fixes #6881
Fixes #6873
Fixes #6871
This commit is contained in:
morluto
2026-10-24 04:28:05 +08:00
parent f2db494bfc
commit 52ca222bd0
14 changed files with 420 additions and 59 deletions
@@ -1,4 +1,8 @@
import { Il2cppBinaryFormatFailure } from "../../../src/il2cpp/Il2cppBinaryFormat.js";
import {
openImageSteps,
readUInt32,
} from "../../../src/il2cpp/Il2cppBinaryImage.js";
import { expect, it } from "vitest";
import {
linkIl2cppBinary,
@@ -9,6 +13,7 @@ import {
createElfFixture,
createIl2cppBinaryFixture,
createIl2cppDyldBindFixture,
createIl2cppRegistrationTailFixture,
createUniversalFixture,
createSplitPointerPeFixture,
FIXTURE_BINARY_BASE,
@@ -593,6 +598,71 @@ it("keeps unbound Mach-O method words classified from their values", () => {
expect(linked.method_addresses[1]).toEqual(expectedAddresses[1]);
expect(linked.method_addresses[4]).toEqual(expectedAddress("no-body"));
});
it("refuses an unresolved inner type value instead of rendering its stored placeholder", () => {
expect(
failure(createIl2cppDyldBindFixture(FIXTURE_BINARY_BASE + 0x990n, 0x980)),
).toEqual({
reason: "unsupported-pointer-encoding",
kind: "unsupported",
});
});
it.each([
[0x600, 2n, "code-registration-not-found"],
[0x408, 3n, "code-gen-modules-not-found"],
[0x850, 4n, "metadata-registration-not-found"],
[0x860, 4n, "metadata-registration-not-found"],
[0x988, 0x001d0000n, "unsupported-pointer-encoding"],
] as const)("does not trust a dyld-owned scalar at %s", (slot, raw, reason) => {
expect(failure(createIl2cppDyldBindFixture(raw, slot)).reason).toBe(reason);
});
it.each([
[0x5f8, 0n, 2],
[0x5fc, 2n << 32n, "unknown"],
[0x600, 2n, "unknown"],
[0x604, 0n, 2],
] as const)(
"uses the four-byte count span for a dyld bind at %s",
(slot, raw, expected) => {
const steps = openImageSteps(
createIl2cppDyldBindFixture(raw, slot),
undefined,
);
let step = steps.next();
while (!step.done) step = steps.next();
expect(readUInt32(step.value, FIXTURE_BINARY_BASE + 0x600n)).toBe(expected);
},
);
it.each([
[0x400, "code-gen-modules-not-found"],
[0x410, "code-gen-modules-not-found"],
[0x500, "code-registration-not-found"],
[0x608, "code-registration-not-found"],
[0x838, "metadata-registration-not-found"],
] as const)(
"does not nominate a registration from dyld-owned word at %s",
(slot, reason) => {
const raw = createIl2cppBinaryFixture().readBigUInt64LE(slot);
expect(failure(createIl2cppDyldBindFixture(raw, slot)).reason).toBe(reason);
},
);
it.each([1, 0xff])(
"ignores ABI count padding byte %d without accepting a changed count",
(padding) => {
const bytes = createIl2cppBinaryFixture();
bytes.fill(padding, 0x604, 0x608);
expect(link(bytes)).toEqual(link(createIl2cppBinaryFixture()));
bytes.writeUInt32LE(3, 0x600);
expect(failure(bytes).reason).toBe("code-registration-not-found");
},
);
it.each([8, 16] as const)(
"rejects %d absent registration bytes without declared zero-fill",
(tailBytes) => {
expect(
failure(createIl2cppRegistrationTailFixture(tailBytes, false)).reason,
).toBe("metadata-registration-not-found");
},
);
it.each([
["PC32", 2],