feat(ghidra): add DOS MZ analysis and complete function extents (#556)
Validate DOS MZ load modules and import them with Ghidra's 16-bit real-mode profile. Preserve complete observed inclusive function body ranges through inventory, function analysis, Evidence and snapshots. Add a public source-generated DOS CLI/MCP verification lane and regressions for malformed headers, body membership and cache profiles. Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
functionBodySchema,
|
||||
procedureIdentitySchema,
|
||||
parseDocuments,
|
||||
parseListCount,
|
||||
parseNames,
|
||||
@@ -80,3 +82,132 @@ describe("Hopper boundary values", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("provider-neutral inclusive function body evidence", () => {
|
||||
const observed = () => ({
|
||||
available: true,
|
||||
provenance: "test-address-set",
|
||||
ranges: [
|
||||
{ start: "0x1000", end: "0x1002" },
|
||||
{ start: "0x1010", end: "0x1011" },
|
||||
],
|
||||
total_bytes: 5,
|
||||
span_bytes: 18,
|
||||
non_contiguous: true,
|
||||
contains_entry: true,
|
||||
});
|
||||
it("represents missing Hopper extent explicitly as unknown", () => {
|
||||
expect(
|
||||
procedureIdentitySchema.parse({ address: "0x1000", name: "main" }).body,
|
||||
).toEqual({
|
||||
available: false,
|
||||
reason: "The provider did not report complete function body ranges.",
|
||||
});
|
||||
});
|
||||
it("counts inclusive one-byte ranges without assuming an enclosing continuous body", () => {
|
||||
expect(
|
||||
functionBodySchema.safeParse({
|
||||
...observed(),
|
||||
ranges: [{ start: "0x1000", end: "0x1000" }],
|
||||
total_bytes: 1,
|
||||
span_bytes: 1,
|
||||
non_contiguous: false,
|
||||
}).success,
|
||||
).toBe(true);
|
||||
expect(functionBodySchema.parse(observed())).toMatchObject({
|
||||
total_bytes: 5,
|
||||
span_bytes: 18,
|
||||
});
|
||||
});
|
||||
it("preserves address-space identity and leaves a multi-space span unknown", () => {
|
||||
expect(
|
||||
functionBodySchema.safeParse({
|
||||
...observed(),
|
||||
ranges: [
|
||||
{ start: "a:0x1000", end: "a:0x1000" },
|
||||
{ start: "b:0x1000", end: "b:0x1001" },
|
||||
],
|
||||
total_bytes: 3,
|
||||
span_bytes: null,
|
||||
}).success,
|
||||
).toBe(true);
|
||||
expect(
|
||||
functionBodySchema.safeParse({
|
||||
...observed(),
|
||||
ranges: [{ start: "a:0x1000", end: "b:0x1000" }],
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
it("allows an observed empty set without manufacturing entry membership", () => {
|
||||
expect(
|
||||
procedureIdentitySchema.safeParse({
|
||||
address: "0x1000",
|
||||
name: "external",
|
||||
body: {
|
||||
...observed(),
|
||||
ranges: [],
|
||||
total_bytes: 0,
|
||||
span_bytes: 0,
|
||||
non_contiguous: false,
|
||||
contains_entry: false,
|
||||
},
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
it("checks entry membership using address space and inclusive endpoints", () => {
|
||||
expect(
|
||||
procedureIdentitySchema.safeParse({
|
||||
address: "0x1002",
|
||||
name: "last",
|
||||
body: observed(),
|
||||
}).success,
|
||||
).toBe(true);
|
||||
expect(
|
||||
procedureIdentitySchema.safeParse({
|
||||
address: "0x1003",
|
||||
name: "gap",
|
||||
body: observed(),
|
||||
}).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
procedureIdentitySchema.safeParse({
|
||||
address: "other:0x1000",
|
||||
name: "other",
|
||||
body: observed(),
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
it.each([
|
||||
{ total_bytes: 18 },
|
||||
{ span_bytes: 5 },
|
||||
{ non_contiguous: false },
|
||||
{
|
||||
ranges: [
|
||||
{ start: "0x1000", end: "0x1002" },
|
||||
{ start: "0x1003", end: "0x1004" },
|
||||
],
|
||||
},
|
||||
{
|
||||
ranges: [
|
||||
{ start: "0x1000", end: "0x1002" },
|
||||
{ start: "0x1002", end: "0x1004" },
|
||||
],
|
||||
},
|
||||
{
|
||||
ranges: [
|
||||
{ start: "0x1010", end: "0x1011" },
|
||||
{ start: "0x1000", end: "0x1002" },
|
||||
],
|
||||
},
|
||||
{
|
||||
ranges: [{ start: "0x0", end: "0x20000000000000" }],
|
||||
total_bytes: Number.MAX_SAFE_INTEGER,
|
||||
span_bytes: Number.MAX_SAFE_INTEGER,
|
||||
non_contiguous: false,
|
||||
},
|
||||
])("rejects contradictory or unsafe range facts %j", (change) => {
|
||||
expect(
|
||||
functionBodySchema.safeParse({ ...observed(), ...change }).success,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user