-
Notifications
You must be signed in to change notification settings - Fork 72
Decompilation Tidbits
The O2 document should generally be referred to for helpful information. https://hackmd.io/vPmcgdaFSlq4R2mfkq4bJg#
However, figuring out where to stick new ideas into that doc is kinda. Well. I don't want to mess with it too much.
The idea of this page is to be able to just use it as a basic notepad. Throw down ideas and later merge them into the O2 doc when they feel fleshed out enough.
The following for loop code will often be optimized to what looks like pointer iteration. There's a few hints we need to look at.
s8 array[0x100];
s32 unrelatedSymbol;
void foo(void) {
for (i = 0; i < 0x100; i++) { print(array[i]); }
}
The above often becomes optimized into:
s8 array[0x100];
s32 unrelatedSymbol;
void foo(void) {
for (ptr = &array[0]; ptr != &array[0] + 0x100; ptr++) { print(*ptr); }
}
Them mips to C will output the code similar to (The bitwise of which is identical):
s8 array[0x100];
s32 unrelatedSymbol;
void foo(void) {
for (ptr = &array[0]; ptr != &unrelatedSymbol; ptr++) { print(*ptr); }
}
So if you ever see:
do {
sym += a_number // ex. 0x34, 0xD, etc.
} while ( != &address)
The a_number likely refers to a struct or array size. And the &address is a compiler generated symbol. (also, the sym is likely not used anywhere else in the project but it can by coincidence line-up with another symbol/variable/address but have no relation to that address.