Skip to content

Fix CParserUtils.parseSignature API for Ghidra 11+#11

Open
andresj-sanchez wants to merge 1 commit intoakiselev:masterfrom
andresj-sanchez:fix-cparserutils-parse-signature-ghidra-11
Open

Fix CParserUtils.parseSignature API for Ghidra 11+#11
andresj-sanchez wants to merge 1 commit intoakiselev:masterfrom
andresj-sanchez:fix-cparserutils-parse-signature-ghidra-11

Conversation

@andresj-sanchez
Copy link
Copy Markdown

@andresj-sanchez andresj-sanchez commented Mar 23, 2026

Fix CParserUtils.parseSignature API compatibility for Ghidra 11+

Fixes #10

Problem

GhidraCliBridge.java fails to compile under Ghidra 11.x with the following errors:

  • parseSignature(GhidraCliBridge, Program, String)GhidraScript does not implement ServiceProvider, so passing this is invalid.
  • parseResults.getDataType()CParseResults no longer has a getDataType() method; parseSignature now returns FunctionDefinitionDataType directly.

This causes the bridge to fail at startup with a ClassNotFoundException.

Fix

  • Replace CParserUtils.CParseResults with FunctionDefinitionDataType as the return type.
  • Pass state.getTool() instead of this as the ServiceProvider argument — the Ghidra tool properly implements ServiceProvider and allows the parser to resolve data types correctly.

Before

ghidra.app.util.cparser.C.CParserUtils.CParseResults parseResults =
    ghidra.app.util.cparser.C.CParserUtils.parseSignature(
        this, currentProgram, sigStr);

if (parseResults == null || parseResults.getDataType() == null) {
    return errorResult("Failed to parse signature: " + sigStr);
}

FunctionDefinition funcDef = (FunctionDefinition) parseResults.getDataType();

After

ghidra.program.model.data.FunctionDefinitionDataType funcDef =
    ghidra.app.util.cparser.C.CParserUtils.parseSignature(
        state.getTool(), currentProgram, sigStr);

if (funcDef == null) {
    return errorResult("Failed to parse signature: " + sigStr);
}

Tested on

  • Ghidra 11.4 DEV — ghidra start and ghidra function list work correctly.

Note: This fix was written with AI assistance and manually verified by a human on Ghidra 11.4 DEV. Other Ghidra versions have not been tested.

Since the README states Ghidra 10.0+ is supported, it's worth verifying whether the CParseResults-based API was already gone in 10.x or if this fix would be a breaking change for those users.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 resolves critical compilation and runtime issues in GhidraCliBridge.java when used with Ghidra 11.x and newer versions. The changes specifically adapt the code to breaking API modifications in Ghidra's CParserUtils.parseSignature method, ensuring the bridge can correctly parse function signatures and operate as intended in the updated environment.

Highlights

  • API Compatibility: Updated the CParserUtils.parseSignature API call in GhidraCliBridge.java to ensure compatibility with Ghidra 11+, addressing breaking changes in the CParseResults return type and the ServiceProvider argument.
  • Return Type Change: Replaced the use of CParserUtils.CParseResults with FunctionDefinitionDataType as the direct return type from parseSignature, reflecting the updated Ghidra API.
  • ServiceProvider Argument: Modified the ServiceProvider argument passed to parseSignature from this (GhidraScript) to state.getTool(), as GhidraScript no longer implements ServiceProvider in Ghidra 11+.
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.

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.

Copy link
Copy Markdown

@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 correctly addresses the API changes in Ghidra 11+ for CParserUtils.parseSignature. The changes are logical and well-documented in the pull request description. I have one minor stylistic suggestion to improve code readability.

Comment on lines +2541 to +2543
ghidra.program.model.data.FunctionDefinitionDataType funcDef =
ghidra.app.util.cparser.C.CParserUtils.parseSignature(
this, currentProgram, sigStr);
state.getTool(), currentProgram, sigStr);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For improved readability and to leverage the existing wildcard import import ghidra.program.model.data.*;, you can use the simple class name for FunctionDefinitionDataType instead of the fully qualified name.

Suggested change
ghidra.program.model.data.FunctionDefinitionDataType funcDef =
ghidra.app.util.cparser.C.CParserUtils.parseSignature(
this, currentProgram, sigStr);
state.getTool(), currentProgram, sigStr);
FunctionDefinitionDataType funcDef =
ghidra.app.util.cparser.C.CParserUtils.parseSignature(
state.getTool(), currentProgram, sigStr);

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.

ghidra-cli fails to start on Ghidra 12 - Java Syntax Error & OSGi Hidden Directory

1 participant