扩展Mach-O文件中的部分 [英] Extend section in Mach-O file

查看:186
本文介绍了扩展Mach-O文件中的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Dyld_shared_cache中提取库,并且需要修复外部引用.

I am trying to extract libraries from the Dyld_shared_cache, and need to fix in external references.

例如,__DATA.__objc_selrefs部分中的指针通常指向mach-o文件之外的数据,以解决我必须从dyld复制相应的c字符串并将其附加到__TEXT.__objc_methname部分的问题.

For example, the pointers in the __DATA.__objc_selrefs section usually point to data outside the mach-o file, to fix that I would have to copy the corresponding c-string from the dyld and append it to the __TEXT.__objc_methname section.

尽管从我对Mach-O文件格式的理解来看,__TEXT.__objc_methname的扩展名将移动其后的所有部分,并迫使我修复所有引用它们的偏移量和指针.有没有一种方法可以在不破坏很多内容的情况下将数据添加到节中?

Though from my understanding of the Mach-O file format, this extension of the __TEXT.__objc_methname would shift all the sections after it and would force me to fix all the offsets and pointers that reference them. Is there a way to add data to a section without breaking a lot of things?

谢谢!

推荐答案

感谢@ Kamil.S提供有关添加新的加载命令和部分的想法.

Thanks to @Kamil.S for the idea about adding a new load command and section.

一种向节中添加更多数据的方法是创建一个重复的节和节,然后将其插入__LINKEDIT节之前.

One way to achieve adding more data to a section is to create a duplicate segment and section and insert it before the __LINKEDIT segment.

  • 滑动__LINKEDIT段,以便我们有空间添加新段.
  • Slide the __LINKEDIT segment so we have space to add the new section.
  1. 定义幻灯片数量,该数量必须与页面对齐,因此我选择0x4000.
  2. 将滑动量添加到相关的加载命令中,包括但不限于:
    • __ LINKEDIT段(duh)
    • dyld_info_command
    • symtab_command
    • dysymtab_command
    • linkedit_data_commands
  1. define the slide amount, this must be page-aligned, so I choose 0x4000.
  2. add the slide amount to the relevant load commands, this includes but is not limited to:
    • __LINKEDIT segment (duh)
    • dyld_info_command
    • symtab_command
    • dysymtab_command
    • linkedit_data_commands

  • 复制该部分并更改以下 1
    • 大小,应为新数据的长度.
    • addr,应位于可用空间中.
    • 偏移量,应在可用空间内.
    • duplicate the section and change the following1
      • size, should be the length of your new data.
      • addr, should be in the free space.
      • offset, should be in the free space.
        • fileoff,应该是可用空间的开始.
        • vmaddr,应该是可用空间的开始.
        • 文件大小,任何大于数据的大小.
        • vmsize,必须与文件大小相同.
        • nsect,进行更改以反映您添加的部分.
        • cmdsize,进行更改以反映segment命令及其段命令的大小.
        • ncmds
        • sizeofcmds
        1. 您可以选择更改segname和sectname字段,尽管这不是必需的.谢谢Kamil.S!

        这篇关于扩展Mach-O文件中的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆