在 IDA Python 中使操作数成为偏移量

逆向工程 蟒蛇
2021-06-20 07:32:00

我使用 ARM 可执行文件。有时我有这样的MOV指令:

MOV R0, #0xCD548A40

其中数字#0xCD548A40是有效的偏移量,但 IDA 不会自动识别它。我尝试使用启用的选项“自动将数据转换为偏移量重新分析可执行文件,但没有任何合适的结果。我还尝试编写 IDAPython 脚本来解决此问题,但我发现转换为偏移的唯一可能性是:

idaapi.jumpto(address)
idaapi.process_ui_action("OpOffset", 0)

这不是太方便使用。

问题

给定特定地址处的指令及其有效偏移量范围内的一个操作数,是否可以使用 IDA Python 将此类数字转换为偏移量?

我应该为此使用哪个 IDAPython API?

2个回答

OpOff为此,我一直在使用 Ida函数。那是idc,不是idapython,但https://www.hex-rays.com/products/ida/support/idapython_docs/idc-module.html#OpOff说,有OpOffidapython也是如此。此外,还有另一个函数 ,OpOffEx可让您指定更多详细信息。我认为其中之一就是您所需要的。

我碰巧遇到了这个确切的问题。

这就是我所做的。for替换if位以仅对一小部分进行测试。

from idautils import *
from idaapi import *
from idc import *

#if True:
#    if True:
#        if True:
#            startea = 0x0F9109DC
#            endea = 0x0F9109F
for segea in Segments():
    for funcea in Functions(segea, SegEnd(segea)):
        functionName = GetFunctionName(funcea)
        for (startea, endea) in Chunks(funcea):
            for ea in Heads(startea, endea):
                if idc.GetMnem(ea) != "MOV" or idc.get_operand_type(ea, 1) != 5 or  idc.get_str_type(idc.get_operand_value(ea, 1)) != 0:
                    continue
                print "0x%08x"%(ea), ":", idc.GetOpnd(ea, 1), idc.get_operand_type(ea, 1)
                idc.op_plain_offset(ea,1,0)

``