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
+27 -1
View File
@@ -13,7 +13,10 @@ import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
import { err, ok, type Result } from "../domain/result.js";
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
/** Read-only direct inventory operations admitted by the Ghidra adapter. */
/**
* Direct inventory operations admitted by the Ghidra adapter. All are reads
* except the naming operations, which edit the ephemeral session database.
*/
export const GHIDRA_INVENTORY_OPERATIONS = [
"inspect_native_load_image",
"read_bytes",
@@ -28,8 +31,16 @@ export const GHIDRA_INVENTORY_OPERATIONS = [
"resolve_containing_procedure",
"search_procedures",
"search_strings",
"set_address_name",
"set_addresses_names",
] as const;
/** Inventory operations that write analyst names into the session database. */
export const GHIDRA_NAMING_OPERATIONS = [
"set_address_name",
"set_addresses_names",
] as const satisfies readonly GhidraInventoryOperation[];
/** One direct inventory operation implemented by the packaged Java bridge. */
export type GhidraInventoryOperation =
(typeof GHIDRA_INVENTORY_OPERATIONS)[number];
@@ -83,6 +94,19 @@ const inputSchemas = {
.strict(),
search_procedures: z.object(searchInput).strict(),
search_strings: z.object(searchInput).strict(),
set_address_name: z
.object({ document, address: explicitAddress, name: z.string().min(1) })
.strict(),
set_addresses_names: z
.object({
document,
names: z.record(explicitAddress, z.string().min(1)),
})
.strict()
.refine(
(value) => Object.keys(value.names).length > 0,
"Supply at least one address name",
),
} satisfies Readonly<Record<GhidraInventoryOperation, z.ZodType>>;
/** Validate and default one provider request before it crosses the socket. */
@@ -281,6 +305,8 @@ const resultSchemas = {
resolve_containing_procedure: containingProcedure,
search_procedures: z.array(searchItem),
search_strings: z.array(searchItem),
set_address_name: z.boolean(),
set_addresses_names: z.record(z.string(), z.boolean()),
} satisfies Readonly<Record<GhidraInventoryOperation, z.ZodType>>;
/** Validate exact Java-bridge output before creating Evidence. */
+11 -2
View File
@@ -8,6 +8,7 @@ import {
} from "../process/WindowsAuthority.js";
import { GHIDRA_FUNCTION_OPERATIONS } from "./GhidraFunctionValues.js";
import { GHIDRA_INVENTORY_OPERATIONS } from "./GhidraInventoryValues.js";
import { GHIDRA_MUTATING_OPERATIONS } from "./GhidraSessionValues.js";
/** Public identity committed by every Ghidra-backed observation. */
export const GHIDRA_PROVIDER_IDENTITY: ProviderIdentity = Object.freeze({
@@ -50,6 +51,14 @@ export const limitationsFor = (operation: string): readonly string[] => {
"Annotation text rejects NUL and unpaired Unicode surrogates before mutation, with the field and UTF-16 index in the error. Supported Unicode and line endings are preserved.",
"Metadata edits invalidate immutable analysis snapshots and are discarded on close. CLI returns the updated dossier before session cleanup; this is not a saved Ghidra project.",
];
case "set_address_name":
case "set_addresses_names":
return [
...common,
"Names use Ghidra USER_DEFINED source. A local function entry renames that function; any other mapped address receives a new or renamed primary label. Existing symbols retain their namespace and accept leaf names or qualified names within that namespace; qualified readback can be reused without adding namespace prefixes. Readback compares the primary symbol name.",
"set_addresses_names applies each address in its own transaction and reports per-address success; invalid names, unmapped addresses, and readback mismatches roll back only that address.",
"Metadata edits invalidate immutable analysis snapshots and are discarded on close; this is not a saved Ghidra project.",
];
case "inspect_native_load_image":
return [
...common,
@@ -162,12 +171,12 @@ export const CAPABILITIES: readonly CapabilityDescriptor[] = Object.freeze(
reason: null,
// Project writes are private import machinery. Analysis reads are bound
// to the artifact/profile; session annotations disable snapshot replay.
...(operation === "annotate_native_function" ||
...(GHIDRA_MUTATING_OPERATIONS.has(operation) ||
operation === "list_documents"
? {}
: { cachePolicy: "snapshot" as const }),
effects: Object.freeze({
mutatesArtifact: operation === "annotate_native_function",
mutatesArtifact: GHIDRA_MUTATING_OPERATIONS.has(operation),
launchesProcess: true,
mayShowUi: false,
mayAccessNetwork: false,
+22 -1
View File
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
GHIDRA_SESSION_CAPABILITIES,
GHIDRA_MUTATING_OPERATIONS,
parseGhidraSessionInfo,
} from "./GhidraSessionValues.js";
@@ -81,7 +82,7 @@ describe("Ghidra mutation handshake", () => {
...value,
read_only: true,
capabilities: value.capabilities.filter(
(c) => c !== "annotate_native_function",
(c) => !GHIDRA_MUTATING_OPERATIONS.has(c),
),
};
expect(
@@ -92,4 +93,24 @@ describe("Ghidra mutation handshake", () => {
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);
}
});
});
+11 -2
View File
@@ -2,7 +2,10 @@ import { z } from "zod";
import type { JsonValue } from "../domain/jsonValue.js";
import { err, ok, type Result } from "../domain/result.js";
import { GHIDRA_INVENTORY_OPERATIONS } from "./GhidraInventoryValues.js";
import {
GHIDRA_INVENTORY_OPERATIONS,
GHIDRA_NAMING_OPERATIONS,
} from "./GhidraInventoryValues.js";
import { GHIDRA_FUNCTION_OPERATIONS } from "./GhidraFunctionValues.js";
import { ghidraExtensionResultSchema } from "./extensions/GhidraExtensions.js";
@@ -14,6 +17,12 @@ export const GHIDRA_SESSION_CAPABILITIES = [
...GHIDRA_FUNCTION_OPERATIONS,
] as const;
/** Methods that edit the session database; read-only bridges omit them. */
export const GHIDRA_MUTATING_OPERATIONS: ReadonlySet<string> = new Set([
"annotate_native_function",
...GHIDRA_NAMING_OPERATIONS,
]);
const capabilitySchema = z.enum(GHIDRA_SESSION_CAPABILITIES);
const sessionInfoSchema = z
@@ -64,7 +73,7 @@ export const parseGhidraSessionInfo = (
const parsed = sessionInfoSchema.safeParse(value);
const readOnly = expected.expectedReadOnly ?? false;
const expectedCapabilities = GHIDRA_SESSION_CAPABILITIES.filter(
(capability) => !readOnly || capability !== "annotate_native_function",
(capability) => !readOnly || !GHIDRA_MUTATING_OPERATIONS.has(capability),
);
if (
!parsed.success ||