Files
rea/tests/boundary/go/goBinaryImage.test.ts
T
a1b5d51a8d feat(go): inspect embedded binary build metadata (#1363)
* feat(go): inspect embedded binary build metadata

* fix(go): preserve byte metadata and validate container mappings

* fix(go): support moduleless legacy build metadata

Recognize optional module string headers in declared zero-filled memory while rejecting ambiguous and unmapped pointers. Preserve the original module-pointer field as the zero-byte source anchor.

Classify initial symlink-loop and overlong-path failures as invalid input, with CLI and MCP regressions.

* fix(go): reject undersized PE optional headers

* fix(native): stabilize ELF memory checks and clean up exec wrappers

Use existing parent/group/run-token ownership for caller-selected Python launchers, which can exec through a shell or prlimit. Add cancellation regressions for the valid wrapper and wrong-parent/token cases.

Replace the timing-dependent 30,000-section memory workload with a valid 32 MiB padded ELF under a 64 MiB address-space limit. Check the same image successfully through CLI and MCP before requiring a typed memory failure, preserving the production timeout and all error assertions.

Validation: npm run check and check:fast passed; 61 focused tests passed including Go CLI/MCP and session snapshots. Real decoder probes with pinned packages passed on Python 3.12.3 and 3.12.14. The full local ELF verifier is blocked by this container's procps/process-ownership boundary; the exact pushed head requires GitHub's real-binary-layout lane.

* test: repair Electron fixtures and stabilize catalog startup checks

Declare Electron imports in option, preload override, and path-resolution fixtures after upstream began requiring proven API provenance. Retain all option and preload assertions and adjust exact source ranges for the added import line.

Use the existing bounded acceptance timeout for the cold catalog lifecycle test instead of a separate 15-second ceiling. This retains the coverage allowance and all catalog, error, and cleanup assertions without retries.

Validation: npm run check, final check:fast, formatting and diff checks passed. Source path regression and Go boundary/MCP/service checks passed. All 20 Go CLI cases and both supported-host runtime cases passed on rerun; two macOS-only cases skipped on Linux. A prior contended local run timed out once in a Go CLI diagnostic; that case passed on rerun. Electron process-boundary verification is blocked locally by procps namespace inspection and requires fresh CI.

* test(mcp): isolate nested schema references between tool contracts

Clear Ajv's non-meta schema registry after each root, including compilation failures. Disabling root registration alone leaves nested IDs available to later tools and can let a dangling reference pass the catalog gate.

Add regressions for leakage after successful and failed compilation while retaining shared meta-schema validators. The regression failed before the fix; all 11 schema cases and full npm run check pass. Reviewed independently.

* test(ci): align Go effects and source-map verification contracts

Audit the Go inspector wording as static metadata inspection. Assert retained source declaration indexes in BOM reconstruction and the compiler-derived nested-map oracle. Keep a 45,000-map admission control below the 32 MiB output budget and the 50,000-map overflow case above it with the expanded representation.

Validation: reproduced all four failing assertions, then passed 120 focused tests and the final admission suite. npm run check and real Chrome 154 / esbuild 0.25.10 source-map verification passed, including all four nested-map scenarios and verified process lineage.

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-12 11:34:02 +08:00

596 lines
20 KiB
TypeScript

import { expect, it } from "vitest";
import { readGoBinaryImage } from "../../../src/go/GoBinaryImage.js";
import {
createGoBinaryFixture,
GO_MODULE_TEXT,
} from "../../fixtures/go/image.js";
it.each([
["elf", 32, "little"],
["elf", 32, "big"],
["elf", 64, "little"],
["elf", 64, "big"],
["pe", 32, "little"],
["pe", 64, "little"],
["macho", 32, "little"],
["macho", 32, "big"],
["macho", 64, "little"],
["macho", 64, "big"],
] as const)(
"reads %s %d-bit %s inline build metadata",
(format, bits, byteOrder) => {
const fixture = createGoBinaryFixture({ format, bits, byteOrder });
expect(readGoBinaryImage(fixture.bytes)).toMatchObject({
format,
bits,
byte_order: byteOrder,
build_info: {
header_offset: fixture.headerOffset,
encoding: "inline",
go_version: "go1.26.0",
module_text: GO_MODULE_TEXT,
module_bytes_base64: fixture.moduleBytes.toString("base64"),
version_location: { offset: fixture.versionOffset, bytes: 8 },
module_location: {
offset: fixture.moduleOffset,
bytes: fixture.moduleBytes.length,
},
},
});
},
);
it.each(["elf", "pe", "macho"] as const)(
"follows mapped pointers in legacy %s metadata",
(format) => {
const fixture = createGoBinaryFixture({
format,
encoding: "pointer",
goVersion: "go1.17",
});
expect(readGoBinaryImage(fixture.bytes).build_info).toMatchObject({
encoding: "pointer",
go_version: "go1.17",
module_text: GO_MODULE_TEXT,
version_location: { offset: fixture.versionOffset, bytes: 6 },
});
},
);
it.each(["elf", "macho"] as const)(
"finds sectionless %s metadata in its writable data mapping",
(format) => {
const fixture = createGoBinaryFixture({ format, sectionless: true });
expect(readGoBinaryImage(fixture.bytes).build_info?.go_version).toBe(
"go1.26.0",
);
},
);
it("does not treat a code/overlay decoy or unaligned marker as Go metadata", () => {
const absent = createGoBinaryFixture({ omitBuildInfo: true });
const decoy = createGoBinaryFixture();
decoy.bytes
.subarray(decoy.headerOffset, decoy.headerOffset + 512)
.copy(absent.bytes, 3072);
expect(readGoBinaryImage(absent.bytes).build_info).toBeNull();
const unaligned = createGoBinaryFixture({
sectionless: true,
omitBuildInfo: true,
});
decoy.bytes
.subarray(decoy.headerOffset, decoy.headerOffset + 512)
.copy(unaligned.bytes, 1025);
expect(readGoBinaryImage(unaligned.bytes).build_info).toBeNull();
});
it("refuses mapped pointer lengths outside the file instead of rounding 64-bit addresses", () => {
const fixture = createGoBinaryFixture({ encoding: "pointer" });
fixture.bytes.writeBigUInt64LE(0x20000000000001n, 1536);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(
/mapped|address/i,
);
const length = createGoBinaryFixture({ encoding: "pointer" });
length.bytes.writeBigUInt64LE(0xffffffffffffffffn, 1544);
expect(() => readGoBinaryImage(length.bytes)).toThrowError(/limit|length/i);
});
it("refuses overlong or truncated varints before decoding or allocating strings", () => {
const fixture = createGoBinaryFixture();
fixture.bytes.fill(
0xff,
fixture.headerOffset + 32,
fixture.headerOffset + 42,
);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/varint/i);
const truncated = createGoBinaryFixture();
truncated.bytes.writeBigUInt64LE(33n, 256 + 64 * 2 + 32);
truncated.bytes[truncated.headerOffset + 32] = 0x80;
expect(() => readGoBinaryImage(truncated.bytes)).toThrowError(
/truncated|range|varint/i,
);
});
it("refuses invalid module framing and preserves BOMs without replacement decoding", () => {
const fixture = createGoBinaryFixture();
fixture.bytes[fixture.moduleOffset] = 0;
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/framing/i);
const bom = createGoBinaryFixture({
goVersion: "\ufeffgo1.26.0",
moduleText: "\ufeffpath\tx\n",
});
expect(readGoBinaryImage(bom.bytes).build_info).toMatchObject({
go_version: "\ufeffgo1.26.0",
module_text: "\ufeffpath\tx\n",
});
});
it("rejects future encodings and invalid pointer widths explicitly", () => {
const flags = createGoBinaryFixture();
flags.bytes[flags.headerOffset + 15] = 0x82;
expect(() => readGoBinaryImage(flags.bytes)).toThrowError(/flags/i);
const width = createGoBinaryFixture({ encoding: "pointer" });
width.bytes[width.headerOffset + 14] = 16;
expect(() => readGoBinaryImage(width.bytes)).toThrowError(/pointer/i);
});
it("preserves non-UTF8 compiler and module bytes without rejecting other observed metadata", () => {
const version = createGoBinaryFixture();
version.bytes[version.versionOffset] = 0xff;
expect(readGoBinaryImage(version.bytes).build_info).toMatchObject({
go_version: null,
go_version_bytes_base64: version.bytes
.subarray(version.versionOffset, version.versionOffset + 8)
.toString("base64"),
module_text: GO_MODULE_TEXT,
});
const module = createGoBinaryFixture({ moduleText: "build\t-tags=x\n" });
module.bytes[module.moduleOffset + 16 + Buffer.byteLength("build\t-tags=")] =
0xff;
expect(readGoBinaryImage(module.bytes).build_info).toMatchObject({
go_version: "go1.26.0",
module_text: null,
module_bytes_base64: module.bytes
.subarray(
module.moduleOffset,
module.moduleOffset + module.moduleBytes.length,
)
.toString("base64"),
});
});
it.each([0, 4, 16])("ignores unused inline pointer width %s", (width) => {
const fixture = createGoBinaryFixture();
fixture.bytes[fixture.headerOffset + 14] = width;
expect(readGoBinaryImage(fixture.bytes).build_info?.go_version).toBe(
"go1.26.0",
);
});
it.each(["pe", "macho"] as const)(
"refuses ambiguous inline %s header mappings",
(format) => {
const fixture = createGoBinaryFixture({ format });
if (format === "pe") {
fixture.bytes.writeUInt16LE(2, 134);
fixture.bytes.copy(fixture.bytes, 304, 264, 304);
fixture.bytes.writeUInt32LE(512, 324);
} else {
fixture.bytes.writeUInt32LE(2, 16);
fixture.bytes.writeUInt32LE(224, 20);
fixture.bytes.writeUInt32LE(0x19, 184);
fixture.bytes.writeUInt32LE(72, 188);
fixture.bytes.write("__ALIAS", 192);
fixture.bytes.writeBigUInt64LE(0x10000n, 208);
fixture.bytes.writeBigUInt64LE(4096n, 216);
fixture.bytes.writeBigUInt64LE(16n, 224);
fixture.bytes.writeBigUInt64LE(4080n, 232);
}
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/ambiguous/i);
},
);
it("refuses a contradictory mapping that overlaps only inline string bytes", () => {
const fixture = createGoBinaryFixture({ format: "pe" });
fixture.bytes.writeUInt16LE(2, 134);
fixture.bytes.copy(fixture.bytes, 304, 264, 304);
fixture.bytes.writeUInt32LE(16, 312);
fixture.bytes.writeUInt32LE(fixture.moduleOffset + 32, 316);
fixture.bytes.writeUInt32LE(16, 320);
fixture.bytes.writeUInt32LE(512, 324);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/ambiguous/i);
});
it("ignores the endian flag for pointer-free strings in a big-endian image", () => {
const fixture = createGoBinaryFixture({ byteOrder: "big" });
fixture.bytes[fixture.headerOffset + 15] = 2;
expect(readGoBinaryImage(fixture.bytes).build_info?.go_version).toBe(
"go1.26.0",
);
});
it("distinguishes unsupported containers from malformed recognized images", () => {
expect(() =>
readGoBinaryImage(Buffer.from([0xca, 0xfe, 0xba, 0xbe])),
).toThrowError(/universal|fat/i);
expect(() => readGoBinaryImage(Buffer.from("\x7fELF"))).toThrowError(
/truncated/i,
);
const pe = createGoBinaryFixture({ format: "pe" });
pe.bytes.writeUInt32LE(0xfffffff0, 60);
expect(() => readGoBinaryImage(pe.bytes)).toThrowError(/range|truncated/i);
});
it("rejects ELF header tables overlapping the native header", () => {
const fixture = createGoBinaryFixture({ sectionless: true });
fixture.bytes.writeBigUInt64LE(0n, 32);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(
/header|overlap/i,
);
const declaredSize = createGoBinaryFixture();
declaredSize.bytes.writeUInt16LE(8192, 52);
expect(() => readGoBinaryImage(declaredSize.bytes)).toThrowError(
/truncated|range/i,
);
});
it("rejects contradictory aliases when a metadata address maps to different file bytes", () => {
const fixture = createGoBinaryFixture();
fixture.bytes.writeUInt16LE(2, 56);
fixture.bytes.writeUInt32LE(1, 184);
fixture.bytes.writeUInt32LE(6, 188);
fixture.bytes.writeBigUInt64LE(16n, 192);
fixture.bytes.writeBigUInt64LE(0x10000n, 200);
fixture.bytes.writeBigUInt64LE(4080n, 216);
fixture.bytes.writeBigUInt64LE(4080n, 224);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/ambiguous/i);
});
it.each(["pe", "elf"] as const)(
"ignores a marker extending past the selected %s data boundary",
(format) => {
const fixture = createGoBinaryFixture({ format, omitBuildInfo: true });
if (format === "pe") fixture.bytes.writeUInt32LE(2040, 264 + 8);
else fixture.bytes.writeBigUInt64LE(2040n, 256 + 64 * 2 + 32);
Buffer.from("ff20476f206275696c64696e663a", "hex").copy(
fixture.bytes,
3056,
);
expect(readGoBinaryImage(fixture.bytes).build_info).toBeNull();
},
);
it.each([0n, 3n])(
"rejects reserved extended ELF section counts containing %s",
(count) => {
const fixture = createGoBinaryFixture();
fixture.bytes.writeUInt16LE(0, 60);
fixture.bytes.writeBigUInt64LE(count, 256 + 32);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(
/extended|section count/i,
);
},
);
it.each(["names", "programs"] as const)(
"rejects extended ELF %s values below their reserved ranges",
(field) => {
const fixture = createGoBinaryFixture();
fixture.bytes.writeUInt16LE(0xffff, field === "names" ? 62 : 56);
fixture.bytes.writeUInt32LE(1, 256 + (field === "names" ? 40 : 44));
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/extended/i);
},
);
it("requires SHT_NULL for the initial section carrying extended ELF numbering", () => {
const bytes = extendedElfFixture();
bytes.writeUInt32LE(1, 4096 + 4);
expect(() => readGoBinaryImage(bytes)).toThrowError(
/initial|section zero|SHT_NULL/i,
);
});
it("reads a valid 65,536-entry ELF section table with an extended name-table index", () => {
const bytes = extendedElfFixture();
expect(readGoBinaryImage(bytes).build_info).toMatchObject({
go_version: "go1.26.0",
module_text: GO_MODULE_TEXT,
});
});
const extendedElfFixture = (): Buffer => {
const fixture = createGoBinaryFixture();
const tableOffset = 4096;
const count = 65536;
const bytes = Buffer.alloc(tableOffset + count * 64);
fixture.bytes.copy(bytes);
bytes.writeBigUInt64LE(BigInt(tableOffset), 40);
bytes.writeUInt16LE(0, 60);
bytes.writeUInt16LE(0xffff, 62);
bytes.writeBigUInt64LE(BigInt(count), tableOffset + 32);
bytes.writeUInt32LE(count - 1, tableOffset + 40);
fixture.bytes.subarray(384, 448).copy(bytes, tableOffset + 64);
fixture.bytes.subarray(320, 384).copy(bytes, tableOffset + (count - 1) * 64);
return bytes;
};
const legacyLayouts = [
["elf", 32, "little"],
["elf", 32, "big"],
["elf", 64, "little"],
["elf", 64, "big"],
["pe", 32, "little"],
["pe", 64, "little"],
["macho", 32, "little"],
["macho", 32, "big"],
["macho", 64, "little"],
["macho", 64, "big"],
] as const;
it.each(legacyLayouts)(
"reads moduleless legacy %s %d-bit %s metadata with a zero-filled module header",
(format, bits, byteOrder) => {
const fixture = zeroFilledModuleFixture(format, bits, byteOrder);
expect(readGoBinaryImage(fixture.bytes).build_info).toMatchObject({
encoding: "pointer",
go_version: "go1.17",
module_text: "",
module_bytes_base64: "",
module_location: { offset: fixture.moduleField, bytes: 0 },
});
},
);
it.each(["elf", "pe", "macho"] as const)(
"recognizes a module header in a %s segment containing only zero-filled memory",
(format) => {
const fixture = zeroFilledModuleFixture(format, 64, "little", true);
expect(readGoBinaryImage(fixture.bytes).build_info).toMatchObject({
go_version: "go1.17",
module_text: "",
module_location: { offset: fixture.moduleField, bytes: 0 },
});
},
);
it.each(["elf", "pe", "macho"] as const)(
"keeps unmapped and partial zero-filled %s module headers invalid",
(format) => {
const fixture = zeroFilledModuleFixture(format, 64, "little");
fixture.bytes.writeBigUInt64LE(
fixture.moduleAddress + 8n,
fixture.moduleField,
);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(
/mapped|range/i,
);
fixture.bytes.writeBigUInt64LE(0x30000n, fixture.moduleField);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(
/mapped|range/i,
);
},
);
it.each(["elf", "pe", "macho"] as const)(
"keeps compiler headers in zero-filled %s memory invalid",
(format) => {
const fixture = zeroFilledModuleFixture(format, 64, "little");
fixture.bytes.writeBigUInt64LE(
fixture.moduleAddress,
fixture.headerOffset + 16,
);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(
/mapped|range/i,
);
},
);
it.each(["elf", "pe", "macho"] as const)(
"keeps nonempty string contents in zero-filled %s memory invalid",
(format) => {
const version = zeroFilledModuleFixture(format, 64, "little");
version.bytes.writeBigUInt64LE(version.moduleAddress, 1536);
expect(() => readGoBinaryImage(version.bytes)).toThrowError(
/mapped|range/i,
);
const module = zeroFilledModuleFixture(format, 64, "little");
module.bytes.writeBigUInt64LE(0x10000n + 1552n, module.moduleField);
module.bytes.writeBigUInt64LE(module.moduleAddress, 1552);
expect(() => readGoBinaryImage(module.bytes)).toThrowError(/mapped|range/i);
},
);
it.each(["elf", "pe", "macho"] as const)(
"rejects zero-filled %s extents overflowing the image address width",
(format) => {
const fixture = zeroFilledModuleFixture(format, 64, "little", true);
if (format === "elf")
fixture.bytes.writeBigUInt64LE(0xfffffffffffffff8n, 184 + 16);
else if (format === "pe")
fixture.bytes.writeBigUInt64LE(0xfffffffffffeffffn, 152 + 24);
else fixture.bytes.writeBigUInt64LE(0xfffffffffffffff8n, 184 + 24);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(
/overflow|addresses/i,
);
},
);
it.each(["elf", "pe", "macho"] as const)(
"ignores unused file offsets for %s memory with no file bytes",
(format) => {
const fixture = zeroFilledModuleFixture(format, 64, "little", true);
if (format === "elf")
fixture.bytes.writeBigUInt64LE(0xffffffffffffffffn, 184 + 8);
else if (format === "pe") fixture.bytes.writeUInt32LE(0xffffffff, 304 + 20);
else fixture.bytes.writeBigUInt64LE(0xffffffffffffffffn, 184 + 40);
expect(readGoBinaryImage(fixture.bytes).build_info?.go_version).toBe(
"go1.17",
);
},
);
it("does not treat Mach-O __PAGEZERO as a module string header", () => {
const fixture = zeroFilledModuleFixture("macho", 64, "little", true);
fixture.bytes.fill(0, 184 + 8, 184 + 24);
fixture.bytes.write("__PAGEZERO", 184 + 8);
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/mapped|range/i);
});
it.each(["elf", "pe", "macho"] as const)(
"refuses file aliases overlapping only part of a zero-filled %s module header",
(format) => {
const fixture = zeroFilledModuleFixture(format, 64, "little");
addLegacyMapping(fixture.bytes, format, {
address: fixture.moduleAddress + 8n,
fileOffset: 512,
fileSize: 8,
memorySize: 8,
});
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/ambiguous/i);
},
);
it.each(["elf", "pe", "macho"] as const)(
"refuses a file alias covering a zero-filled %s module header even when file bytes are zero",
(format) => {
const fixture = zeroFilledModuleFixture(format, 64, "little");
addLegacyMapping(fixture.bytes, format, {
address: fixture.moduleAddress,
fileOffset: 512,
fileSize: 16,
memorySize: 16,
});
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/ambiguous/i);
},
);
it("does not infer PE zero-fill from raw padding beyond a smaller virtual size", () => {
const fixture = createGoBinaryFixture({ format: "pe", encoding: "pointer" });
fixture.bytes.writeUInt32LE(1024, 264 + 8);
expect(readGoBinaryImage(fixture.bytes).build_info?.go_version).toBe(
"go1.26.0",
);
});
it.each(["inline", "pointer"] as const)(
"refuses zero-filled aliases overlapping only %s string bytes",
(encoding) => {
const fixture = createGoBinaryFixture({ format: "pe", encoding });
addLegacyMapping(fixture.bytes, "pe", {
address: 0x10000n + BigInt(fixture.moduleOffset + 32),
fileOffset: 0,
fileSize: 0,
memorySize: 8,
});
expect(() => readGoBinaryImage(fixture.bytes)).toThrowError(/ambiguous/i);
},
);
const zeroFilledModuleFixture = (
format: "elf" | "pe" | "macho",
bits: 32 | 64,
byteOrder: "little" | "big",
separateSegment = false,
) => {
const fixture = createGoBinaryFixture({
format,
bits,
byteOrder,
encoding: "pointer",
goVersion: "go1.17",
});
const view = new DataView(
fixture.bytes.buffer,
fixture.bytes.byteOffset,
fixture.bytes.byteLength,
);
const little = byteOrder === "little";
const moduleAddress = separateSegment
? 0x20000n
: format === "pe"
? 0x10c00n
: 0x11000n;
const moduleField = fixture.headerOffset + 16 + bits / 8;
if (bits === 64) view.setBigUint64(moduleField, moduleAddress, little);
else view.setUint32(moduleField, Number(moduleAddress), little);
if (separateSegment) {
addLegacyMapping(
fixture.bytes,
format,
{ address: moduleAddress, fileOffset: 0, fileSize: 0, memorySize: 16 },
{ bits, little },
);
} else if (format === "elf") {
if (bits === 64) view.setBigUint64(168, 4112n, little);
else view.setUint32(148, 4112, little);
} else if (format === "pe") {
view.setUint32(152 + (bits === 64 ? 112 : 96) + 8, 2064, little);
} else if (bits === 64) {
view.setBigUint64(32 + 32, 4112n, little);
} else {
view.setUint32(28 + 28, 4112, little);
}
return { ...fixture, moduleAddress, moduleField };
};
const addLegacyMapping = (
bytes: Buffer,
format: "elf" | "pe" | "macho",
{
address,
fileOffset,
fileSize,
memorySize,
}: {
address: bigint;
fileOffset: number;
fileSize: number;
memorySize: number;
},
{ bits, little }: { bits: 32 | 64; little: boolean } = {
bits: 64,
little: true,
},
): void => {
const wide = bits === 64;
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const u32 = (offset: number, value: number) =>
view.setUint32(offset, value, little);
const word = (offset: number, value: bigint) => {
if (wide) view.setBigUint64(offset, value, little);
else u32(offset, Number(value));
};
if (format === "elf") {
view.setUint16(wide ? 56 : 44, 2, little);
const entry = 128 + (wide ? 56 : 32);
u32(entry, 1);
u32(entry + (wide ? 4 : 24), 6);
word(entry + (wide ? 8 : 4), BigInt(fileOffset));
word(entry + (wide ? 16 : 8), address);
word(entry + (wide ? 32 : 16), BigInt(fileSize));
word(entry + (wide ? 40 : 20), BigInt(memorySize));
} else if (format === "pe") {
view.setUint16(134, 2, little);
const entry = 152 + (wide ? 112 : 96) + 40;
u32(entry + 8, memorySize);
u32(entry + 12, Number(address - 0x10000n));
u32(entry + 16, fileSize);
u32(entry + 20, fileOffset);
u32(entry + 36, 0xc0000040);
} else {
const entry = wide ? 32 + 72 + 80 : 28 + 56 + 68;
const size = wide ? 72 : 56;
u32(16, 2);
u32(20, entry + size - (wide ? 32 : 28));
u32(entry, wide ? 0x19 : 1);
u32(entry + 4, size);
bytes.write("__EXTRA", entry + 8);
word(entry + 24, address);
word(entry + (wide ? 32 : 28), BigInt(memorySize));
word(entry + (wide ? 40 : 32), BigInt(fileOffset));
word(entry + (wide ? 48 : 36), BigInt(fileSize));
u32(entry + (wide ? 56 : 40), 3);
u32(entry + (wide ? 60 : 44), 3);
}
};