Personal original, reprint please indicate source: Cnblogs.com/jailbreaker
In win under the reverse need to read PE, also engage in iOS security must understand Mach-o format, the official Mach-o document of fruit in this: https://developer.apple.com/library/mac/documentation/ Developertools/conceptual/machoruntime/index.html
In this paper, the actual project analysis, to achieve the purpose of "understand", the use of tools or the previous blog used Hopper.
First drag the target file into Hopper, I'm here for the analysis of ARMV7 architecture, select Show Segment list:
Then select the first line to reach the Mach-o header area:
The middle of the IDE appears as follows:
Hopper's comments have been more detailed, under Xcode, open mach-o/loader.h, look at the definition of the header structure:
According to the above 2 diagram, Correspondence Analysis:
1.magic, is the magic number of Mach-o file, 0xfeedface is 32 bits, 0XFEEDFACF stands for 64 bit
2.cputype and Cupsubtype represent the type of CPU and its subtypes, a bit of a mouthful, directly look at the definition in mach/machine.h, examples are C and 9, defined as follows:
#define CPU_TYPE_ARM ((cpu_type_t) )
#define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
When loading the file, Hopper prompts to select the schema type, which is ARMv7
3. followed by filetype, the value in the example is 2, which represents the executable file
#defineMH_EXECUTE 0x2/* Demand Paged executable file * *
4.ncmds refers to the number of LOAD commands (load commands), in the example , total, number 0-
5.sizeofcmds represents the total byte size of the load commands, and the load commands area is immediately following the header area.
6. The last flags, in the example 0x00200085, are split by bit and correspond to the following:
#defineMH_NOUNDEFS 0x1/* The object file has no undefined references */
#define Mh_dyldlink 0x4/* The object file is input for the
Dynamic linker and can ' t be staticly
Link edited again */
#define Mh_twolevel 0x80/* The image is using Two-level name
Space Bindings */
#define Mh_allow_stack_execution 0x20000/* When the This bit is set and all stacks
In the task would be given stack
Execution privilege. Only
At this point, Mach-o's header area analysis is complete.
[iOS reverse Combat VI] read MACH-O (1)