Files
reverse-engineering-anything/src/native/metadata/Il2cppContainer.test.ts
T
morluto c19c2d6723 fix(native): separate container facts from Go metadata admission
Move ELF, PE and Mach-O container parsing into a shared native owner. Go alone selects and validates Go build-info sections, so unrelated malformed Go metadata no longer blocks Rust dependency or IL2CPP inspection. Remove the superseded Go-specific container representation and migrate all consumers. Adapted from draft PR #5510 without asserting human PR readiness.

Validation: 51 compiled CLI/MCP acceptance tests across Rust, Go and IL2CPP; 186 shared-reader tests; full check:ci passed. Three public synthetic-file probes reproduce the baseline Rust refusal and validate the fixed SDK-advertised MCP output, artifact digests and unchanged bytes. The exact zero-address nonallocated ELF case now succeeds for Rust while Go still reports invalid_format. No target execution or real compiler-artifact qualification was performed; no performance improvement is claimed.

Closes #3398
2026-10-21 11:58:15 +08:00

51 lines
2.0 KiB
TypeScript

import { expect, it } from "vitest";
import { readGoBinaryImage } from "../../go/GoBinaryImage.js";
import { createRustImageWithGoSection } from "../../../tests/fixtures/rust/image.js";
import { openImageSteps } from "../../il2cpp/Il2cppBinaryImage.js";
import { readBinaryContainer } from "./readBinaryContainer.js";
it.each(["unmapped", "zero-fill", "duplicate", "out-of-file"] as const)(
"keeps IL2CPP admission independent of a Mach-O Go build-info %s failure",
(fault) => {
const goNamed = createRustImageWithGoSection("macho", fault);
const control = Buffer.from(goNamed);
const sectionName = Buffer.from("__other\0".padEnd(16, "\0"), "ascii");
for (let index = 0; index < (fault === "duplicate" ? 2 : 1); index++)
sectionName.copy(control, 408 + index * 152);
expect(() => readGoBinaryImage(goNamed)).toThrow(/build-info|mapped/i);
expect(readGoBinaryImage(control).build_info).toBeNull();
expect(readBinaryContainer(goNamed).load_regions).toEqual(
readBinaryContainer(control).load_regions,
);
const image = openImageSteps(goNamed, undefined).next();
expect(image.done).toBe(true);
if (!image.done)
throw new Error("container admission unexpectedly yielded");
expect(image.value.bytes).toBe(goNamed);
expect(image.value.container).toMatchObject({
format: "macho",
macho_chained_fixups: false,
});
expect(image.value.container.executable_mappings?.length).toBeGreaterThan(
0,
);
expect(
image.value.container.sections.filter(
(section) =>
section.format === "macho" &&
section.section_name === "__go_buildinfo",
),
).toHaveLength(fault === "duplicate" ? 2 : 1);
const controlImage = openImageSteps(control, undefined).next();
expect(controlImage.done).toBe(true);
if (!controlImage.done)
throw new Error("control container admission unexpectedly yielded");
expect(controlImage.value.container.mappings).toEqual(
image.value.container.mappings,
);
},
);