mirror of
https://github.com/morluto/rea.git
synced 2026-10-31 20:06:14 +00:00
fix(il2cpp): preserve recognized truncated metadata prefixes
This commit is contained in:
1 parent
eb7acc70bf
commit
b3aadaf474
10 files changed
+273
-25
No files matched your search
@@ -7,6 +7,7 @@ import {
|
||||
il2cppIndexWidth,
|
||||
il2cppMetadataRecordBytes,
|
||||
readIl2cppMetadata,
|
||||
readIl2cppMetadataForLinking,
|
||||
readIl2cppMetadataSteps,
|
||||
} from "../../../src/il2cpp/Il2cppMetadataFile.js";
|
||||
import {
|
||||
@@ -24,9 +25,14 @@ import {
|
||||
type Il2cppMetadataFixture,
|
||||
} from "../../fixtures/il2cpp/metadata.js";
|
||||
|
||||
const failure = (bytes: Buffer) => {
|
||||
const failure = (
|
||||
bytes: Buffer,
|
||||
reader:
|
||||
| typeof readIl2cppMetadata
|
||||
| typeof readIl2cppMetadataForLinking = readIl2cppMetadata,
|
||||
) => {
|
||||
try {
|
||||
readIl2cppMetadata(bytes);
|
||||
reader(bytes);
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof Il2cppMetadataFormatFailure) return cause;
|
||||
throw cause;
|
||||
@@ -161,7 +167,8 @@ describe("rejected IL2CPP global-metadata", () => {
|
||||
"unrecognized-magic",
|
||||
"unsupported",
|
||||
);
|
||||
rejects(Buffer.alloc(4), "unrecognized-magic", "unsupported");
|
||||
for (const length of [4, 5, 6, 7])
|
||||
rejects(Buffer.alloc(length), "unrecognized-magic", "unsupported");
|
||||
rejects(
|
||||
mutated((_, bytes) => bytes.writeInt32LE(30, 4)),
|
||||
"unsupported-version",
|
||||
@@ -169,6 +176,40 @@ describe("rejected IL2CPP global-metadata", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("retains the decoder's signed interpretation of a complete high-bit version", () => {
|
||||
const bytes = Buffer.alloc(8);
|
||||
bytes.writeUInt32LE(0xfab11baf, 0);
|
||||
bytes.writeUInt32LE(0xffffffff, 4);
|
||||
const rejected = failure(bytes);
|
||||
expect(rejected.reason).toBe("unsupported-version");
|
||||
expect(rejected.kind).toBe("unsupported");
|
||||
expect(rejected.message).toContain("metadata version -1 is not supported");
|
||||
});
|
||||
|
||||
it.each([4, 5, 6, 7])(
|
||||
"retains recognized magic and reports a %i-byte version prefix as truncated",
|
||||
(length) => {
|
||||
const bytes = Buffer.alloc(length);
|
||||
bytes.writeUInt32LE(0xfab11baf, 0);
|
||||
const rejected = failure(bytes);
|
||||
expect(rejected.reason).toBe("truncated-header");
|
||||
expect(rejected.kind).toBe("corrupt");
|
||||
expect(rejected.message).toContain(
|
||||
"fewer than the 8-byte magic/version prefix",
|
||||
);
|
||||
expect(rejected.message).toContain("metadata version is unknown");
|
||||
},
|
||||
);
|
||||
|
||||
it("uses the same truncated-prefix classification before native linking", () => {
|
||||
const bytes = Buffer.alloc(7);
|
||||
bytes.writeUInt32LE(0xfab11baf, 0);
|
||||
const rejected = failure(bytes, readIl2cppMetadataForLinking);
|
||||
expect(rejected.reason).toBe("truncated-header");
|
||||
expect(rejected.kind).toBe("corrupt");
|
||||
expect(rejected.message).toContain("metadata version is unknown");
|
||||
});
|
||||
|
||||
it("rejects a truncated header and an unexpected header size", () => {
|
||||
rejects(
|
||||
createIl2cppMetadataFixture().bytes.subarray(0, 200),
|
||||
|
||||
@@ -352,6 +352,41 @@ it("retains the exact empty source observation without claiming a decoded invent
|
||||
});
|
||||
});
|
||||
|
||||
it("retains the exact source when recognized magic has no complete version", async () => {
|
||||
const root = await createTestTempDirectory("rea-il2cpp-short-prefix-");
|
||||
const path = join(root, "global-metadata.dat");
|
||||
const bytes = Buffer.alloc(7);
|
||||
bytes.writeUInt32LE(0xfab11baf, 0);
|
||||
await writeFile(path, bytes);
|
||||
const result = await inspectMetadata(path);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("Expected truncated metadata prefix");
|
||||
expect(result.error).toMatchObject({
|
||||
_tag: "AnalysisInputError",
|
||||
issues: [
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_format",
|
||||
message: expect.stringMatching(
|
||||
/truncated-header:.*metadata version is unknown/u,
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(result.error.partialObservation).toMatchObject({
|
||||
operation: "observe_il2cpp_metadata_source",
|
||||
normalized_result: {
|
||||
artifact: {
|
||||
path,
|
||||
bytes: bytes.length,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
},
|
||||
inventory_status: "not-returned-as-complete",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the metadata source observation when the selected binary does not link", async () => {
|
||||
const root = await createTestTempDirectory("rea-il2cpp-binary-failure-");
|
||||
const path = join(root, "global-metadata.dat");
|
||||
|
||||
Reference in new issue
Block a user