mirror of
https://github.com/morluto/rea.git
synced 2026-11-10 00:36:35 +00:00
refactor(pe): share optional-header facts across readers
This commit is contained in:
1 parent
971b48f702
commit
deed39f7c4
9 files changed
+250
-105
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseExecutableHeader } from "./binaryTarget.js";
|
||||
import {
|
||||
parseExecutableHeader,
|
||||
peDebugDirectoryEntry,
|
||||
parsePeRecordFacts,
|
||||
} from "./binaryTarget.js";
|
||||
import { dosMz, elf, fat, pe, thinMach } from "./binaryTarget.fixture.js";
|
||||
|
||||
describe("executable header parsing", () => {
|
||||
@@ -377,3 +381,44 @@ const fat64 = (cpus: readonly number[], littleEndian: boolean): Buffer => {
|
||||
});
|
||||
return bytes;
|
||||
};
|
||||
|
||||
it.each([
|
||||
{ magic: 0x10b, directoryOffset: 96 },
|
||||
{ magic: 0x20b, directoryOffset: 112 },
|
||||
])(
|
||||
"retains a complete debug entry when later declared directories are unavailable ($magic)",
|
||||
({ magic, directoryOffset }) => {
|
||||
const optional = Buffer.alloc(directoryOffset + 7 * 8);
|
||||
optional.writeUInt16LE(magic);
|
||||
optional.writeUInt32LE(0x400, 60);
|
||||
optional.writeUInt32LE(0xffffffff, directoryOffset - 4);
|
||||
optional.writeUInt32LE(0x2400, directoryOffset + 6 * 8);
|
||||
optional.writeUInt32LE(28, directoryOffset + 6 * 8 + 4);
|
||||
expect(peDebugDirectoryEntry(optional)).toEqual({
|
||||
debugRva: 0x2400,
|
||||
debugSize: 28,
|
||||
sizeOfHeaders: 0x400,
|
||||
});
|
||||
expect(
|
||||
peDebugDirectoryEntry(optional.subarray(0, optional.length - 1)),
|
||||
).toBeUndefined();
|
||||
optional.writeUInt32LE(6, directoryOffset - 4);
|
||||
expect(peDebugDirectoryEntry(optional)).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps validated optional-header facts separate from executable metadata", () => {
|
||||
const bytes = pe(0x8664);
|
||||
const record = bytes.subarray(bytes.readUInt32LE(0x3c));
|
||||
const parsed = parsePeRecordFacts(record, undefined);
|
||||
if (!parsed.ok) throw new Error(parsed.error);
|
||||
expect(parsed.value.optionalHeader).toMatchObject({ magic: 0x20b, bits: 64 });
|
||||
expect(parsed.value.metadata).toEqual({
|
||||
format: "pe",
|
||||
peMachine: 0x8664,
|
||||
architecture: "x86_64",
|
||||
availableArchitectures: ["x86_64"],
|
||||
executableRole: "application",
|
||||
managed: false,
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user