Improve the ExportToHeader action #8481
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I recently wanted to make a cheat for a video game for educational purposes and the lolz of course.


I decided that I want to use Ghidras type system more than I used to, but realized that the ExportToHeaderAction has several flaws, for one there was a bogus float16 "declaration"
Bool was redefined and that made my C++ compiler unhappy and even a modern C23 compiler would choke on this
and by far the most annoying problem: structs were not packed.
This actually caused some frustration when I didn't realize why the offsets were different to what Ghidra reported.
These commits should fix these problems.
Bool is now only declared if you use an old C compiler.
Fixed-size floats are not redeclared at all, a comment correctly stated that the declaration is different on each platform, however it still emitted the name as the declaration which caused the bogus float16 typedef that literally just said the type name and nothing else. For now fixed-size floats don't get a declaration, someone who uses them can easily declare them manually.
And the structs are now packed. I use MSVC-style pragmas here, because GCC and LLVM/Clang both support MSVCs approach, but MSVC doesn't support the others (
[[gnu::packed]]or__attribute__((packed))), which in a rare case of circumstances makes MSVCs approach the most portable. I believe that there should be export options to control this, but that would've probably made this PR a lot bigger than it would need to be.This does not just allow GCC and Clang to parse Ghidras headers without modification but also allows Ghidra to parse its own headers. Although I should add that this is more or less anecdotal because I have not tried to feed a testset through it, so there may be edge cases that I haven't noticed.