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>
This commit is contained in:
Giridhar
2026-10-11 04:35:38 +08:00
committed by GitHub
co-authored by morluto
parent d6f698d8af
commit 6e0d5d64d3
13 changed files with 351 additions and 24 deletions
@@ -62,6 +62,66 @@ it("rejects contradictory annotation readback across the provider and MCP bounda
}
});
it("routes address naming to Ghidra with compact per-address results", async () => {
const requests: { operation: string; input: unknown }[] = [];
let output: unknown = null;
const harness = await connectGhidraMcp(
"ghidra-address-naming",
(operation, input) => {
requests.push({ operation, input });
return Promise.resolve(ok(jsonValueSchema.parse(output)));
},
);
try {
output = true;
const single = await harness.mcp.callTool({
name: "set_address_name",
arguments: { address: "0x1000", name: "fixture_entry" },
});
expect(single.isError).not.toBe(true);
expect(single.structuredContent).toMatchObject({ normalized_result: true });
output = { "0x1000": true, "0x2000": false };
const batch = await harness.mcp.callTool({
name: "set_addresses_names",
arguments: { names: { "0x1000": "fixture_entry", "0x2000": "g_value" } },
});
expect(batch.isError).not.toBe(true);
expect(batch.structuredContent).toMatchObject({
normalized_result: { "0x1000": true, "0x2000": false },
});
expect(requests).toEqual([
{
operation: "set_address_name",
input: { document: null, address: "0x1000", name: "fixture_entry" },
},
{
operation: "set_addresses_names",
input: {
document: null,
names: { "0x1000": "fixture_entry", "0x2000": "g_value" },
},
},
]);
const empty = await harness.mcp.callTool({
name: "set_addresses_names",
arguments: { names: {} },
});
expect(empty.isError).toBe(true);
expect(requests).toHaveLength(2);
output = "fixture_entry";
const malformed = await harness.mcp.callTool({
name: "set_address_name",
arguments: { address: "0x1000", name: "fixture_entry" },
});
expect(malformed.isError).toBe(true);
expect(parseMcpToolError(malformed)).toMatchObject({
error: { code: "unreadable_output" },
});
} finally {
await harness.close();
}
});
describe("Ghidra MCP evidence parity", () => {
it("preserves provider evidence, composed parity, and capability routing", async () => {
const harness = await connectGhidraMcp("ghidra-parity");
@@ -19,7 +19,10 @@ import type {
GhidraLauncher,
} from "../../../../src/ghidra/GhidraLauncher.js";
import type { GhidraTransportKind } from "../../../../src/ghidra/GhidraTransport.js";
import { GHIDRA_SESSION_CAPABILITIES } from "../../../../src/ghidra/GhidraSessionValues.js";
import {
GHIDRA_MUTATING_OPERATIONS,
GHIDRA_SESSION_CAPABILITIES,
} from "../../../../src/ghidra/GhidraSessionValues.js";
import { waitForExit as waitForChildExit } from "../../../support/process/processFixture.js";
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
@@ -177,7 +180,7 @@ describe("GhidraClient", () => {
capabilities: GHIDRA_SESSION_CAPABILITIES.filter(
(value) =>
HOST_TRANSPORT === "unix-socket" ||
value !== "annotate_native_function",
!GHIDRA_MUTATING_OPERATIONS.has(value),
),
target: {
image_base: "0x1000",
+7 -2
View File
@@ -5,6 +5,11 @@
#define REA_CPP_SYMBOL(name) name
#endif
volatile int rea_namespace_alpha_value
__asm__(REA_CPP_SYMBOL("_ZN5alpha5valueE")) = 3;
volatile int rea_namespace_nested_value
__asm__(REA_CPP_SYMBOL("_ZN5outer5inner5valueE")) = 1;
__attribute__((noinline, used)) int rea_namespace_alpha(int value)
__asm__(REA_CPP_SYMBOL("_ZN5alpha4sameEi"));
__attribute__((noinline, used)) int rea_namespace_beta(int value)
@@ -12,9 +17,9 @@ __attribute__((noinline, used)) int rea_namespace_beta(int value)
__attribute__((noinline, used)) int rea_namespace_nested(int value)
__asm__(REA_CPP_SYMBOL("_ZN5outer5inner4sameEi"));
int rea_namespace_alpha(int value) { return value + 3; }
int rea_namespace_alpha(int value) { return value + rea_namespace_alpha_value; }
int rea_namespace_beta(int value) { return value * 2; }
int rea_namespace_nested(int value) { return value - 1; }
int rea_namespace_nested(int value) { return value - rea_namespace_nested_value; }
int main(void) {
return rea_namespace_alpha(1) + rea_namespace_beta(2) +
+8 -1
View File
@@ -231,6 +231,8 @@ const sessionInfo = ({
"resolve_containing_procedure",
"search_procedures",
"search_strings",
"set_address_name",
"set_addresses_names",
"annotate_native_function",
"inspect_native_data_type",
"inspect_native_instruction",
@@ -246,7 +248,12 @@ const sessionInfo = ({
"xrefs",
].filter(
(value) =>
transport === "unix-socket" || value !== "annotate_native_function",
transport === "unix-socket" ||
![
"annotate_native_function",
"set_address_name",
"set_addresses_names",
].includes(value),
),
target: {
name: "fixture",