Closed InusualZ closed 2 years ago
Looks like we don't recognize that r5 is an argument to sprintf, so we optimize it out. Knowing which registers to pass as arguments to functions on ppc is difficult in general, unfortunately, though we should be able to add a heuristic that captures this particular case based on the deduction that the register is not used in any other way.
Ohh, I see.
I changed the function definition to:
void sprintf(char* __s, char* __format, unsigned int d); // @8045decc
from:
void sprintf(char* __s, char* __format, ...); // @8045deccZ
And now it "work"
Maybe you can see also check if the function is variadic
And have variadic functions consume all the registers they can? Yeah, that's not unreasonable. Will lead to false positives but that may be okay given variadic functions are a rare case.
consume all the registers they can
I don't know if possible, but you can exclude most registers that haven't being touched since the last call to a function (before the call to the variadic)
Yeah, we already take into account function calls clobbering registers and such. But argument registers are very often used as temps, and called unknown functions are treated as writing to r3/r4/f1.
Fixed in 008adfcf9afeb0ea6df2cbee3d2351c832cd0bef (for variadic functions, lmk if this generates too many false positives and I can back it out) and 6b6e1390bf30013247343623194964ff13d0c45b (for functions not in context, based on the "unread register" heuristic).
Thank you, seems to be working correctly as far as I can see.
Sorry about the tittle, I don't know enough about how the decompiler works so I went with what I understand is happening
m2c output
Ghidra Output
arguments
input.s context.c