ios - Mach-O 二进制 : external undefined symbols not found after patching symtab

标签 ios c ida mach-o dyld

我正在尝试符号化反转的 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;
}

我做了什么:

  1. 将源代码编译到 ARM 上面,没有任何称为“helloworld”的优化。
  2. 剥离了这个“helloworld”程序并将其命名为“helloworld_stripped”。
  3. 在 MachOView 和 hexfiend 中打开“helloworld_stripped”(进行编辑)。
  4. 将“helloworld_stripped”另存为“helloworld_stripped2”
  5. 通过将“_division”添加到字符串表的末尾来修改字符串表

Modifying string table by adding division in red

  1. 在“helloworld_stripped2”的符号表中添加了一个条目,如下所示:

Adding the division symbol in the symtab

  1. 修改了 LC_SYMTAB 和 LC_DYNSYMTAB 加载命令以反射(reflect)新的字符串表大小、偏移量等。以下 otool -l 输出反射(reflect)了这一点(“* * * * *”是 helloworld_stripped 和 '--- -' 是 helloworld_stripped2): <code>otool -l</code> - load commands changed
  2. 然后我在 IDA pro 中打开“helloworld_stripped”和“helloworld_stripped2”并看到:

Problem

问题:

修补后的可执行文件“helloworld_stripped2”缺少 printf 函数。为什么 printf 函数在剥离的可执行文件中而不是在修补的可执行文件中?我没有在符号表中更改它,并且 printf 在字符串表中的位置也没有更改。

非常感谢任何建议!

编辑:请参阅下面的答案。

最佳答案

好吧,基本上,我自己发现了问题:我忘记用新的符号表条目值更新间接符号表。当我更新它时,IDA pro 能够同时显示 _division 和 _printf。

enter image description here

圈出的值对应符号表中的项索引。由于符号表被更新,间接(如 printf)符号的索引发生变化。因此必须修改动态符号表以反射(reflect)它们的新条目索引。希望它能帮助那里的人。

关于ios - Mach-O 二进制 : external undefined symbols not found after patching symtab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20238892/

相关文章:

assembly - 了解 x86 MOV 语法

ios - UICollectionView didSelectItemAt 从不触发

ios - self.navigationController.navigationBar setHidden :NO not working when view controllers are swapped out

ios - 更改iOS锁屏的行为

我可以这样模拟多个客户端吗?

创建指向二维数组的指针

ios - 为什么应用自定义推送动画时键盘会隐藏?

c - 在 C 中使用 memmove 从字符串中删除子字符串

ida - 如何在 IDA 6.1 的程序集 View 中禁用图形模式?

portable-executable - 如何在 IDA pro 中显示 PE header ?