我试图使用IDA来分析二进制写,并由我自己在Linux上编译。在函数窗口中,IDA显示函数experiment(std::string,int,std::string) .text 00000000004181FB 0000082F 000004D8 00000000 R . . . B . .,但是当我试图通过ida获取函数时。
Python>for i in idautils.Functions():
Python> name = idaapi.get_func_name(i)
Python> if name.startswith('_Z10experimentSsiSs') or name.startswith('experiment'):
Python> print name
Python> print idc.GetType(i)结果是
_Z10experimentSsiSs None
没有函数被命名为experiment,函数_Z10experimentSsiSs的类型(似乎是函数experiment())为None。我想得到所有函数的参数,但如上所述,我无法得到函数的信息(_Z10experimentSsiSs),甚至找不到函数(实验)。为什么会这样呢?我该怎么办?
发布于 2018-11-22 06:40:25
AFAIK,idc.getType只使用C函数。在使用C++时,名称是残缺。
下面是我做的一个快速测试:
#include <iostream>
#include <string>
void test(const std::string& s1, const std::string& s2)
{
std::cout << s1 << " " << s2 << std::endl;
return;
}
int main(int argc, char* argv[])
{
if(argc != 3)
{
std::cerr << "2 args needed" << std::endl;
return -1;
}
test(argv[1], argv[2]);
return 0;
}编译,测试:
neitsa@eagle:/mnt/temp/gpp$ g++ -o test test.cpp
neitsa@eagle:/mnt/temp/gpp$ ./test hello world
hello world在IDA (我使用7.2)中,test函数有这个(怪物):
.text:0000000000000CBA ; test(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
.text:0000000000000CBA public _Z4testRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_
.text:0000000000000CBA _Z4testRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_ proc near因此,从技术上讲,(损坏的)函数名是:_Z4testRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_
由于参数的类型是由符号信息提供的(也就是说,如果去掉二进制文件,就不能再访问这些信息了!)除了RTTI (它也可以提供这种类型的信息)之外,获得它们的唯一方法是分解名称,然后解析它:
知道姓名:
Python>idaapi.get_func_name(0xcba)
_Z4testRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_解出它:
Python>idc.Demangle(idaapi.get_func_name(0xcba), idc.GetLongPrm(idc.INF_SHORT_DN))
test(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>> const&,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>> const&)一旦有了,您就可以解析函数原型并提取参数类型(这可能不适合C++.)。
您可能需要尝试使用INF_LONG_DN,它似乎在每个参数之后添加空格。在解析时,这可能会有所帮助:
Python>idc.Demangle(idaapi.get_func_name(0xcba), idc.GetLongPrm(idc.INF_LONG_DN))
test(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)注意:请尝试使用strip <program> -o <program_stripped>,您将看到函数的名称将不再存在。
https://stackoverflow.com/questions/53405153
复制相似问题