ghidra icon indicating copy to clipboard operation
ghidra copied to clipboard

ExportToHeaderAction: replace special chars with underscores like in ExportToCAction

Open mattiasgrenfeldt opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. When I export decompiled code to a file using the ExportToCAction, strange characters in type names (like ., [, ], and /) are replaced by underscores (_). But when I export my data type archive using the ExportToHeaderAction in the data type manager, the same replacement doesn't happen.

It seems like the replacement in the ExportToCAction action happens here in the PrettyPrinter class: https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/PrettyPrinter.java#L103-L108

Describe the solution you'd like The same type names appearing in both places, with strange characters replaced by underscores. I want this so that I can concatenate the two files and send them to a C parser.

Describe alternatives you've considered The alternative I'm going for at the moment is to simply not have strange characters in my type names.

mattiasgrenfeldt avatar Apr 20 '23 12:04 mattiasgrenfeldt

I discovered a related issue. When the PrettyPrinter prints the function prototype, it does not do the normalization either. This can be seen in the function findSignature which directly follows the print function mentioned above: https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/PrettyPrinter.java#L117-L129

The consequence of this is that when you use the CppExporter class (https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Decompiler/src/main/java/ghidra/app/util/exporter/CppExporter.java) with isCreateHeaderFile set to true, function prototypes will be printed to the exported .h-file, with invalid characters in the function names.

mattiasgrenfeldt avatar Apr 27 '23 12:04 mattiasgrenfeldt