zoukankan      html  css  js  c++  java
  • iOS安全攻防(十六)看懂mach-o(1)

    个人原创,转帖请注明来源:cnblogs.com/jailbreaker

    在win下搞逆向需要看懂pe,同样搞iOS安全攻防必须看懂mach-o格式,水果的官方mach-o文档在此:https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/MachORuntime/index.html

    本文中实际项目分析,来达到“看懂”的目的,使用的工具还是前一篇blog所用的hopper。

    先将目标文件拖进hopper,我这里针对的是ARMv7架构的分析,选择显示segment list:

    NewImage

    然后选择第一行,到达mach-o header区域:

    NewImage

    hopper中间显示如下:

    NewImage

    hopper的注释已经比较详细了,在xcode下,打开mach-o/loader.h ,看下header结构的定义:

    NewImage

     

    根据以上2图,对应分析:

      1.magic,是mach-o文件的魔数,0xfeedface代表的是32位,0xfeedfacf代表64位

      2.cputype和cupsubtype代表的是cpu的类型和其子类型,有点拗口,直接看mach/machine.h中的定义,例子中分别是c和9,定义如下:

      #define CPU_TYPE_ARM((cpu_type_t) 12)

      #define CPU_SUBTYPE_ARM_V7((cpu_subtype_t) 9)

      加载文件的时候hopper 提示选择架构类型,就是ARMv7

        

     3.接着是filetype,例子中的值是2,代表可执行的文件

      #defineMH_EXECUTE  0x2/* demand paged executable file */

        

     4.ncmds 指的是加载命令(load commands)的数量,例子中一共23个,编号0-22

     5.sizeofcmds 表示23个load commands的总字节大小, load commands区域是紧接着header区域的。

     6.最后个flags,例子中是0x00200085,按位拆分,对应如下:

     

    #defineMH_NOUNDEFS0x1/* the object file has no undefined  references */

    #define MH_DYLDLINK0x4/* the object file is input for the

      dynamic linker and can't be staticly

      link edited again */

    #define MH_TWOLEVEL0x80/* the image is using two-level name

      space bindings */

    #define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks 

      in the task will be given stack

      execution privilege.  Only

     

    至此,mach-o的header区域分析完毕了。

     

  • 相关阅读:
    weblogic 的应用 常见问题处理 db2 链接不上(转载)
    WebLogic简单的备份和恢复
    linux 切换用户之后变成-bash-x.x$的解决方法
    weblogic迁移随手记
    生产环境下Centos 6.5优化配置 (装载)
    查看db2表空间使用率
    Linux 之 rsyslog 系统日志转发(转载)
    windows下定时利用bat脚本实现ftp上传和下载
    rsyslog同步history日志(转载)
    linux比较指令comm、diff、grep -Ff
  • 原文地址:https://www.cnblogs.com/jailbreaker/p/4185226.html
Copyright © 2011-2022 走看看