Skip to content

四 Mach O的文件类型

Kevin775263419 edited this page Mar 7, 2019 · 1 revision
  1. Mach-O是Mach object的缩写,是Mac\iOS上用于存储程序、库的标准格式。

  2. 属于Mach-O格式的文件类型有.,大致有这么多类型

  3. #define	MH_OBJECT	0x1		/* relocatable object file */
    #define	MH_EXECUTE	0x2		/* demand paged executable file */
    #define	MH_FVMLIB	0x3		/* fixed VM shared library file */
    #define	MH_CORE		0x4		/* core file */
    #define	MH_PRELOAD	0x5		/* preloaded executable file */
    #define	MH_DYLIB	0x6		/* dynamically bound shared library */
    #define	MH_DYLINKER	0x7		/* dynamic link editor */
    #define	MH_BUNDLE	0x8		/* dynamically bound bundle file */
    #define	MH_DYLIB_STUB	0x9		/* shared library stub for static */
    					/*  linking only, no section contents */
    #define	MH_DSYM		0xa		/* companion file with only debug */
    					/*  sections */
  4. 可以在xnu源码中,查看到Mach-O格式的详细(https://opensource.apple.com/tarballs/xnu/

    • EXTERNAL_HEADERS/mach-o/fat.h
    • EXTERNAL_HEADERS/mach-o/loader.h
常见的Mach-O文件类型
  1. MH_OBJECT
    • 目标文件(.o)
    • 静态库文件(.a),静态库其实就是N个.o合并在一起
  2. MH_EXECUTE:可执行文件
    • .app/x
  3. MH_DYLIB:动态库文件
    • .dylib
    • .framework/xx
  4. MH_DYLINKER:动态链接编辑器
    • /usr/lib/dyld
  5. MH_DSYM:存储着二进制文件符号信息的文件
    • .dSYM/Contents/Resources/DWARF/xx(常用于分析APP的崩溃信息)
  6. .o文件是中间文件,1.c 编译成1.o 很多的.o文件可以链接成一个可执行文件
  7. 在Xcode中查看target的Mach-O类型,build settings 搜索Mach -O 可以查看可执行文件的类型,xCode可以看到是Executable类型。