Files
rea/src/domain/elfDynamicEntry.test.ts
T
morluto 6336fe5bb5 refactor: consolidate binary analysis admission and format ownership
Reuse the existing provider input admission helper across twelve services,
preserving cancellation, schema errors, path policies, and Evidence handling.
Share ELF dynamic records across Dart, MIPS, and IL2CPP readers, and reuse
Mach-O segment and section records for Node SEA location.

Require canonical DOS ownership before GPU PE section discovery so relocation
bytes cannot masquerade as a PE pointer. Cover valid short DOS headers and
the malformed case through both inventory and the public CLI.
2026-10-26 16:44:21 +08:00

58 lines
1.9 KiB
TypeScript

import { expect, it } from "vitest";
import { readElfDynamicEntry } from "./elfDynamicEntry.js";
const formats = [
{ bits: 32, littleEndian: false },
{ bits: 32, littleEndian: true },
{ bits: 64, littleEndian: false },
{ bits: 64, littleEndian: true },
] as const;
it.each(formats)(
"preserves signed ELF$bits tags and unsigned values (littleEndian=$littleEndian)",
({ bits, littleEndian }) => {
const wide = bits === 64;
const length = wide ? 16 : 8;
const backing = Buffer.alloc(length + 19, 0xa5);
const bytes = backing.subarray(7, 7 + length);
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const tag = wide ? -0x8000000000000000n : -0x80000000n;
const value = wide ? 0xffffffffffffffffn : 0xffffffffn;
if (wide) {
view.setBigInt64(0, tag, littleEndian);
view.setBigUint64(8, value, littleEndian);
} else {
view.setInt32(0, Number(tag), littleEndian);
view.setUint32(4, Number(value), littleEndian);
}
const before = Buffer.from(backing);
const parsed = readElfDynamicEntry(backing.subarray(7), bits, littleEndian);
expect(backing.equals(before)).toBe(true);
backing.fill(0);
expect(parsed).toEqual({ ok: true, value: { tag, value } });
expect(readElfDynamicEntry(bytes, bits, littleEndian)).toEqual({
ok: true,
value: { tag: 0n, value: 0n },
});
},
);
it.each(formats)(
"refuses incomplete ELF$bits dynamic entries (littleEndian=$littleEndian)",
({ bits, littleEndian }) => {
const length = bits === 64 ? 16 : 8;
const backing = Buffer.alloc(length + 7);
for (let observed = 0; observed < length; observed++)
expect(
readElfDynamicEntry(
backing.subarray(7, 7 + observed),
bits,
littleEndian,
),
).toEqual({
ok: false,
error: { kind: "malformed", message: "ELF dynamic entry is truncated" },
});
},
);