NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
50.53k stars 5.78k forks source link

Export data as C code #2635

Open MatrixM9 opened 3 years ago

MatrixM9 commented 3 years ago

Is your feature request related to a problem? Please describe. Currently when using Export Programm data, such as global variables is not exported alongside the functions. Exporting this information as well would be very valuable for the user.

For example creating C code for arrays, structure initializations, simple value assignments etc.

Describe the solution you'd like Add an option to Export Programm to also export the data as C code.

Describe alternatives you've considered Writing a script to automate this or exporting the data by hand.

loneicewolf commented 3 years ago

I agree with @MatrixM9 , This is something I would like to see. It would make the job easier for many.

Have a great week both @MatrixM9 And @NSA!

//Will

astrelsky commented 3 years ago

An alternative would be to add a copy special for this.

Maybe this could be done via extension point so that users could add their own to format it in the language of their choice.

pabx06 commented 3 years ago

exporting data/structure that you have defined in the listing. would be nice. use case: you want to export an array of 200 bytes used for crypto routines. for later use...

astrelsky commented 3 years ago

exporting data/structure that you have defined in the listing. would be nice. use case: you want to export an array of 200 bytes used for crypto routines. for later use...

You can copy as C code now. Have you tried it out?

pabx06 commented 3 years ago

exporting data/structure that you have defined in the listing. would be nice. use case: you want to export an array of 200 bytes used for crypto routines. for later use...

You can copy as C code now. Have you tried it out?

1616946682846646603554126274967 I tried all the above However the array of struct i am trying to copy has components like strings (char *) and int. The strings doesn't get copied out.. primitive are 👌 but pointer pointee doesn't

EuanKirkhope commented 2 years ago

If you clone snapshot the listing view, press the edit listing button, then setup as below:

exportvars

The text fields are spacer fields, then right click on it and select "Set text".

Unselect the edit listing, and you can then cut and paste the text into a text editor and it gets you 90% of the way there. Doesn't work to well for large byte arrays due the dreaded ellipsis' (...) but is a good start

Also needs a script or manual clean up of empty padding bytes

wothke commented 2 years ago

An alternative would be to add a copy special for this.

Maybe this could be done via extension point so that users could add their own to format it in the language of their choice.

It is just plain annoying that the existing "Export program C/C++" function does not export the global variables that the exported functions actually use. It is all the more frustrating after having spent all that time manually configuring the correct data types and even giving labels to those vars. Obviously it is a bug of the existing export C/C++ functionality that it completely "forgets" to export the global variables that it uses (whether or not there should be even additional export format features seems to be an academic question as long as that existing bug hasn't been fixed)

PS: the "existing workarounds" are just useless garbage: manually selecting and copy/pasting respective labels is sabotaged by the editors silly auto-selection-expansion which forces you to cleanup all the unwanted extra text that the editor forces you to copy. The "Special copy" options are totally useless with regard to types like doubles (etc). I find it very surprising (and sad) that one year after the original bug report nothing seems to have been improved regarding this very unsatisfactory situation. :-(

IceTDrinker commented 2 years ago

where should one look to try to add some form of export for these globals ?