Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Mach-O/Load commands

From ReverseEngineering.wiki
Topic page of Format:Mach-O.

Reference of the Mach-O load commands (LC_* values), the CPU type constants used by mach_header and fat_arch, platform ids of LC_BUILD_VERSION and the segment and section structures.

Load command header

Every command begins uint32 cmd; uint32 cmdsize;. Commands whose value has bit 0x80000000 (LC_REQ_DYLD) set must be understood by dyld or the load fails. Strings inside commands use lc_str: a 32-bit offset from the start of the command.

LC_* values

Value Name
0x1 LC_SEGMENT (32-bit)
0x2 LC_SYMTAB (symoff, nsyms, stroff, strsize)
0x4 / 0x5 LC_THREAD / LC_UNIXTHREAD (old entry point, thread state)
0xB LC_DYSYMTAB
0xC / 0xD LC_LOAD_DYLIB / LC_ID_DYLIB
0xE / 0xF LC_LOAD_DYLINKER / LC_ID_DYLINKER (usually /usr/lib/dyld)
0x19 LC_SEGMENT_64
0x1B LC_UUID (16 bytes)
0x1D LC_CODE_SIGNATURE (linkedit_data_command)
0x1E LC_SEGMENT_SPLIT_INFO
0x20 LC_LAZY_LOAD_DYLIB
0x21 / 0x2C LC_ENCRYPTION_INFO / _64 (cryptoff, cryptsize, cryptid)
0x22 LC_DYLD_INFO (0x80000022 = LC_DYLD_INFO_ONLY): rebase, bind, weak bind, lazy bind, export opcode streams
0x24 / 0x25 / 0x2F / 0x30 LC_VERSION_MIN_MACOSX / IPHONEOS / TVOS / WATCHOS
0x26 LC_FUNCTION_STARTS (ULEB128 deltas of function addresses)
0x27 LC_DYLD_ENVIRONMENT
0x29 LC_DATA_IN_CODE
0x2A LC_SOURCE_VERSION
0x2B LC_DYLIB_CODE_SIGN_DRS
0x2D / 0x2E LC_LINKER_OPTION / LC_LINKER_OPTIMIZATION_HINT
0x31 LC_NOTE
0x32 LC_BUILD_VERSION (platform, minos, sdk, tool list)
0x80000018 LC_LOAD_WEAK_DYLIB
0x8000001C LC_RPATH
0x8000001F LC_REEXPORT_DYLIB
0x80000023 LC_LOAD_UPWARD_DYLIB
0x80000028 LC_MAIN (entryoff, stacksize)
0x80000033 LC_DYLD_EXPORTS_TRIE
0x80000034 LC_DYLD_CHAINED_FIXUPS
0x80000035 LC_FILESET_ENTRY

LC_BUILD_VERSION platform ids

1 macOS, 2 iOS, 3 tvOS, 4 watchOS, 5 bridgeOS, 6 Mac Catalyst, 7 iOS simulator, 8 tvOS simulator, 9 watchOS simulator, 10 DriverKit. Versions are packed xxxx.yy.zz (major in the high 16 bits).

CPU types

cputype = base | ABI flag. ABI64 flag 0x01000000, ABI64_32 flag 0x02000000. X86 = 7, x86_64 = 0x01000007, ARM = 12, ARM64 = 0x0100000C, ARM64_32 = 0x0200000C, POWERPC = 18, POWERPC64 = 0x01000012. arm64 subtypes: 0 ALL, 1 V8, 2 ARM64E (pointer-authenticated; the top byte of cpusubtype carries the pointer-auth ABI version, mask 0x0F000000).

Segments and sections

segment_command_64: cmd, cmdsize, segname[16], vmaddr, vmsize, fileoff, filesize, maxprot, initprot, nsects, flags (72 bytes), followed by nsects section_64 of 80 bytes: sectname[16], segname[16], addr, size, offset, align, reloff, nreloc, flags, reserved1-3. Section type is the low byte of flags (S_REGULAR 0, S_ZEROFILL 1, S_CSTRING_LITERALS 2, S_THREAD_LOCAL_VARIABLES 0x13, S_INIT_FUNC_OFFSETS 0x16); attributes are the high bits (S_ATTR_PURE_INSTRUCTIONS 0x80000000, S_ATTR_SOME_INSTRUCTIONS 0x400).

Chained fixups

Full layouts (header, starts, imports, every pointer format and the arm64e authenticated bit fields) are on Format:Mach-O/Chained fixups; the older opcode streams are on Format:Mach-O/Bind and rebase opcodes; LC_ENCRYPTION_INFO on Format:Mach-O/Encryption info.

LC_DYLD_CHAINED_FIXUPS (0x80000034) replaces the bind/rebase opcode streams on newer toolchains: static pointers in __DATA/__got look like garbage (tag bits in the high bits) until decoded. Page-start value 0xFFFF means no fixups on that page.

Parent: Format:Mach-O.