-
Notifications
You must be signed in to change notification settings - Fork 25
Implement Microsoft COFF exporter #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Ooh neat!
Yeah, delinking tends to do that to one's mind. I don't know what it would do to a CS101 teacher's mind, but I expect either some pretty fireworks or a one-way trip to a psychiatric hospital.
I definitely want to merge this once it's ready. I expected that object file formats and ISAs to be mostly orthogonal, which is why I went for exporting object files rather than assembly when designing my tooling. This PR proves my theory. Overall the code itself looks fairly good for a first draft. I'll add code comments later today, but I have some general observations:
I can deal with these issues myself if you need (and in particular I'll handle the tests myself, I need to make some adjustments to the test harness to support COFF anyways). This is the first ever non-trivial PR I'm receiving on one of my repositories, so this is kind of uncharted territory for me. I'll try to make the process as smooth as possible.
|
|
I'm rebasing right now. As for the CI failure... Apparently, Ghidra prior to a very recent version had an annoying typo in the |
boricj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fairly good so far, here's the list of changes needed before I can merge this.
src/main/java/ghidra/app/util/exporter/CoffRelocatableObjectExporter.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/CoffRelocatableObjectExporter.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/CoffRelocatableObjectExporter.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/CoffRelocatableObjectExporter.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/coff/CoffRelocatableSymbolAux.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/coff/CoffRelocatableSymbolAuxFile.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/coff/CoffRelocatableSymbolAux.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/coff/CoffRelocatableSymbolAux.java
Outdated
Show resolved
Hide resolved
src/main/java/ghidra/app/util/exporter/coff/CoffRelocatableSymbolTable.java
Outdated
Show resolved
Hide resolved
Yeah, at some point I'll need to revisit the range of Ghidra versions I should support, going all the way back to 10.3 probably no longer makes sense now. I'm fine with dropping |
0feeaa5 to
b543dc1
Compare
|
OK, tried to address all of that. Just ran through it and I think I got the last of it. I'd be interested in getting this working with MIPS and other systems too, though yeah I'd favor keeping it out of the scope of this particular PR, since it's already pretty large. Let me know if there's anything else you spot before merging. I checked with Organize Imports and spotless and I think all of the formatting issues are resolved. |
|
It looks like tests are passing, but I think because its running from a fork PR it is running into some kind of permission issue? Not 100% sure. |
Sure, the MIPS relocation type mapper can come later, it's not necessary for x86 operation. My ELF object file exporter can tolerate a missing relocation mapper (no relocation would be emitted in that case), I won't require that from the COFF object file exporter before merging it.
It should be fine. I've seen some opportunities to harmonize and refactor code with the ELF exporter, but I won't require these to be addressed before merging. In fact, I will probably wait until I have a third object file exporter before doing that, it's still not obvious what would be actually good candidates for refactoring.
The tests do pass, they only cover the existing ELF exporter and relocation synthesizers, nothing covers the COFF exporter yet. It seems that the test report artifacts can't be created inside the GitHub Actions run itself. It looks like I'll have to set up a split workflow on my end to fix this. I'll ping you when it's done (I'll need that PR rebased on top of master for a linear history before merging, but there's no need to do that as long as I haven't sorted this out). |
f8ee82a to
b6e21aa
Compare
|
You can try rebasing your PR on top of the master branch. I think it's sorted out, but the runs on the PR won't use the updated workflows on my master branch as-is. |
|
Rebased. Looks like the workflow still needs to be approved though. FWIW, if you want to merge this some other way outside the normal GitHub PR flow, feel free. |
|
Looks like everything's sorted out. I'll merge the PR tomorrow (it's getting a bit late here), after playing with the COFF exporter on my side for a bit. |
|
I rebased and merged it into master. Fixing the I'll look into adding some COFF tests and maybe add the MIPS relocation type mapper myself. |
|
Oh, that's cool, thanks! I'm using NixOS unstable which is currently on Ghidra 11.0.3 still, so I think I'll need to wait a couple weeks most likely. That said, it's not too big of a deal since in the meantime I can continue using my local version. |
|
This is so cool, nice! |
About a month ago you mentioned on Hacker News that adding COFF support should be easy and fairly self-contained. You were right.
This is an implementation of the delinker exporter that outputs the Microsoft COFF format. It's still very rough around the edges but I was able to use it to successfully delink and relink an i386 Windows executable. Interestingly, with some careful delinking, I can take a program compiled by MSVC for Windows, delink it to ELF and relink it with glibc to make it run on Linux, and delink it to COFF and relink it with MinGW to make it run on Windows again. 🤯
Feel free to leave a lot of comments. I can try to address comments, though I may take a bit depending on how busy I am. Not sure if you want to merge this upstream but I'm eager to get delinking into the world of Windows reverse engineering as it seems extremely promising for a wide variety of reverse engineering tasks.
Some notes: