Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(targets): retain unsupported PE machine in diagnostics (#2448)

Aurantium43738bec579f
diff --git a/src/domain/binaryTarget.ts b/src/domain/binaryTarget.ts
index 48da65960..99bc6dd24 100644
--- a/src/domain/binaryTarget.ts
+++ b/src/domain/binaryTarget.ts
@@ -278,8 +278,12 @@ export const parsePeRecord = (
record.toString("binary", 0, 4) !== "PE\u0000\u0000"
)
return err("invalid or truncated PE header");
- const machine = decodePeMachine(record.readUInt16LE(4));
- if (machine === undefined) return err("unsupported PE architecture");
+ const machineType = record.readUInt16LE(4);
+ const machine = decodePeMachine(machineType);
+ if (machine === undefined)
+ return err(
+ `unsupported PE architecture (COFF machine 0x${machineType.toString(16).padStart(4, "0")})`,
+ );
const { architecture } = machine;
const optionalHeaderSize = record.readUInt16LE(20);
if (optionalHeaderSize > 4096 || record.length < 24 + optionalHeaderSize)
diff --git a/tests/boundary/filesystem/targetDiagnostics.test.ts b/tests/boundary/filesystem/targetDiagnostics.test.ts
index 5d1953760..dacd21687 100644
--- a/tests/boundary/filesystem/targetDiagnostics.test.ts
+++ b/tests/boundary/filesystem/targetDiagnostics.test.ts
@@ -4,9 +4,35 @@ import { describe, expect, it } from "vitest";
import { systemDoctorHost } from "../../../src/application/Doctor.js";
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
+import { pe } from "../../../src/domain/binaryTarget.fixture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
describe("executable format refusal diagnostics", () => {
+ it.each([
+ [0x01a6, "0x01a6"],
+ [0x0000, "0x0000"],
+ [0xffff, "0xffff"],
+ ] as const)(
+ "retains unsupported PE machine %i in the refusal",
+ async (machine, expectedMachine) => {
+ const directory = await createTestTempDirectory("rea-target-pe-machine-");
+ const path = join(directory, "unsupported.exe");
+ const bytes = pe(0x014c);
+ bytes.writeUInt16LE(machine, 0x44);
+ await writeFile(path, bytes);
+
+ const result = await parseBinaryTarget(path);
+ if (result.ok) throw new Error("unsupported PE target was admitted");
+ const reason = `unsupported PE architecture (COFF machine ${expectedMachine})`;
+ expect(projectAnalysisError(result.error)).toMatchObject({
+ code: "target_unavailable",
+ category: "unsupported_target",
+ message: `Cannot open artifact: ${reason}.`,
+ details: { reason, constraint: "file_format_rejected" },
+ });
+ },
+ );
+
it.each(["NE", "LE", "LX"] as const)(
"reports unsupported %s executables without path advice",
async (signature) => {