Ghidra: Defining structures and enums using C (similar to functions)

Created on 11 Sep 2019  路  2Comments  路  Source: NationalSecurityAgency/ghidra

Is your feature request related to a problem? Please describe.
Defining a structure or an enum using the GUI is a painstaking process. For example, I see that a library was used, and I can find the library's headers. Since the "Parse C headers" functionality is a bit temperamental, I would like to simply import a single structure or enum, similar to how the function editor works.

The only way I can do that today is to create a header file, put just that one structure, and then import using the "Parse C headers" function. It takes too much time.

Describe the solution you'd like
It would be nice to have a simple parser (similar to the one used for defining functions), for parsing a structure from a simplified C-like syntax.

Describe alternatives you've considered
I was thinking about a "define new type" functionality which can parse typedefs, structs, enums and functions, all in a single "import" window. But that's a bit more complicated.

Additional context

Data Types Enhancement

Most helpful comment

I wrote a small script that somewhat achieves this. The basic idea is that you can just instantiate a CParser with your current datatype manager and let it parse arbitrary strings. I don't know much about Java GUIs and the only thing I found is the AskString dialog, but when in a hurry this should still be better and faster then the "Parse C headers" way.

I didn't need this feature directly so this script is still extremely simplistic but hopefully serves as an example that this is not actually that hard to do.

All 2 comments

I wrote a small script that somewhat achieves this. The basic idea is that you can just instantiate a CParser with your current datatype manager and let it parse arbitrary strings. I don't know much about Java GUIs and the only thing I found is the AskString dialog, but when in a hurry this should still be better and faster then the "Parse C headers" way.

I didn't need this feature directly so this script is still extremely simplistic but hopefully serves as an example that this is not actually that hard to do.

Extended this to be a proper GUI and renamed it because it actually handles all data types.

Picture of Script GUI

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tzizi picture tzizi  路  17Comments

0x6d696368 picture 0x6d696368  路  18Comments

0x6d696368 picture 0x6d696368  路  19Comments

SocraticBliss picture SocraticBliss  路  26Comments

lab313ru picture lab313ru  路  16Comments