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).
> 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.
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.
> " The thing you do then is go through each function it produces and fix up the names and maybe re-organize it to be more readable."
How do you do this, when most of the code is like (real fn decompilation from random binary opened with Ghidra v10.0.4 for example's sake just now): undefined8 FUN_14004dd60(longlong *param_1)
{
if ((((*param_1 != 0) && (param_1[1] != 0)) && (param_1[2] != 0)) &&
((param_1[0x2b] != 0 && (*(longlong *)(param_1[0x2b] + 0x28) != 0)))) {
if (*(char *)((longlong)param_1 + 0x21) != '\0') {
return 0;
}
(**(code **)(param_1[1] + 0x18))();
*(undefined *)((longlong)param_1 + 0x21) = 1;
return 1;
}
return 0;
}
This program is 14MB, and Ghidra says: # of Functions: 12661
# of Symbols: 118504
# of Data Types: 6513
It just seems unapproachably daunting.(Serious question, not being passive-aggressive. I find this stuff interesting and wish I understood it more.)
And actually then thinking about the way it's calling it, i'm wondering if this is actually from some C++ standard library code for doing stuff with a vtable, looking up the vtable entry and checking it's validity before calling it (in this case, location 0x18, and checking some kind of RTTI at 0x28 and 0x2b) and storing that it's been initialized in 0x21. So I think this might be part of an initialization function for some property on top of a object that exists at *param_1. and the decompiler has misinterpreted it as a longlong because of the access patterns (64bit pointers).
This looks nothing like the pseudocode C that IDA/Ghidra spit out, so how would you go about doing this even?
It says in the README:
Which is a bit "Draw-the-rest-of-the-fucking-owl" for me. Or am I just clueless.