Files
reverse-engineering-anything/src/domain/peCoffHeader.test.ts
T
Matt Van Hornandgensokyo-dev 637e4cb60c feat(native): inspect DWARF compile units offline
Add bounded offline DWARF compilation-unit inspection with source provenance, explicit coverage, caller-selected controls and shared ELF compression framing.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-17 10:04:46 +00:00

41 lines
1.2 KiB
TypeScript

import { expect, it } from "vitest";
import { readPeCoffHeader } from "./peCoffHeader.js";
it("retains raw COFF declarations from a borrowed record without admission policy", () => {
const source = Buffer.alloc(39, 0xa5);
const record = source.subarray(7, 27);
record.writeUInt16LE(0xffff, 0);
record.writeUInt16LE(0x1234, 2);
record.writeUInt32LE(0x01020304, 8);
record.writeUInt32LE(0x0a0b0c0d, 12);
record.writeUInt16LE(0xfedc, 16);
record.writeUInt16LE(0x89ab, 18);
const before = Buffer.from(source);
expect(readPeCoffHeader(source.subarray(7))).toEqual({
ok: true,
value: {
machine: 0xffff,
sectionCount: 0x1234,
symbolTableOffset: 0x01020304,
symbolCount: 0x0a0b0c0d,
optionalHeaderSize: 0xfedc,
characteristics: 0x89ab,
},
});
expect(source.equals(before)).toBe(true);
});
it.each(Array.from({ length: 20 }, (_, length) => length))(
"reports a truncated %i-byte COFF record without reading outside it",
(length) => {
const source = Buffer.alloc(40, 0xff);
expect(readPeCoffHeader(source.subarray(7, 7 + length))).toEqual({
ok: false,
error: {
kind: "malformed",
message: expect.stringContaining("truncated"),
},
});
},
);