我从 HexRays 支持那里收到了一个答案,它有一个解决方案,它不依赖于解析由GetType(ea)
.
假设我们从一个函数原型开始:
int __cdecl main(int argc, const char **argv, const char **envp)
这是来自一个 ELF 文件,x86 abi;东西在堆栈上传递。
然后,我可以执行以下操作:
Python>from idaapi import *
Python>tif = tinfo_t()
Python>get_tinfo2(here(), tif)
True
Python>funcdata = func_type_data_t()
Python>tif.get_func_details(funcdata)
True
Python>funcdata.size()
3
Python>for i in xrange(funcdata.size()):
Python> print "Arg %d: %s (of type %s, and of location: %s)" % (i, funcdata[i].name, print_tinfo('', 0, 0, PRTYPE_1LINE, funcdata[i].type, '', ''), funcdata[i].argloc.atype())
Python>
Arg 0: argc (of type int, and of location: 1)
Arg 1: argv (of type const char **, and of location: 1)
Arg 2: envp (of type const char **, and of location: 1)
请注意,它告诉我位置类型是1
,对应于“堆栈”:https :
//www.hex-rays.com/products/ida/support/sdkdoc/group___a_l_o_c__.html
现在,让我们假设我将原型更改为:
.text:0804ABA1 ; int __usercall main@<eip>(int argc@<eax>, const char **argv@<esp>, const char **envp@<edx>)
然后:
Python>get_tinfo2(here(), tif)
True
Python>tif.get_func_details(funcdata)
True
Python>for i in xrange(funcdata.size()):
Python> print "Arg %d: %s (of type %s, and of location: %s)" % (i, funcdata[i].name, print_tinfo('', 0, 0, PRTYPE_1LINE, funcdata[i].type, '', ''), funcdata[i].argloc.atype())
Python>
Arg 0: argc (of type int, and of location: 3)
Arg 1: argv (of type const char **, and of location: 3)
Arg 2: envp (of type const char **, and of location: 3)
参数位置类型3
现在是,对应于“内部寄存器”。
(然后,我将不得不使用reg1()
检索实际寄存器号知道什么寄存器参数传入)
归功于 Hex Rays 的 Arnaud。