如何通过 IDA 中的说明了解当前的 EIP?

逆向工程 艾达 蟒蛇 登记
2021-07-01 07:50:50
import idaapi
x=0
while x<10:
    idaapi.step_into()
    rv = idaapi.regval_t()
    idaapi.get_reg_val('EIP',rv)
    ea = rv.ival
    print hex(ea)
    x+=1

你好。这是一个可以进入 10 次的脚本。我想使用 idaapi.get_reg_val() API 获得更新版本的 EIP 值如果我在这里运行此代码就是我得到的。

0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL
0xffffffffffffffffL

虽然实际 EIP 值一直有效我也尝试过其他路径

while ea !=0x0040af75:
    idaapi.step_into()
    eip = GetRegValue('EIP')
    print eip

但是后来我得到了纯粹的错误,其含义对我来说很神秘

Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\Program Files (x86)\IDA 6.8\python\idc.py", line 7889, in GetRegValue
    assert res, "get_reg_val() failed, bogus register name ('%s') perhaps?" % name
AssertionError: get_reg_val() failed, bogus register name ('EIP') perhaps?

所以它看起来像它调用这个低级函数的任何一种方式 - get_reg_val 但不能正常使用字符串参数。如果不在循环中,这两个函数 get_reg_val 和 GetRegValue() 都可以正常工作。帮我

2个回答

这个问题的有效答案是 Python 脚本和调试器执行流程异步执行。所以每次我们要求调试器执行 step_into() 时,我们也需要等待这个过程结束。这可以通过在 step_into 之后插入 GetDebuggerEvent(WFNE_SUSP, -1) 来完成

import idaapi

x=0
while x<10:
    idaapi.step_into()
    GetDebuggerEvent(WFNE_SUSP, -1)      
    rv = idaapi.regval_t()
    print idaapi.get_reg_val('EIP',rv)
    ea = rv.ival
    print hex(ea)
    x+=1

遇到与您的其他路径相同的错误,但使用 ESP 寄存器:

Python> GetRegValue('ESP')

File "C:\Program Files (x86)\IDA 6.8\python\idc.py", line 7889, in GetRegValue
    assert res, "get_reg_val() failed, bogus register name ('%s') perhaps?" % name
AssertionError: get_reg_val() failed, bogus register name ('ESP') perhaps?

在我的情况下,原因是运行静态分析会话。刚开始调试,然后手动或由 BP 挂起,GetRegVal() 工作正常。

Python> GetRegValue('ESP')
1232116