feat(ghidra): admit explicit DOS COM analysis (#702)
* feat(ghidra): admit explicit DOS COM analysis Carry caller-selected COM interpretation through CLI, MCP and target identity, seed real-mode entry/context before Ghidra analysis, and verify complete loaded bytes, source mappings and measured register context. Keep original binaries unchanged and PSP/runtime coverage explicit. Assisted-by: Nitori (gensokyo-skills:nitori-reverse-engineering) * fix(verification): validate COM package selection before allocating fixtures
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("DOS COM admission", () => {
|
||||
it.each(["fixture.com", "fixture.hop", "fixture.js", "fixture.bin"])(
|
||||
"requires explicit interpretation for %s",
|
||||
async (name) => {
|
||||
const directory = await createTestTempDirectory("rea-com-target-");
|
||||
const path = join(directory, name);
|
||||
const bytes = Buffer.from("b83412c3", "hex");
|
||||
await writeFile(path, bytes);
|
||||
const target = await parseBinaryTarget(
|
||||
path,
|
||||
directory,
|
||||
"arm64",
|
||||
undefined,
|
||||
"dos-com",
|
||||
);
|
||||
expect(target).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
path,
|
||||
format: "dos-com",
|
||||
kind: "executable",
|
||||
architecture: "x86",
|
||||
availableArchitectures: ["x86"],
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
},
|
||||
});
|
||||
expect(await readFile(path)).toEqual(bytes);
|
||||
const detected = await parseBinaryTarget(path);
|
||||
expect(detected.ok && detected.value.format).not.toBe("dos-com");
|
||||
},
|
||||
);
|
||||
it.each([0, 0xff01])("rejects invalid file extent %i", async (length) => {
|
||||
const directory = await createTestTempDirectory("rea-com-target-");
|
||||
const path = join(directory, "fixture.com");
|
||||
await writeFile(path, Buffer.alloc(length));
|
||||
expect(
|
||||
await parseBinaryTarget(path, directory, "x64", undefined, "dos-com"),
|
||||
).toMatchObject({ ok: false, error: { _tag: "BinaryTargetError" } });
|
||||
});
|
||||
it("rejects contradictory target kind", async () => {
|
||||
const directory = await createTestTempDirectory("rea-com-target-");
|
||||
const path = join(directory, "fixture.com");
|
||||
await writeFile(path, Buffer.from("c3", "hex"));
|
||||
expect(
|
||||
await parseBinaryTarget(path, directory, "x64", "database", "dos-com"),
|
||||
).toMatchObject({ ok: false, error: { _tag: "BinaryTargetError" } });
|
||||
});
|
||||
});
|
||||
@@ -141,6 +141,7 @@ const outputFor = (name: string): JsonValue => {
|
||||
source_files: [],
|
||||
mappings: [],
|
||||
relocations: [],
|
||||
entry_context: [],
|
||||
entry_points: [],
|
||||
},
|
||||
limitations: ["Transport fixture only"],
|
||||
|
||||
@@ -64,6 +64,35 @@ afterEach(async () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe("Ghidra COM loader", () => {
|
||||
it("loads explicit COM at its PSP-relative entry before auto-analysis", () => {
|
||||
const arguments_ = ghidraHeadlessArguments({
|
||||
projectRoot: "/tmp/project",
|
||||
targetPath: "/tmp/target.com",
|
||||
bridgeScriptPath: "/package/bridge/ReaGhidraBridge.java",
|
||||
descriptorPath: "/tmp/session.json",
|
||||
ghidraLogPath: "/tmp/ghidra.log",
|
||||
scriptLogPath: "/tmp/script.log",
|
||||
dosCom: true,
|
||||
});
|
||||
expect(arguments_.slice(4, 12)).toEqual([
|
||||
"-loader",
|
||||
"BinaryLoader",
|
||||
"-loader-baseAddr",
|
||||
"1000:0100",
|
||||
"-processor",
|
||||
"x86:LE:16:Real Mode",
|
||||
"-cspec",
|
||||
"default",
|
||||
]);
|
||||
const prepare = arguments_.indexOf("-preScript");
|
||||
expect(arguments_[prepare + 1]).toBe("ReaGhidraPrepareCom.java");
|
||||
expect(prepare).toBeLessThan(arguments_.indexOf("-postScript"));
|
||||
expect(arguments_).toContain("-readOnly");
|
||||
expect(arguments_).toContain("-deleteProject");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra headless launcher", () => {
|
||||
it("forces the admitted real-mode language and loader for DOS MZ", () => {
|
||||
const arguments_ = ghidraHeadlessArguments({
|
||||
|
||||
Reference in New Issue
Block a user