如何从已编译的elf文件中提取所有函数,即使函数没有符号
How to extract all functions out of a compiled elf file,even the function has no symbol
IDA 可以执行 this:some 没有符号的函数将以 'sub_address' 命名。
我如何在运行时执行此操作。
enter image description here
简而言之,您反汇编所有导出函数并查找 call
指令。对于每个 call
指令,您获取地址操作数并将其标记为另一个函数,并将其反汇编。递归地同上。
从 call
个操作数中找到的此类函数是 IDA 调用的 sub_XXXX
。
How to extract all functions out of a compiled elf file,even the function has no symbol
您没有定义适合您的函数(您确实应该定义)。
注意,如果编译器有 inlined 一个函数,它不会出现在 ELF 文件中,即使它当然存在于源代码中(整个程序本可以用 link-时间优化,例如 g++ -flto -O2
在编译和 link 时间;那么你将有许多内联函数,包括几个标记为 not inline
在源代码中)。
原始源代码可以用 visibility 技巧编译。
软件构建可能使用了一些 code obfuscation 技术。
如果某些函数被间接调用(想想 C++ 中的虚方法,总是通过某些 vtable; or think of some static
function whose address is put into some function pointer variable or struct
field) then you practically cannot detect it, since to reliably do that on the binary executable requires a precise analysis of all the possible (function pointer) values of some register or memory location (and that is undecidable, see Rice's theorem 调用)。
一个程序也可以加载一个 plugin at runtime (e.g. using dlopen
) and call functions in it. It could also generate some machine code when running (e.g. with the help of GNU lightning, asmjit, libgccjit, etc...) 并调用这样一个生成的函数。
所以一般来说你无法实现你的目标(特别是如果你假设你的 "adversary",软件作者,使用巧妙的技术使函数提取变得困难) .一般情况下,decompilation是不可能的(如果你希望它精确完整的话)。
但是, 提出了一些粗略和不完整的近似值。您需要决定这是否足够(甚至 IDA 也给出了近似结果)。
最后,在某些法律体系中,反编译或reverse engineering of a binary executable is forbidden (even when technically possible); check the EULA或合同(或法律)与您的二进制软件和您的情况有关。您真的应该验证您尝试做的事情是否合法(也可能不合法,在某些情况下您可能会面临坐牢的风险)。
顺便说一句,所有这些原因都是我更喜欢始终使用 free software, whose source code is published and can be studied and improved. I am willingly avoiding proprietary software.
的原因
IDA 可以执行 this:some 没有符号的函数将以 'sub_address' 命名。 我如何在运行时执行此操作。
enter image description here
简而言之,您反汇编所有导出函数并查找 call
指令。对于每个 call
指令,您获取地址操作数并将其标记为另一个函数,并将其反汇编。递归地同上。
从 call
个操作数中找到的此类函数是 IDA 调用的 sub_XXXX
。
How to extract all functions out of a compiled elf file,even the function has no symbol
您没有定义适合您的函数(您确实应该定义)。
注意,如果编译器有 inlined 一个函数,它不会出现在 ELF 文件中,即使它当然存在于源代码中(整个程序本可以用 link-时间优化,例如 g++ -flto -O2
在编译和 link 时间;那么你将有许多内联函数,包括几个标记为 not inline
在源代码中)。
原始源代码可以用 visibility 技巧编译。
软件构建可能使用了一些 code obfuscation 技术。
如果某些函数被间接调用(想想 C++ 中的虚方法,总是通过某些 vtable; or think of some static
function whose address is put into some function pointer variable or struct
field) then you practically cannot detect it, since to reliably do that on the binary executable requires a precise analysis of all the possible (function pointer) values of some register or memory location (and that is undecidable, see Rice's theorem 调用)。
一个程序也可以加载一个 plugin at runtime (e.g. using dlopen
) and call functions in it. It could also generate some machine code when running (e.g. with the help of GNU lightning, asmjit, libgccjit, etc...) 并调用这样一个生成的函数。
所以一般来说你无法实现你的目标(特别是如果你假设你的 "adversary",软件作者,使用巧妙的技术使函数提取变得困难) .一般情况下,decompilation是不可能的(如果你希望它精确完整的话)。
但是,
最后,在某些法律体系中,反编译或reverse engineering of a binary executable is forbidden (even when technically possible); check the EULA或合同(或法律)与您的二进制软件和您的情况有关。您真的应该验证您尝试做的事情是否合法(也可能不合法,在某些情况下您可能会面临坐牢的风险)。
顺便说一句,所有这些原因都是我更喜欢始终使用 free software, whose source code is published and can be studied and improved. I am willingly avoiding proprietary software.
的原因