fix(ghidra): preserve Unicode boundaries without breaking sessions
Validate native annotation text before mutation and escape surrogate code units in Java bridge JSON replies. Reject unsupported text with field and index diagnostics while preserving supported Unicode and line endings. Probe real CLI/MCP annotation, transport, mapping, rollback and cleanup behavior; replace seven redundant unit tests with E2E and SDK boundary coverage.
This commit is contained in:
@@ -1,120 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
isGhidraInventoryOperation,
|
||||
parseGhidraInventoryInput,
|
||||
parseGhidraInventoryResult,
|
||||
} from "./GhidraInventoryValues.js";
|
||||
|
||||
describe("Ghidra inventory boundary values", () => {
|
||||
it("admits explicit byte reads and source offset mapping without invented caps", () => {
|
||||
expect(
|
||||
parseGhidraInventoryInput("read_bytes", { address: "0x10000" }),
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: { address: "0x10000", document: null, length: 256 },
|
||||
});
|
||||
expect(
|
||||
parseGhidraInventoryInput("read_bytes", {
|
||||
address: "0x10000",
|
||||
length: 4097,
|
||||
}).ok,
|
||||
).toBe(true);
|
||||
expect(
|
||||
parseGhidraInventoryInput("read_bytes", { address: "0x10000", length: 0 })
|
||||
.ok,
|
||||
).toBe(false);
|
||||
expect(
|
||||
parseGhidraInventoryInput("address_to_file_offset", {
|
||||
address: "HEADER:0x1",
|
||||
}).ok,
|
||||
).toBe(true);
|
||||
});
|
||||
it("checks byte length and completeness before accepting memory Evidence", () => {
|
||||
const result = {
|
||||
address: "0x10000",
|
||||
requested_bytes: 4,
|
||||
returned_bytes: 2,
|
||||
bytes_hex: "0410",
|
||||
complete: false,
|
||||
};
|
||||
expect(parseGhidraInventoryResult("read_bytes", result)).toEqual({
|
||||
ok: true,
|
||||
value: result,
|
||||
});
|
||||
for (const change of [
|
||||
{ complete: true },
|
||||
{ returned_bytes: 4 },
|
||||
{ bytes_hex: "04" },
|
||||
{ requested_bytes: 1 },
|
||||
])
|
||||
expect(
|
||||
parseGhidraInventoryResult("read_bytes", { ...result, ...change }).ok,
|
||||
).toBe(false);
|
||||
expect(
|
||||
parseGhidraInventoryResult("address_to_file_offset", {
|
||||
address: "0x10000",
|
||||
file_offset: -1,
|
||||
}).ok,
|
||||
).toBe(false);
|
||||
});
|
||||
it("accepts complete inventories and searches without page controls", () => {
|
||||
expect(parseGhidraInventoryInput("list_procedures", {})).toEqual({
|
||||
ok: true,
|
||||
value: { document: null },
|
||||
});
|
||||
expect(
|
||||
parseGhidraInventoryInput("search_strings", { pattern: "needle" }),
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
pattern: "needle",
|
||||
mode: "literal",
|
||||
case_sensitive: false,
|
||||
document: null,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
parseGhidraInventoryInput("list_procedures", { limit: 100 }),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
expect(
|
||||
parseGhidraInventoryInput("list_documents", { extra: true }),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
});
|
||||
|
||||
it("keeps the admitted operation set closed", () => {
|
||||
expect(isGhidraInventoryOperation("list_names")).toBe(true);
|
||||
expect(isGhidraInventoryOperation("goto_address")).toBe(false);
|
||||
expect(isGhidraInventoryOperation("set_comment")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns complete typed inventory arrays", () => {
|
||||
const procedures = Array.from({ length: 700 }, (_, index) => ({
|
||||
address: `0x${(0x401000 + index).toString(16)}`,
|
||||
value: `sub_${index}`,
|
||||
procedure: { external: false, thunk: false, thunk_target: null },
|
||||
}));
|
||||
expect(parseGhidraInventoryResult("list_procedures", procedures)).toEqual({
|
||||
ok: true,
|
||||
value: procedures,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects malformed inventory items", () => {
|
||||
expect(
|
||||
parseGhidraInventoryResult("list_procedures", [
|
||||
{
|
||||
address: "00401000",
|
||||
value: "main",
|
||||
procedure: { external: false, thunk: false, thunk_target: null },
|
||||
},
|
||||
]),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
|
||||
expect(
|
||||
parseGhidraInventoryResult("search_strings", [{ address: "0x1000" }]),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
|
||||
});
|
||||
});
|
||||
import { parseGhidraInventoryResult } from "./GhidraInventoryValues.js";
|
||||
|
||||
// Wire-boundary fixture only; real-provider acceptance belongs to the DOS verifier.
|
||||
describe("containing-procedure complete body evidence", () => {
|
||||
|
||||
Reference in New Issue
Block a user