ghidra icon indicating copy to clipboard operation
ghidra copied to clipboard

Defining structures and enums using C (similar to functions)

Open chibicitiberiu opened this issue 6 years ago • 3 comments

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

chibicitiberiu avatar Sep 11 '19 16:09 chibicitiberiu

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.

fmagin avatar Nov 16 '19 19:11 fmagin

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

Picture of Script GUI

fmagin avatar Nov 17 '19 16:11 fmagin

This would be great.

zkxjzmswkwl avatar Nov 18 '24 16:11 zkxjzmswkwl