mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 06:04:03 +00:00
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>
41 lines
1.2 KiB
TypeScript
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"),
|
|
},
|
|
});
|
|
},
|
|
);
|