test(il2cpp): consolidate section geometry and prefix checks (#12863)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 10:22:15 -05:00
1 parent 75fe508eb4
commit 7e2e4d41f5
2 files changed
+54 -87

No files matched your search

+53 -58
View File
@@ -496,70 +496,65 @@ cliTest(
const root = await createTestTempDirectory("rea-il2cpp-prefix-fail-");
const { client, call } = await connectLocalToolsMcp();
for (const length of [4, 5, 6, 7]) {
const path = join(root, `magic-${length}.dat`);
const bytes = Buffer.alloc(length);
bytes.writeUInt32LE(0xfab11baf, 0);
await writeFile(path, bytes);
const path = join(root, "incomplete-version.dat");
const bytes = Buffer.from([0xaf, 0x1b, 0xb1, 0xfa, 37, 0, 0]);
await writeFile(path, bytes);
const expected = {
code: "invalid_request",
details: {
operation: "inspect_il2cpp_metadata",
issues: [
{
path: ["path"],
reason: "invalid_format",
message: expect.stringContaining(
"truncated-header: the file has",
),
},
],
partial_observation: {
normalized_result: {
artifact: {
path,
bytes: length,
sha256: createHash("sha256").update(bytes).digest("hex"),
},
inventory_status: "not-returned-as-complete",
const expected = {
code: "invalid_request",
details: {
operation: "inspect_il2cpp_metadata",
issues: [
{
path: ["path"],
reason: "invalid_format",
message: expect.stringContaining("truncated-header"),
},
],
partial_observation: {
normalized_result: {
artifact: {
path,
bytes: bytes.length,
sha256: createHash("sha256").update(bytes).digest("hex"),
},
inventory_status: "not-returned-as-complete",
},
},
};
const result = await cli.run({
arguments: ["inspect-il2cpp-metadata", path, "--json"],
});
expect(result.exitCode).toBe(1);
expect(result.json).toMatchObject(expected);
},
};
const result = await cli.run({
arguments: ["inspect-il2cpp-metadata", path, "--json"],
});
expect(result.exitCode).toBe(1);
expect(result.json).toMatchObject(expected);
const response = await call("inspect_il2cpp_metadata", { path });
const projected = parseMcpToolError(response).error;
expect(projected).toMatchObject({
...expected,
details: {
...expected.details,
partial_observation: {
kind: "retained-evidence",
evidence_id: expect.any(String),
},
const response = await call("inspect_il2cpp_metadata", { path });
const projected = parseMcpToolError(response).error;
expect(projected).toMatchObject({
...expected,
details: {
...expected.details,
partial_observation: {
kind: "retained-evidence",
evidence_id: expect.any(String),
},
});
const reference = projected.details?.partial_observation as {
evidence_id: string;
};
const bundle = parseEvidenceBundle(
toolContract("get_evidence_bundle").outputSchema.parse(
(await call("get_evidence_bundle", { detail: "complete" }))
.structuredContent,
).result,
);
expect(
bundle.records.find(
({ evidence_id }) => evidence_id === reference.evidence_id,
),
).toMatchObject(expected.details.partial_observation);
}
},
});
const reference = projected.details?.partial_observation as {
evidence_id: string;
};
const bundle = parseEvidenceBundle(
toolContract("get_evidence_bundle").outputSchema.parse(
(await call("get_evidence_bundle", { detail: "complete" }))
.structuredContent,
).result,
);
expect(
bundle.records.find(
({ evidence_id }) => evidence_id === reference.evidence_id,
),
).toMatchObject(expected.details.partial_observation);
await client.ping();
},
);
@@ -155,18 +155,13 @@ describe("IL2CPP global-metadata version 39", () => {
},
);
it("accepts empty sections that share an offset with occupied sections and padding gaps", () => {
it("accepts an empty section whose offset is inside an occupied section", () => {
const bytes = mutated((fixture, target) => {
const methods = fixture.section("methods");
target.writeInt32LE(
methods.offset + 3,
fixture.header("windowsRuntimeStrings", "offset"),
);
// Grow strings into trailing padding that no other section occupies.
target.writeInt32LE(
fixture.section("strings").size,
fixture.header("strings", "size"),
);
});
expect(readIl2cppMetadata(bytes).types).toEqual(FIXTURE_TYPES);
});
@@ -501,29 +496,6 @@ describe("rejected IL2CPP metadata references", () => {
);
});
it("rejects a string section overlapping literal data", () => {
rejects(
mutated((fixture, bytes) => {
bytes.writeInt32LE(
fixture.section("strings").offset - 1,
fixture.header("strings", "offset"),
);
}),
"section-overlap",
);
});
it("decodes a valid string suffix from its byte offset", () => {
const fixture = createIl2cppMetadataFixture({
typeNames: { 0: "xPlayer" },
});
const bytes = Buffer.from(fixture.bytes);
const originalOffset = fixture.record("typeDefinitions", 0);
bytes.writeInt32LE(bytes.readInt32LE(originalOffset) + 1, originalOffset);
expect(readIl2cppMetadata(bytes).types[0]?.name).toBe("Player");
});
it("accepts a UTF-8 code-point boundary suffix and rejects a split code point", () => {
const fixture = createIl2cppMetadataFixture({
typeNames: { 0: "xéclair" },