Skip to content

feat(ghidra): admit set_address_name and set_addresses_names - #1635

Merged
morluto merged 2 commits into
morluto:mainfrom
giri256:feat/ghidra-address-naming
Oct 10, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
giri256:feat/ghidra-address-naming

Conversation

@giri256

@giri256 giri256 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Ghidra sessions now admit set_address_name and set_addresses_names. Before this change both failed with capability_unavailable: operation is not declared by this provider, so agents had to rename through annotate_native_function, which returns a full function dossier per call and cannot name data addresses.

Fixes #1634

Problem and expected behavior

  • Trigger: open_binary on any x86/x64 PE with Ghidra, then set_address_name {address, name}. The result is capability_unavailable.
  • Expected: the same contract Hopper offers. set_address_name returns a boolean; set_addresses_names returns a record of per-address booleans. Function entries and data addresses are both nameable, and the names show up in later pseudocode, address_name and list_names.

Change and scope

  • Bridge (ReaGhidraBridge.java): applyAddressName runs one transaction per address.
    • At a local function entry it renames the function. It reuses annotationLeafName, so qualified names behave as in annotate_native_function.
    • At any other mapped address it renames the existing non-dynamic primary symbol, or creates a USER_DEFINED label and makes it primary.
    • It verifies by primary-symbol readback. An invalid or duplicate name, or a readback mismatch, returns false and rolls back only that address. Unmapped addresses fail the single operation with invalid_request and are false inside a batch.
  • Adapter:
    • Both operations join GHIDRA_INVENTORY_OPERATIONS, with strict input schemas (a batch needs at least one entry) and boolean result schemas.
    • The new GHIDRA_MUTATING_OPERATIONS (annotate_native_function plus the naming operations) is the single source for:
      • read-only handshake filtering;
      • mutatesArtifact;
      • opting out of snapshot replay.
    • Windows P0 stays read-only.
  • Not included: set_comment / set_inline_comment / bookmarks for Ghidra, and persistence beyond the ephemeral session.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the Ghidra adapter (src/ghidra/*Values.ts, GhidraProviderCapabilities.ts) and the Java bridge.
  • CLI and MCP/tool-catalog contract: no new tools. Existing tool contracts and output schemas are reused unchanged; the Ghidra provider now declares two more operations.
  • Provider, bridge, target-format, or platform compatibility:
    • The Linux/macOS unix-socket bridge advertises two more capabilities, and the handshake requires them.
    • Windows P0 excludes them, like annotate_native_function.
    • Hopper is unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged. Edits are session metadata; source bytes are never written.
  • Process execution, authorization, cleanup, or containment impact: none beyond the existing mutation authority.
  • Generated metadata, package, or installation impact: none committed. Authored docs and the skill reference are updated.

Evidence and regression coverage

  • Tests added or updated:
    • GhidraSessionValues.test.ts: naming is treated as mutation, and a missing naming capability fails the handshake.
    • ghidraEvidenceMcp.test.ts: MCP routing and exact provider inputs; compact boolean and record results; an empty batch is rejected before the provider; malformed bridge output gives unreadable_output.
    • The fake bridge fixture and the ghidraClient handshake now include the new capabilities.
  • Base reproduction: on main, set_address_name against Ghidra returns capability_unavailable (operation is not declared by this provider).
  • User-visible MCP output: real Ghidra 12.1.4, Win32 PE (1996 game executable):
    set_address_name {address:"0x409ad0", name:"melee_blow_landed"} -> true
    set_addresses_names {"0x4052c0":"bike_take_hit","0x4642d8":"g_player_bike","0x4b8a12":"g_player_level","0x409ad1":"bad name with spaces"}
      -> {"0x4052c0":true,"0x4642d8":true,"0x4b8a12":true,"0x409ad1":false}
    address_name {address:"0x4642d8"} -> "g_player_bike"
    procedure_pseudo_code 0x4096f0 -> now calls melee_blow_landed(...) and reads g_player_bike / g_player_level
    
  • Remaining proof gaps: no macOS run; no Windows (by design read-only).

Validation performed

All on the rebased commit (base be44b50), Node 26.10, Arch Linux x64:

  • npx tsc --noEmit -p tsconfig.json: pass
  • npx vitest run src/ghidra: 243 passed
  • npm run test:focused -- tests/boundary/mcp/ghidraEvidenceMcp.test.ts tests/boundary/providers/ghidra/{ghidraClient,ghidraTransport,ghidraTargetSnapshot}.test.ts: 4 files, 38 passed
  • npm run check:fast: pass (pre-commit oxfmt/oxlint also pass)
  • Manual MCP stdio run against real Ghidra 12.1.4: output shown above.
  • npm run verify:ghidra (real provider) did not pass locally, and the failure does not look related to this change:
    • With the patch, the entry-aliases scenario failed in close_binary with cleanup_incomplete: owned launcher command identity did not match (observed=[java]; expected=.../bin/java). This looks like a shutdown race where the JVM is already defunct when the ownership check reads it.
    • The unpatched base commit timed out locally after 25 minutes without finishing.
    • Another Ghidra session was running on the machine at the same time, so I'd rely on CI for this suite.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A custom bridge that pins the old capability list would fail the exact handshake, as with any capability addition.
  • Real Hopper/Ghidra, browser, or OS coverage: Ghidra 12.1.4 with Temurin JDK 21 on Arch Linux x64. No Hopper or macOS.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: only session-database metadata is written; source bytes are untouched; Windows P0 is unaffected.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

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.
@morluto

morluto commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thanks for your first PR, @giri256, and welcome to REA! 🎉 This is a useful addition—compact naming for Ghidra function entries and globals makes the investigation workflow much smoother. I appreciate the detailed write-up, regression coverage, and real-provider verification. I've pushed fixes for the two namespace edge cases found during review, along with regression coverage. Thanks again for contributing!

@morluto
morluto merged commit 6e0d5d6 into morluto:main Oct 10, 2026
9 checks passed
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The new rename tools work on Linux with Ghidra. I renamed functions and data, one at a time and in a batch. The names showed up in the decompiled code.

I checked main at 0f605bca9 (#1602), which includes 6e0d5d6 (#1635). The target was a small x86-64 ELF built with gcc. It had three functions and two globals.

Results

Check Result
Focused tests (3 files) 38 passed
Rename a function entry true. The decompiled code shows the new name
Rename a data address true. It becomes a primary label
Rename three addresses at once all true
Read the names back new names in both tools
Unmapped address, one call error: address not mapped
Unmapped address inside a batch false for that address. The valid one still applied
Empty name, and an empty batch rejected by the input schema
Name with spaces false
Tool list after a failed rename both tools still listed
Close and reopen original names return
npm run verify:ghidra passed

The reopen result matches the stated limit. Edits are not saved in a Ghidra project.

I saw two small things that may surprise a caller.

  • A duplicate name worked. Two functions both named dup_name each returned true. Two data labels did the same. The decompiled code then calls both dup_name. The PR text says a duplicate name returns false, so this differs from it, at least in the global namespace.
  • The name ns:: returned true on a function in the global namespace. Ghidra stored it as a literal name. The empty-name check only runs inside a named namespace.

Not run

  • Windows, macOS, or any PE target.
  • Hopper and IDA.
  • Names in a C++ namespace, except through the repo's own verify:ghidra lane. I did not probe them by hand.

Thanks, Giridhar, for the feature. Thanks, morluto, for the namespace fixes.

Test setup

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Ghidra: admit set_address_name / set_addresses_names

3 participants