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:
@@ -36,6 +36,7 @@ const formatSchema = z.enum([
|
||||
"elf",
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
|
||||
@@ -49,6 +49,7 @@ const artifactFormatSchema = z.enum([
|
||||
"elf",
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"hopper",
|
||||
"analysis-database",
|
||||
"ipa",
|
||||
|
||||
@@ -7,7 +7,7 @@ export type { BinaryArchitecture, BinaryTarget } from "./binaryTargetTypes.js";
|
||||
/** Format and architecture facts recovered from an executable header. */
|
||||
export type ExecutableMetadata =
|
||||
| {
|
||||
readonly format: "mach-o" | "elf" | "dos-mz";
|
||||
readonly format: "mach-o" | "elf" | "dos-mz" | "dos-com";
|
||||
readonly architecture: BinaryArchitecture;
|
||||
readonly availableArchitectures: readonly BinaryArchitecture[];
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ type ExecutableTarget = BinaryTargetIdentity & {
|
||||
*/
|
||||
export type BinaryTarget =
|
||||
| (ExecutableTarget & {
|
||||
readonly format: "mach-o" | "elf" | "dos-mz";
|
||||
readonly format: "mach-o" | "elf" | "dos-mz" | "dos-com";
|
||||
readonly executableRole?: never;
|
||||
readonly managed?: never;
|
||||
})
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { executableFormatHintSchema, validateDosComLength } from "./dosCom.js";
|
||||
|
||||
describe("explicit DOS COM interpretation", () => {
|
||||
it.each([1, 0xff00])("admits the segment extent %i", (length) => {
|
||||
expect(validateDosComLength(length).ok).toBe(true);
|
||||
});
|
||||
it.each([0, -1, 0xff01, 1.5, NaN, Infinity])(
|
||||
"rejects invalid extent %i",
|
||||
(length) => {
|
||||
expect(validateDosComLength(length).ok).toBe(false);
|
||||
},
|
||||
);
|
||||
it("does not turn arbitrary format names into raw COM", () => {
|
||||
expect(executableFormatHintSchema.safeParse("dos-com").success).toBe(true);
|
||||
expect(executableFormatHintSchema.safeParse("raw").success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import { z } from "zod";
|
||||
import { err, ok, type Result } from "./result.js";
|
||||
|
||||
/** Headerless DOS COM interpretation explicitly selected by the caller. */
|
||||
export const executableFormatHintSchema = z.literal("dos-com");
|
||||
/** Explicit executable interpretation for formats with no identifying header. */
|
||||
export type ExecutableFormatHint = z.infer<typeof executableFormatHintSchema>;
|
||||
|
||||
/** Validate the single 64 KiB COM segment, excluding its 256-byte PSP prefix. */
|
||||
export const validateDosComLength = (length: number): Result<null, string> =>
|
||||
Number.isSafeInteger(length) && length >= 1 && length <= 0xff00
|
||||
? ok(null)
|
||||
: err(
|
||||
"DOS COM requires 1..65280 file bytes (64 KiB segment minus the 256-byte PSP prefix)",
|
||||
);
|
||||
@@ -27,6 +27,7 @@ const subjectSchema = z.object({
|
||||
"elf",
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
|
||||
@@ -55,6 +55,20 @@ export const nativeLoadImageObservationSchema = z.strictObject({
|
||||
}),
|
||||
),
|
||||
entry_points: z.array(address),
|
||||
entry_context: z.array(
|
||||
z.strictObject({
|
||||
address,
|
||||
registers: z.array(
|
||||
z.strictObject({
|
||||
name: z.string().min(1),
|
||||
value_hex: z
|
||||
.string()
|
||||
.regex(/^0x[a-f0-9]+$/u)
|
||||
.nullable(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
/** Independent comparison, preserving both expectations and measured values. */
|
||||
@@ -77,7 +91,7 @@ export const nativeLoadImageSchema = z.discriminatedUnion("status", [
|
||||
}),
|
||||
z.strictObject({
|
||||
status: z.enum(["verified", "mismatch"]),
|
||||
format: z.literal("dos-mz"),
|
||||
format: z.enum(["dos-mz", "dos-com"]),
|
||||
target_sha256: digest,
|
||||
load_segment: integer.max(0xffff),
|
||||
header_bytes: integer,
|
||||
@@ -100,3 +114,5 @@ export type NativeLoadImage = z.infer<typeof nativeLoadImageSchema>;
|
||||
export type NativeLoadImageObservation = z.infer<
|
||||
typeof nativeLoadImageObservationSchema
|
||||
>;
|
||||
/** One independently compared native import fact. */
|
||||
export type NativeLoadImageCheck = z.infer<typeof nativeLoadImageCheckSchema>;
|
||||
|
||||
@@ -238,7 +238,11 @@ const familiesFor = (format: string, path: string): RuntimeFamily[] => {
|
||||
if (format === "javascript-bundle") families.add("javascript");
|
||||
if (format === "jvm-class" || /(?:^|\/)[^/]+\.class$/iu.test(path))
|
||||
families.add("jvm");
|
||||
if (["elf", "mach-o", "mach-o-universal", "pe", "dos-mz"].includes(format))
|
||||
if (
|
||||
["elf", "mach-o", "mach-o-universal", "pe", "dos-mz", "dos-com"].includes(
|
||||
format,
|
||||
)
|
||||
)
|
||||
families.add("native");
|
||||
if (format === "webassembly" || /(?:^|\/)[^/]+\.wasm$/iu.test(path))
|
||||
families.add("webassembly");
|
||||
|
||||
Reference in New Issue
Block a user