I am using IDA pro 6.95 (paid version) to RE some PowerPC code. The PowerPC normally uses r1
as the stack pointer, so IDA builds the stack frame and local variables from r1
. Parameters are passed in r3
, r4
, r5
, etc. The problem I am having that I see this:
.text: foo:
.text:.set back_chain, -0x30 // Stack frame
.text: .set var_4, -4
.text: .set sender_lr, 4
<<<function preamble snipped>>>
.text: mr r31, r1 // Copy stack pointer to r31
.text: stw r3, 8(r31) // All local variables are relative
.text: stw r4, 0xC(r31) // to r31, instead of r1, so IDA
// doesn't recognize them.
And I want to see this:
.text: foo:
.text:.set back_chain, -0x30 // Stack frame
.text: .set var_C, -C
.text: .set var_8, -8
.text: .set var_4, -4
.text: .set sender_lr, 4
<<<function preamble snipped>>>
.text: mr r31, r1 // Copy stack pointer to r31
.text: stw r3, var_8(r31) // All local variables are
.text: stw r4, var_C(r31) // recognized and nameable.
What I want is to convert all, e.g. 8(r31)
local variable references in the function to normal var_8(r31)
syntax. I do not want to have to change each reference manually. Is there a way to:
- Convince IDA that
r31
is the stack pointer? - Change all
8(31)
tovar_8(r31)
in a single command? - Otherwise get the effect I am looking for in a way I haven't thought of?
main()
function of an executable that was compiled using CodeWarrior. It does the same thing as OP's function: the SP is copied to r31, and r31 is used as the SP in the rest of the function.