5 ms·
I'm not aware of any good general-case automation for this. When I've done this in the past, it basically consists of: 1) Decompile project using Ghidra/IDA,
by bri3d 5y ago
I'm not aware of any good general-case automation for this.
When I've done this in the past, it basically consists of:
1) Decompile project using Ghidra/IDA, first pass.
2) Load symbols if present (sounds like there was a PDB for this one, which makes things a lot easier).
3) Read decompilation/asm for unnamed subs and try to name them based on what they do.
4) Export all decompiled source into an editor and start copy/paste/editing into readable source. Highly manual process, for some files it's just pattern matching / renaming and goes really quickly, for others it's full reimplementation and a bit harder.
And, if you look at most "decompiled game" projects, I think this is the industry standard way to do this. For example, OpenRCT2 started as a repository full of manually created source with Hex-Rays names and slowly evolved module-by-module into readable source code. (disclosure: per the child post, my original assumption that OpenRCT2 was copied out of Hex-Rays was inaccurate, since it was originally written in assembler it didn't follow a standard C ABI and the decompiler wouldn't work properly anyway).
- gavinray 5y ago> sounds like there was a PDB for this one, which makes things a lot easier Ah yeah that certainly reduces the difficulty by an order of magnitude. Do you know of anyone who has done this with high-skill as a recorded video tutorial? Seems like one of those things much easier to follow in video than text due to how complicated IDA/Ghidra are as tools.
- bri3d 5y agoCheck out `wrongbaud` tutorials: https://hackaday.io/course/172292-introduction-to-reverse-engineering-with-ghidra https://hackaday.io/course/172292-introduction-to-reverse-en... . wrongbaud's are the best trainings I've seen for Ghidra so far. I actually haven't watched this particular course (I confused it with some other ones) - but given what I've seen, I'm sure it's good.
- gavinray 5y agoThanks a ton for the point in the right direction!
- duncanspumpkin 5y agoFor OpenRCT2 thats not quite how we did it. We didn't use IDA decomp output as its useless with Chris Sawyer calling conventions you had to just read the assembly. We did name things as per IDA when things were completely unknown hence why there was lots of sub_XXXX functions and byte_XXXX. I personally just used OllyDbg and read the assembly and wrote equivalent C code. I've a few videos of implementing functions for OpenRCT2 and OpenLoco if you are interested.
- bri3d 5y agoI stand corrected - I'll check them out! It makes sense that the Sawyer calling conventions wouldn't decompile correctly, since he was just making the ABI up as he programmed.