Otool可以提取并显示ios下目标文件的相关信息,包括头部,加载命令,各个段,共享库,动态库等等。它拥有大量的命令选项,是一个功能强大的分析工具,当然还可以做反汇编的工具使用。
2. Mach-o基本结构
Mach-o包含三个基本区域:
头部(header structure)。
加载命令(load command)。
段(segment)。可以拥有多个段(segment),每个段可以拥有零个或多个区域(section)。每一个段(segment)都拥有一段虚拟地址映射到进程的地址空间。
链接信息。一个完整的用户级Mach-o文件的末端是链接信息。其中包含了动态加载器用来链接可执行文件或者依赖库所需使用的符号表,字符串表等等。
3. 头部结构
Mach-o的头部帮助内核迅速确定当前文件所支持的CPU架构。它位于Mach-o文件的开始部分。
可以用otool –h XX来获取某文件的header structure。
Otool –h ButtonFun;
ButtonFun (architecture armv6):
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedface 12 6 000 2 19 2404 000000085
ButtonFun (architecture armv7):
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedface 12 9 000 2 19 2404 000200085
从上面的输出可以看到header部分的字段,下面来看一下头部结构的定义和意义:
[codesyntax lang="c" lines="normal"]
struct mach_header {
uint32_t magic;
/* mach magic number identifier */
cpu_type_t cputype;
/* cpu specifier */
cpu_subtype_t cpusubtype;
/* machine specifier */
uint32_t filetype;
/* type of file */
uint32_t ncmds;
/* number of load commands */
uint32_t sizeofcmds;
/* the size of all the load commands */
uint32_t flags;
/* flags */
};
[/codesyntax] 64位对应的定义(下文中不再追述64位下的定义):
[codesyntax lang="c" lines="fancy"]
struct mach_header_64 {
uint32_t magic;
/* mach magic number identifier */
cpu_type_t cputype;
/* cpu specifier */
cpu_subtype_t cpusubtype;
/* machine specifier */
uint32_t filetype;
/* type of file */
uint32_t ncmds;
/* number of load commands */
uint32_t sizeofcmds;
/* the size of all the load commands */
uint32_t flags;
/* flags */
uint32_t reserved;
/* reserved */
};
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-42605-1.html
不要一天都在自己近海训练
国家不会不在乎
一直不动的抱那只股票可以赚钱
伊拉克总统已死