mirror of
https://github.com/morluto/rea.git
synced 2026-11-09 16:26:36 +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
@@ -9,7 +9,10 @@ import { setImmediate } from "node:timers/promises";
|
||||
import type { DesktopFile, DesktopFact } from "../domain/desktopApplication.js";
|
||||
import { jsonValueByteLength } from "../domain/jsonValueByteLength.js";
|
||||
import { observeIl2cppMetadataHeaderPrefix } from "../domain/il2cpp/il2cppMetadataHeaderPrefix.js";
|
||||
import { parsePeRecord, peRvaToFileOffset } from "../domain/binaryTarget.js";
|
||||
import {
|
||||
parsePeRecordFacts,
|
||||
peRvaToFileOffset,
|
||||
} from "../domain/binaryTarget.js";
|
||||
import { readManagedMetadataLayout } from "../dotnet/ManagedMetadataLayout.js";
|
||||
import { readAssemblyReferenceName } from "../dotnet/ManagedMetadataInventoryRows.js";
|
||||
import { ManagedReaderFailure } from "../dotnet/ManagedReaderFailure.js";
|
||||
@@ -221,24 +224,24 @@ const inspectPeFile = async (
|
||||
"PE optional header exceeds the supported format bound",
|
||||
);
|
||||
const optional = await read(peOffset + 24, optionalSize);
|
||||
const parsed = parsePeRecord(Buffer.concat([coff, optional]), undefined);
|
||||
const parsed = parsePeRecordFacts(Buffer.concat([coff, optional]), undefined);
|
||||
if (!parsed.ok) {
|
||||
row.issues.push(parsed.error);
|
||||
return;
|
||||
}
|
||||
if (parsed.value.format !== "pe") return;
|
||||
if (parsed.value.metadata.format !== "pe") return;
|
||||
fact({
|
||||
kind: "native-image-header",
|
||||
offset: peOffset,
|
||||
value: { format: "pe", machine: header.value.machine },
|
||||
});
|
||||
if (!parsed.value.managed) return;
|
||||
const directories = optional.readUInt16LE(0) === 0x20b ? 112 : 96;
|
||||
const cliRva = optional.readUInt32LE(directories + 14 * 8);
|
||||
const cliSize = optional.readUInt32LE(directories + 14 * 8 + 4);
|
||||
if (!parsed.value.metadata.managed) return;
|
||||
const cliDirectory = parsed.value.optionalHeader.dataDirectories[14];
|
||||
if (cliDirectory === undefined) return;
|
||||
const { address: cliRva, size: cliSize } = cliDirectory;
|
||||
fact({
|
||||
kind: "pe-cli-directory",
|
||||
offset: peOffset + 24 + directories + 14 * 8,
|
||||
offset: peOffset + 24 + cliDirectory.offset,
|
||||
value: { rva: cliRva, bytes: cliSize },
|
||||
});
|
||||
if (unityManagedDirectory === null) return;
|
||||
@@ -249,7 +252,7 @@ const inspectPeFile = async (
|
||||
rva,
|
||||
sections,
|
||||
sectionCount,
|
||||
optional.readUInt32LE(60),
|
||||
parsed.value.optionalHeader.sizeOfHeaders,
|
||||
bytes,
|
||||
);
|
||||
const cliOffset = mapped(cliRva, 16);
|
||||
|
||||
Reference in new issue
Block a user