问题
I need an additional register to store a string in a smali method. I am aware of the register logic in smali code (see https://github.com/JesusFreke/smali/wiki/Registers), but i am still wondering how to archive an increase in registers.
Assuming i have a method with .locals n. Now i want to have .locals n+1. First i thought to iterate over the method and add 1 to each v register (v0 -> v1, v1 -> v2). Then v0 would be my new register and i would not clobber any existing data. Furthermore i keep the alignment between p and v registers.
Unfortunately this simple approach results in non-compiling code. I have no clue why. What did I miss to do?
回答1:
Unfortunately, there is no simple, guaranteed way to do this. However, the closest thing is increment the number of registers in .registers
or .locals
, like you described, and then the last non-parameter register will be available for your use. Also, make sure the file was not disassembled with the -p/--no-parameter-registers option, so that all of the parameter registers use their own numbering scheme, so they won't be affected by the increase in registers.
The one problem you might run into when using this approach is due to the fact that the parameter registers are bumped down a register. This can cause problems if, for example, one of the parameter registers was mapped to v15, and it gets bumped down to v16. This can be a problem because a lot of instructions can only accept v0 through v15. So in these cases, you might need to add another temp register or two and play musical chairs with the register values, swapping values into and out of the lower registers for use in such instructions that can only address the first 16 registers.
Due to the complexity of doing this, I usually recommend that you try to avoid changing the number of registers in an existing method. Instead try to implement the logic in a new method that you can then call from the existing method without having to allocate new registers. Of course, depending on what you're wanting to do, this isn't always possible.
来源:https://stackoverflow.com/questions/27341565/smali-increase-number-of-registers