【问题标题】:Mach-O binary: external undefined symbols not found after patching symtabMach-O 二进制文件:修补 symtab 后未找到外部未定义符号
【发布时间】:2013-12-12 21:12:37
【问题描述】:

我正在尝试符号化反转的 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”修改字符串表

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

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

问题:

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

非常感谢任何建议!

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

【问题讨论】:

  • 问三个问题而不是一个问题

标签: ios c ida mach-o dyld


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2023-04-02
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    相关资源
    最近更新 更多