Skip to content

Conversation

@Sumandora
Copy link

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"
image
Bool was redefined and that made my C++ compiler unhappy and even a modern C23 compiler would choke on this
image
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.

This removes all float declarations by default.
The default float gets its own getCTypeDeclaration override in the
attempt of stating intent more clearly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant