Skip to content

feat: add data type creation, function signatures, and namespace support#8

Open
encounter wants to merge 2 commits intoakiselev:masterfrom
encounter:feat/type-recovery-and-signatures
Open

feat: add data type creation, function signatures, and namespace support#8
encounter wants to merge 2 commits intoakiselev:masterfrom
encounter:feat/type-recovery-and-signatures

Conversation

@encounter
Copy link

Summary

Adds commands to define Ghidra data types using C syntax, adjust function prototypes, and organize symbols into namespaces.

  • Add type import-c command to parse and import C type definitions (structs, unions, enums, typedefs)
  • Add function set-signature command to apply C-style function prototypes (with calling convention support)
  • Enhance symbol rename to support namespace assignment via Ns::Name syntax and --namespace flag
  • Normalize bridge command naming to {entity}_{action} pattern

New Commands

type import-c

Parses C type definitions and imports them into the program's data type manager. Supports structs, unions, enums, typedefs (including function pointers), bitfields, and struct inheritance.

# Import to root category
ghidra type import-c 'struct Vec3 { float x; float y; float z; };'

# Import into a named category
ghidra type import-c --category /CTimer \
  'struct CTimer;
   typedef void (*CTimer_dtor)(CTimer *this, short flags);
   struct CTimer_vtable { void *rtti0; void *rtti1; CTimer_dtor dtor; };
   struct CTimer { CTimer_vtable *vtable; int state; float timer; };'

function set-signature

Parses a C-style function prototype and applies it to the target function, including return type, parameters, calling convention, and name.

ghidra function set-signature 0x401000 'void __thiscall Update(float dt, int flags)'
ghidra function set-signature 0x401000 'int __cdecl ParseConfig(char *path, int flags)'

Enhanced symbol rename

Now accepts an address or name as target, and supports namespace assignment in a single operation.

ghidra symbol rename 0x401000 MyClass::Update       # rename + set namespace
ghidra symbol rename 0x401000 Update --namespace MyClass  # equivalent
ghidra symbol rename 0x401000 Update --namespace ''  # move to global namespace
ghidra symbol rename old_label new_label             # rename by name (non-primary labels supported)

Internal Changes

  • Renamed bridge commands from list_functions/get_function/etc. to function_list/function_get/etc. for consistency with the symbol_*/type_*/comment_* pattern
  • Removed handleRenameFunction — function renaming now routes through symbol_rename
  • Added findUniqueSymbolByNameOrAddress() helper used by both symbol_rename and symbol_delete
  • Added createNamespaceHierarchy() for creating nested A::B::C namespaces

Tests

  • test_symbol_rename_non_primary_label_by_name — verifies renaming targets the correct label, not the primary symbol at the same address
  • test_type_import_c_category_keeps_existing_same_named_types — verifies importing same-named types into different categories doesn't clobber existing ones

Add type import-c command for parsing C type definitions into Ghidra's
data type manager with optional category placement. Add function
set-signature command for applying C-style function prototypes including
calling conventions. Enhance symbol rename to accept address or name
targets and support namespace assignment via Ns::Name syntax or
--namespace flag.

Normalize bridge command naming to {entity}_{action} pattern. Remove
handleRenameFunction in favor of routing through symbol_rename. Add
findUniqueSymbolByNameOrAddress and createNamespaceHierarchy helpers.
@gemini-code-assist
Copy link

Summary of Changes

Hello @encounter, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the Ghidra CLI's capabilities for reverse engineering and program analysis. It introduces powerful new commands for defining complex C data types, precisely setting function signatures with calling conventions, and organizing symbols within namespaces. These additions streamline the process of enriching Ghidra projects with recovered type information and better structured symbols, making the CLI a more robust tool for automated analysis workflows.

Highlights

  • New type import-c Command: Introduced a new command to parse and import C-style data type definitions (structs, unions, enums, typedefs, bitfields, and struct inheritance) directly into Ghidra's data type manager, with support for organizing types into specific categories.
  • New function set-signature Command: Added a command to apply C-style function prototypes to target functions, including return types, parameters, and calling conventions such as __thiscall, __cdecl, __stdcall, and __fastcall.
  • Enhanced symbol rename Command: The symbol rename command now supports namespace assignment using either Ns::Name syntax or an explicit --namespace flag, allowing symbols to be moved to the global namespace or nested namespaces. It also correctly handles renaming non-primary labels by name.
  • Standardized Bridge Command Naming: Internal Ghidra bridge commands have been refactored to follow a consistent {entity}_{action} naming pattern (e.g., function_list, type_import_c), improving clarity and maintainability.
Changelog
  • .claude/skills/ghidra-cli/SKILL.md
    • Updated function command documentation to replace rename with set-signature and add details for set-signature.
    • Updated symbol rename documentation to reflect new TARGET and NEW_NAME arguments, and --namespace flag.
    • Added type import-c command documentation with examples for importing to root and specific categories.
    • Updated example workflow to include type import-c, symbol rename for namespace, and function set-signature.
  • README.md
    • Added "Type recovery", "Function prototypes", and "Symbol management" to the feature list.
    • Updated example commands for function set-signature, symbol rename (with namespace), and type import-c.
    • Expanded the example AI agent workflow to demonstrate the new type recovery and function prototyping steps.
  • src/cli.rs
    • Added SetSignature subcommand to FunctionCommands with target and signature arguments.
    • Modified RenameArgs to use target instead of old_name and added an optional namespace argument.
    • Added ImportC subcommand to TypeCommands with code and optional category arguments.
  • src/ghidra/scripts/GhidraCliBridge.java
    • Imported necessary Ghidra classes for CParser, ApplyFunctionSignatureCmd, and FunctionRenameOption.
    • Removed old list_functions, get_function, rename_function, create_function, delete_function dispatch cases.
    • Added new dispatch cases for function_list, function_get, function_create, function_delete, function_set_signature, and type_import_c.
    • Renamed handleListFunctions to handleFunctionList.
    • Renamed handleGetFunction to handleFunctionGet.
    • Removed handleRenameFunction (function renaming now goes through symbol_rename).
    • Renamed handleCreateFunction to handleFunctionCreate.
    • Renamed handleDeleteFunction to handleFunctionDelete.
    • Modified handleSymbolDelete to use findUniqueSymbolByNameOrAddress and return address.
    • Modified handleSymbolRename to accept target (address or name), parse newName for :: namespaces, and handle an explicit namespace argument.
    • Added createNamespaceHierarchy helper function to create nested namespaces.
    • Added handleTypeImportC to parse C code, import types, and optionally move them to a specified category.
    • Added handleFunctionSetSignature to parse C function signatures, apply them to functions, and handle __thiscall convention.
    • Added helper methods findUserDataTypes, isUserFacingDataType, findBestParsedDataType, findBestDataType for type management.
    • Added findUniqueSymbolByNameOrAddress to resolve symbols by name or address, handling ambiguity.
  • src/ipc/client.rs
    • Updated list_functions command name to function_list.
    • Modified symbol_rename to accept target, new_name, and namespace arguments.
    • Added type_import_c client method.
    • Added function_set_signature client method.
  • src/main.rs
    • Updated extract_project_from_command and extract_program_from_command to include SetSignature and ImportC commands.
    • Modified execute_via_bridge to correctly dispatch function_get, function_create, function_delete with new names.
    • Modified execute_via_bridge for FunctionCommands::Rename to call client.symbol_rename with new arguments.
    • Added dispatch logic for FunctionCommands::SetSignature and TypeCommands::ImportC.
  • tests/symbol_tests.rs
    • Added unique_suffix helper for generating unique test names.
    • Added test_symbol_rename_non_primary_label_by_name to verify renaming of non-primary labels.
  • tests/type_tests.rs
    • Added unique_suffix helper.
    • Added test_type_import_c_category_keeps_existing_same_named_types to ensure category-based type imports don't clobber existing types.
Activity
  • New commands type import-c and function set-signature were introduced.
  • The symbol rename command was enhanced to support namespaces.
  • Internal bridge command naming was standardized for consistency.
  • Several new tests were added to cover the new symbol rename behavior and type import-c functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@encounter
Copy link
Author

encounter commented Feb 24, 2026

Apologies for the LLM-y PR description, just wanted to quickly note that I (a human) was actively and carefully iterating on the design and details here. Let me know what you think!

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant new features, including C-style data type creation, function signature updates, and namespace support for symbols. The implementation is robust and includes corresponding documentation and test updates. I have a couple of suggestions to improve API consistency for symbol operations and to make the handling of the __thiscall calling convention more robust. Overall, this is an excellent set of enhancements.

…x for __thiscall

Change symbol_delete JSON key from "name" to "address" to match
symbol_rename. Use \b word boundaries when stripping __thiscall to
avoid matching substrings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant