mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
test(il2cpp): share metadata fixture refusal setup (#15959)
This commit is contained in:
1 parent
e59e558993
commit
3f33f1411a
1 file changed
+75
-142
@@ -63,6 +63,11 @@ const mutated = (
|
||||
return bytes;
|
||||
};
|
||||
|
||||
const rejectEdited = (
|
||||
reason: Il2cppMetadataFailureReason,
|
||||
edit: Parameters<typeof mutated>[0],
|
||||
) => rejects(mutated(edit), reason);
|
||||
|
||||
describe("IL2CPP global-metadata version 39", () => {
|
||||
it("yields through a large owner range before emitting its first parameter fact", () => {
|
||||
const fixture = createIl2cppMetadataFixture({
|
||||
@@ -92,17 +97,11 @@ describe("IL2CPP global-metadata version 39", () => {
|
||||
it.each([-1, 0x7fffffff])(
|
||||
"rejects an invalid empty-literal sentinel %i",
|
||||
(sentinel) => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) => {
|
||||
bytes.writeInt32LE(4, fixture.header("stringLiterals", "size"));
|
||||
bytes.writeInt32LE(1, fixture.header("stringLiterals", "count"));
|
||||
bytes.writeInt32LE(
|
||||
sentinel,
|
||||
fixture.section("stringLiterals").offset,
|
||||
);
|
||||
}),
|
||||
"index-out-of-range",
|
||||
);
|
||||
rejectEdited("index-out-of-range", (fixture, bytes) => {
|
||||
bytes.writeInt32LE(4, fixture.header("stringLiterals", "size"));
|
||||
bytes.writeInt32LE(1, fixture.header("stringLiterals", "count"));
|
||||
bytes.writeInt32LE(sentinel, fixture.section("stringLiterals").offset);
|
||||
});
|
||||
},
|
||||
);
|
||||
it.each([1, 2, 4] as const)(
|
||||
@@ -246,63 +245,42 @@ describe("rejected IL2CPP global-metadata", () => {
|
||||
"truncated-header",
|
||||
"truncated",
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(384, fixture.header("stringLiterals", "offset")),
|
||||
),
|
||||
"unexpected-header-size",
|
||||
rejectEdited("unexpected-header-size", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(384, fixture.header("stringLiterals", "offset")),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects sections outside the file or with negative fields", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(bytes.length, fixture.header("methods", "size")),
|
||||
),
|
||||
"section-out-of-bounds",
|
||||
rejectEdited("section-out-of-bounds", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(bytes.length, fixture.header("methods", "size")),
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(-1, fixture.header("events", "count")),
|
||||
),
|
||||
"section-out-of-bounds",
|
||||
rejectEdited("section-out-of-bounds", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(-1, fixture.header("events", "count")),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects overlapping occupied sections", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("typeDefinitions").offset + 4,
|
||||
fixture.header("images", "offset"),
|
||||
),
|
||||
rejectEdited("section-overlap", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("typeDefinitions").offset + 4,
|
||||
fixture.header("images", "offset"),
|
||||
),
|
||||
"section-overlap",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects record sizes that disagree with counts or index widths", () => {
|
||||
// Not a whole multiple of the record count.
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("methods").count! + 1,
|
||||
fixture.header("methods", "count"),
|
||||
),
|
||||
rejectEdited("record-size-mismatch", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("methods").count! + 1,
|
||||
fixture.header("methods", "count"),
|
||||
),
|
||||
"record-size-mismatch",
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(2, fixture.header("nestedTypes", "count")),
|
||||
),
|
||||
"record-size-mismatch",
|
||||
rejectEdited("record-size-mismatch", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(2, fixture.header("nestedTypes", "count")),
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(0, fixture.header("methods", "count")),
|
||||
),
|
||||
"record-size-mismatch",
|
||||
rejectEdited("record-size-mismatch", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(0, fixture.header("methods", "count")),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -452,70 +430,46 @@ it.each(["interfaceOffsets", "typeDefinitions"] as const)(
|
||||
|
||||
describe("rejected IL2CPP metadata references", () => {
|
||||
it("rejects image, type, method and nested-type indices outside their tables", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeUInt32LE(9, fixture.record("images", 1) + 9),
|
||||
),
|
||||
"index-out-of-range",
|
||||
rejectEdited("index-out-of-range", (fixture, bytes) =>
|
||||
bytes.writeUInt32LE(9, fixture.record("images", 1) + 9),
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) => {
|
||||
// methodStart follows fieldStart in the int32 start block.
|
||||
const at = fixture.record("typeDefinitions", 0) + 8 + 3 + 1 + 4 + 4;
|
||||
bytes.writeInt32LE(4, at);
|
||||
}),
|
||||
"index-out-of-range",
|
||||
rejectEdited("index-out-of-range", (fixture, bytes) => {
|
||||
// methodStart follows fieldStart in the int32 start block.
|
||||
const at = fixture.record("typeDefinitions", 0) + 8 + 3 + 1 + 4 + 4;
|
||||
bytes.writeInt32LE(4, at);
|
||||
});
|
||||
rejectEdited("index-out-of-range", (fixture, bytes) =>
|
||||
bytes.writeUInt8(4, fixture.record("methods", 2) + 4),
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeUInt8(4, fixture.record("methods", 2) + 4),
|
||||
),
|
||||
"index-out-of-range",
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(4, fixture.section("nestedTypes").offset),
|
||||
),
|
||||
"index-out-of-range",
|
||||
rejectEdited("index-out-of-range", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(4, fixture.section("nestedTypes").offset),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a type nested in two declaring types", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) => {
|
||||
// Two string indices, three 1-byte type indices, generic container, flags.
|
||||
const starts = fixture.record("typeDefinitions", 3) + 8 + 3 + 1 + 4;
|
||||
bytes.writeInt32LE(0, starts + 16);
|
||||
bytes.writeUInt16LE(1, starts + 32 + 8);
|
||||
}),
|
||||
"nested-type-conflict",
|
||||
);
|
||||
rejectEdited("nested-type-conflict", (fixture, bytes) => {
|
||||
// Two string indices, three 1-byte type indices, generic container, flags.
|
||||
const starts = fixture.record("typeDefinitions", 3) + 8 + 3 + 1 + 4;
|
||||
bytes.writeInt32LE(0, starts + 16);
|
||||
bytes.writeUInt16LE(1, starts + 32 + 8);
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unterminated, out-of-range and non-UTF-8 strings", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("strings").size,
|
||||
fixture.record("methods", 0),
|
||||
),
|
||||
rejectEdited("invalid-string", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("strings").size,
|
||||
fixture.record("methods", 0),
|
||||
),
|
||||
"invalid-string",
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("strings").size - 1,
|
||||
fixture.header("strings", "size"),
|
||||
),
|
||||
rejectEdited("invalid-string", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(
|
||||
fixture.section("strings").size - 1,
|
||||
fixture.header("strings", "size"),
|
||||
),
|
||||
"invalid-string",
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeUInt8(0xff, fixture.stringOffset("Update")),
|
||||
),
|
||||
"invalid-string",
|
||||
rejectEdited("invalid-string", (fixture, bytes) =>
|
||||
bytes.writeUInt8(0xff, fixture.stringOffset("Update")),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -536,11 +490,8 @@ describe("rejected IL2CPP metadata references", () => {
|
||||
|
||||
it("rejects nesting cycles and self-nesting", () => {
|
||||
// Type 0 owns nestedTypes entry 0; listing itself there is a self-cycle.
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(0, fixture.section("nestedTypes").offset),
|
||||
),
|
||||
"nested-type-conflict",
|
||||
rejectEdited("nested-type-conflict", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(0, fixture.section("nestedTypes").offset),
|
||||
);
|
||||
rejects(
|
||||
createIl2cppMetadataFixture({ nestingCycle: true }).bytes,
|
||||
@@ -549,11 +500,8 @@ describe("rejected IL2CPP metadata references", () => {
|
||||
});
|
||||
|
||||
it("rejects methods whose declaring type disagrees with the owning type range", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeUInt8(3, fixture.record("methods", 1) + 4),
|
||||
),
|
||||
"declaring-type-mismatch",
|
||||
rejectEdited("declaring-type-mismatch", (fixture, bytes) =>
|
||||
bytes.writeUInt8(3, fixture.record("methods", 1) + 4),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -701,21 +649,15 @@ describe("IL2CPP metadata coverage checks", () => {
|
||||
|
||||
it("rejects a method outside its declaring type's range", () => {
|
||||
// Type 3 owns methods [3, 5); shrinking it strands method 4.
|
||||
rejects(
|
||||
mutated((fixture, bytes) => {
|
||||
const starts = fixture.record("typeDefinitions", 3) + 8 + 3 + 1 + 4;
|
||||
bytes.writeUInt16LE(1, starts + 32);
|
||||
}),
|
||||
"declaring-type-mismatch",
|
||||
);
|
||||
rejectEdited("declaring-type-mismatch", (fixture, bytes) => {
|
||||
const starts = fixture.record("typeDefinitions", 3) + 8 + 3 + 1 + 4;
|
||||
bytes.writeUInt16LE(1, starts + 32);
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects images whose type ranges overlap", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeUInt8(2, fixture.record("images", 1) + 8),
|
||||
),
|
||||
"image-range-overlap",
|
||||
rejectEdited("image-range-overlap", (fixture, bytes) =>
|
||||
bytes.writeUInt8(2, fixture.record("images", 1) + 8),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -817,28 +759,19 @@ describe("IL2CPP metadata members and string literals", () => {
|
||||
|
||||
it("rejects member ranges claimed twice or outside their table", () => {
|
||||
// Type 1 claims field 0 as well, which type 0 already owns.
|
||||
rejects(
|
||||
mutated((fixture, bytes) => {
|
||||
const starts = fixture.record("typeDefinitions", 1) + 8 + 3 + 1 + 4;
|
||||
bytes.writeInt32LE(0, starts);
|
||||
}),
|
||||
"declaring-type-mismatch",
|
||||
);
|
||||
rejects(
|
||||
mutated((fixture, bytes) => {
|
||||
const starts = fixture.record("typeDefinitions", 1) + 8 + 3 + 1 + 4;
|
||||
bytes.writeInt32LE(2, starts);
|
||||
}),
|
||||
"index-out-of-range",
|
||||
);
|
||||
rejectEdited("declaring-type-mismatch", (fixture, bytes) => {
|
||||
const starts = fixture.record("typeDefinitions", 1) + 8 + 3 + 1 + 4;
|
||||
bytes.writeInt32LE(0, starts);
|
||||
});
|
||||
rejectEdited("index-out-of-range", (fixture, bytes) => {
|
||||
const starts = fixture.record("typeDefinitions", 1) + 8 + 3 + 1 + 4;
|
||||
bytes.writeInt32LE(2, starts);
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects string literals outside the literal data", () => {
|
||||
rejects(
|
||||
mutated((fixture, bytes) =>
|
||||
bytes.writeInt32LE(99, fixture.section("stringLiterals").offset + 4),
|
||||
),
|
||||
"index-out-of-range",
|
||||
rejectEdited("index-out-of-range", (fixture, bytes) =>
|
||||
bytes.writeInt32LE(99, fixture.section("stringLiterals").offset + 4),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user