Skip to content

FunctionSignatureParser does not handle calling convention #8831

@DrFrugalOfficial

Description

@DrFrugalOfficial

Describe the bug
The class FunctionSignatureParser is used for parsing a C-style function signature string into it's FunctionSignature representation via the parse method.
For the easy signatures without explicit calling convention this works well, as far as I tested it, but as soon as a calling convention is passed, the script errors.
The root cause is most likely the handling in extractReturnType not expecting calling conventions in the String, and parse not handling them at all.

To Reproduce
Run the following Java GhidraScript:

FunctionSignatureParser fsp = new FunctionSignatureParser(currentProgram.getDataTypeManager(), null);
FunctionSignature fs = fsp.parse(null, "void* __cdecl test(void * arg0)");
println("sig: " + fs.toString());

You should see an error pop up like this:

Can't resolve return type: void* __cdecl
ghidra.app.util.cparser.C.ParseException: Can't resolve return type: void* __cdecl
	at ghidra.app.util.parser.FunctionSignatureParser.extractReturnType(FunctionSignatureParser.java:267)
	at ghidra.app.util.parser.FunctionSignatureParser.parse(FunctionSignatureParser.java:114)
	at DrFrugal.run(DrFrugal.java:39)
	at ghidra.app.script.GhidraScript.executeNormal(GhidraScript.java:460)
	at ghidra.app.script.GhidraScript.doExecute(GhidraScript.java:314)
	at ghidra.app.script.GhidraScript.execute(GhidraScript.java:290)
	at ghidra.app.plugin.core.script.RunScriptTask.run(RunScriptTask.java:46)
	at ghidra.util.task.Task.monitoredRun(Task.java:134)
	at ghidra.util.task.TaskRunner.lambda$startTaskThread$0(TaskRunner.java:106)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)

---------------------------------------------------
Build Date: 2025-Dec-05 1355 EST
Ghidra Version: 12.0
Java Home: C:\Program Files\Amazon Corretto\jdk21.0.5_11
JVM Version: Amazon.com Inc. 21.0.5
OS: Windows 11 10.0 amd64
Workstation: KARAZHAN

Expected behavior
The parse function can handle the available calling conventions (the string for unknown / default would be good to be handled too).
In case of the calling convention not being present in the string, it should use the default as it is already doing.

Screenshots
not needed

Attachments
not needed

Environment (please complete the following information):

  • OS: Windows 11 25H2 26200.7462
  • Java Version: 21.0.5_11
  • Ghidra Version: 12.0
  • Ghidra Origin: official GitHub distro

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions