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區域分析完畢了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM