Files
rea/src/ghidra/GhidraSessionValues.test.ts
T
Giridharandmorluto 6e0d5d64d3 feat(ghidra): admit set_address_name and set_addresses_names (#1635)
* feat(ghidra): admit set_address_name and set_addresses_names

Ghidra sessions rejected the existing naming tools with "operation is not declared by this provider", so agents had to use annotate_native_function, which returns a complete function dossier per rename and cannot name data addresses.

The Java bridge now names a local function entry (namespace-aware, like annotate_native_function) or creates/renames the primary label at any other mapped address, verifying readback. set_addresses_names applies each address in its own transaction and reports per-address booleans. Both are mutating capabilities: excluded from read-only (Windows P0) handshakes and from snapshot replay.

* fix(ghidra): normalize qualified symbol names and reject empty leaves

Share namespace-aware leaf normalization across functions and primary labels. Invalid qualified leaves now return false for naming operations without marking the provider unavailable; function annotations retain typed invalid-input errors.

Extend real CLI/MCP namespace verification with namespaced globals, readback replay, failed-name rollback, mixed batches, and capability checks.

Validation: 75 focused tests and npm run check pass. Ghidra 12.1.4/JDK 21 namespace verification passes on macOS arm64 with unchanged source bytes and complete cleanup. The full host lane passes this workflow before the existing entry-alias fixture fails because the compiler places its interior label at the function entry.

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-11 04:35:38 +08:00

117 lines
3.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
GHIDRA_SESSION_CAPABILITIES,
GHIDRA_MUTATING_OPERATIONS,
parseGhidraSessionInfo,
} from "./GhidraSessionValues.js";
const expected = {
runId: "d6fcbb66-e829-4ff6-a535-0035aec63139",
providerVersion: "12.1.4",
profileDigest: "a".repeat(64),
targetSha256: "b".repeat(64),
expectedLanguageId: "x86:LE:16:Real Mode",
expectedCompilerSpecId: "default",
};
const session = (
language = expected.expectedLanguageId,
compiler = "default",
) => ({
name: "REA Ghidra bridge",
run_id: expected.runId,
profile_digest: expected.profileDigest,
provider: { id: "ghidra", version: expected.providerVersion },
read_only: false,
analysis_complete: true,
analysis_timed_out: false,
capabilities: [...GHIDRA_SESSION_CAPABILITIES],
target: {
name: "legacy.exe",
language_id: language,
compiler_spec_id: compiler,
image_base: "0x0",
default_address_space: "ram",
sha256: expected.targetSha256,
},
});
describe("Ghidra DOS import commitment", () => {
it("accepts the exact admitted real-mode language and compiler", () => {
expect(parseGhidraSessionInfo(session(), expected).ok).toBe(true);
});
it("rejects a 32-bit interpretation even when artifact and profile hashes match", () => {
expect(
parseGhidraSessionInfo(session("x86:LE:32:default"), expected).ok,
).toBe(false);
});
it("rejects compiler drift independently of the language", () => {
expect(
parseGhidraSessionInfo(session(undefined, "windows"), expected).ok,
).toBe(false);
});
});
describe("Ghidra mutation handshake", () => {
it("requires the exact mutation authority and rejects duplicate capabilities", () => {
const value = session();
expect(
parseGhidraSessionInfo({ ...value, read_only: true }, expected).ok,
).toBe(false);
expect(
parseGhidraSessionInfo(
{ ...value, capabilities: [...value.capabilities, "ping"] },
expected,
).ok,
).toBe(false);
expect(
parseGhidraSessionInfo(
{
...value,
capabilities: value.capabilities.filter(
(c) => c !== "annotate_native_function",
),
},
expected,
).ok,
).toBe(false);
});
it("excludes database mutation from the Windows transport handshake", () => {
const value = session();
const windows = {
...value,
read_only: true,
capabilities: value.capabilities.filter(
(c) => !GHIDRA_MUTATING_OPERATIONS.has(c),
),
};
expect(
parseGhidraSessionInfo(windows, { ...expected, expectedReadOnly: true })
.ok,
).toBe(true);
expect(
parseGhidraSessionInfo(value, { ...expected, expectedReadOnly: true }).ok,
).toBe(false);
});
it("treats address naming as database mutation", () => {
expect([...GHIDRA_MUTATING_OPERATIONS].sort()).toEqual([
"annotate_native_function",
"set_address_name",
"set_addresses_names",
]);
const value = session();
for (const naming of ["set_address_name", "set_addresses_names"]) {
expect(value.capabilities).toContain(naming);
expect(
parseGhidraSessionInfo(
{
...value,
capabilities: value.capabilities.filter((c) => c !== naming),
},
expected,
).ok,
).toBe(false);
}
});
});