我正在尝试符号化反转的 iOS 二进制文件。于是开始学习Mach-O格式here并编写了一个基本程序来测试将一个符号手动添加到剥离二进制文件的简单示例 (!):
#include <stdio.h>
#include <stdlib.h>
int division(int a, int b);
int m;
int main(void)
{
int i,j;
printf("initializing i\n");
i = 10;
printf("initializing j\n");
j=1;
printf("i = %d, j = %d\n", i, j);
m = division(i, j);
printf("m = %d / %d = %d\n", i, j, m);
return 0;
}
int division(int a, int b)
{
return a / b;
}
我做了什么:
- 将源代码编译到 ARM 上面,没有任何称为“helloworld”的优化。
- 剥离了这个“helloworld”程序并将其命名为“helloworld_stripped”。
- 在 MachOView 和 hexfiend 中打开“helloworld_stripped”(进行编辑)。
- 将“helloworld_stripped”另存为“helloworld_stripped2”
- 通过将“_division”添加到字符串表的末尾来修改字符串表
- 在“helloworld_stripped2”的符号表中添加了一个条目,如下所示:
- 修改了 LC_SYMTAB 和 LC_DYNSYMTAB 加载命令以反射(reflect)新的字符串表大小、偏移量等。以下
otool -l
输出反射(reflect)了这一点(“* * * * *”是 helloworld_stripped 和 '--- -' 是 helloworld_stripped2): - 然后我在 IDA pro 中打开“helloworld_stripped”和“helloworld_stripped2”并看到:
问题:
修补后的可执行文件“helloworld_stripped2”缺少 printf 函数。为什么 printf 函数在剥离的可执行文件中而不是在修补的可执行文件中?我没有在符号表中更改它,并且 printf 在字符串表中的位置也没有更改。
非常感谢任何建议!
编辑:请参阅下面的答案。
最佳答案
好吧,基本上,我自己发现了问题:我忘记用新的符号表条目值更新间接符号表。当我更新它时,IDA pro 能够同时显示 _division 和 _printf。
圈出的值对应符号表中的项索引。由于符号表被更新,间接(如 printf)符号的索引发生变化。因此必须修改动态符号表以反射(reflect)它们的新条目索引。希望它能帮助那里的人。
关于ios - Mach-O 二进制 : external undefined symbols not found after patching symtab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20238892/