斯马里语:增加寄存器数量 [英] Smali: Increase number of registers

查看:415
本文介绍了斯马里语:增加寄存器数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个额外的寄存器来以smali方法存储字符串.我知道smali代码中的寄存器逻辑(请参见 https://github.com/JesusFreke/smali/wiki/Registers ),但是我仍然想知道如何归档增加的寄存器数.

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.

假设我有一个 .locals n 的方法.现在我想拥有 .locals n + 1 .首先,我想遍历该方法,并向每个v寄存器加1(v0-> v1,v1-> v2).那么v0将是我的新寄存器,而我不会破坏任何现有数据.此外,我保持p和v寄存器之间的对齐.

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?

推荐答案

不幸的是,没有简单,有保证的方法可以做到这一点.但是,最接近的是如您所述增加.registers.locals中的寄存器数量,然后最后一个非参数寄存器将可供您使用.另外,请确保使用-p/-no-parameter-registers选项对文件进行 not 的反汇编,以便所有参数寄存器都使用其自己的编号方案,这样它们就不会受到影响通过增加寄存器.

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.

使用这种方法时,您可能会遇到的一个问题是由于参数寄存器被撞到了寄存器的事实.例如,如果其中一个参数寄存器被映射到v15,并且被降低到v16,则可能会导致问题.这可能是一个问题,因为许多指令只能接受v0到v15.因此,在这些情况下,您可能需要添加另一个或两个临时寄存器,并使用该寄存器的值来演奏音乐椅子,将值交换进出较低的寄存器,以用于只能寻址前16个寄存器的指令.

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.

这篇关于斯马里语:增加寄存器数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆