← Mach-O
Mach-O·Format guide
All tools

How an iOS app's code is stored

Every executable, framework and dynamic library on Apple platforms is a Mach-O file: a small header, a list of load commands that tell the kernel and dyld how to map and link it, and the segments with the machine code and data. On top of that, Objective-C and Swift each write their own metadata into dedicated sections. This page describes these structures as the Mach-O tool reads them.

The format is defined in the XNU and dyld headers (mach-o/loader.h, mach-o/fat.h, mach-o/nlist.h, mach-o/fixup-chains.h), the Objective-C runtime (objc4, objc-runtime-new.h) and the Swift ABI documents (swift/ABI/Metadata.h, docs/ABI/Mangling.rst). All multi-byte fields are little-endian except in the fat header and the code signature, which are big-endian.

Contents

  1. Fat / universal header
  2. mach_header_64
  3. Load commands
  4. Segments and sections
  5. Fixups: chained fixups and LC_DYLD_INFO
  6. Chained pointer formats
  7. Symbols: LC_SYMTAB and LC_DYSYMTAB
  8. Function starts, code signature, encryption
  9. Libraries, rpaths and the entry point
  10. Stubs and GOT
  11. Objective-C metadata
  12. Swift metadata
  13. Swift name mangling
  14. arm64e pointer authentication
  15. Reading the page
  16. SwiftDemangler (lib/swift-demangle.js)
  17. MachOImage (lib/macho.js)
  18. MachOCrossReferences (lib/macho-xref.js)
  19. SymbolsFile (lib/symbols-file.js)

1Fat / universal header

A universal (fat) file bundles several complete Mach-O files, one per architecture. App Store apps for iOS are usually thin (arm64 only) after App Thinning; frameworks distributed to developers and macOS binaries are often fat. The header is big-endian:

magic+0 · u32 BE
nfat_arch+4 · u32 BE
fat_arch[nfat_arch]+8 · 20 or 32 bytes each
Offset Size fat_arch (0xcafebabe) fat_arch_64 (0xcafebabf)
+0 4 cputype
+4 4 cpusubtype
+8 4 / 8 offset (u32) of the slice in the file offset (u64)
+12 / +16 4 / 8 size (u32) size (u64)
+16 / +24 4 align, as a power of two (slices usually start on a 16 KB page: 214)
— / +28 4 — reserved

The tool parses every slice and shows a button per architecture; everything below is per slice. Each slice is a complete Mach-O whose own offsets are relative to the slice start.

3Load commands

Each load command starts with cmd (u32) and cmdsize (u32, the total size including these 8 bytes, a multiple of 8). Commands with bit 0x80000000 (LC_REQ_DYLD) must be understood by dyld or the image refuses to load. Strings inside a command (library names, paths) are stored as an lc_str: a u32 offset from the start of the command to a NUL-terminated string within it.

cmd Name What it says
0x19 LC_SEGMENT_64 One segment and its sections (below).
0x2 LC_SYMTAB The symbol table and its string table.
0xb LC_DYSYMTAB Ranges of local / exported / undefined symbols and the indirect symbol table.
0x80000034 LC_DYLD_CHAINED_FIXUPS Rebases and binds as pointer chains (iOS 15+ deployment targets).
0x80000033 LC_DYLD_EXPORTS_TRIE The exported symbols, as a trie (goes with chained fixups).
0x22 / 0x80000022 LC_DYLD_INFO(_ONLY) Older fixup format: rebase, bind, weak-bind, lazy-bind and export opcode streams.
0xc LC_LOAD_DYLIB A library this image needs. Variants: LC_LOAD_WEAK_DYLIB (0x80000018, may be missing), LC_REEXPORT_DYLIB, LC_LOAD_UPWARD_DYLIB, LC_LAZY_LOAD_DYLIB.
0xd LC_ID_DYLIB A library's own install name (only in dylibs and frameworks).
0xe LC_LOAD_DYLINKER The dynamic linker path, /usr/lib/dyld.
0x8000001c LC_RPATH A run-path search directory for @rpath/… names.
0x80000028 LC_MAIN Entry point offset and stack size.
0x1b LC_UUID 128-bit build UUID; matches the .dSYM and crash logs.
0x32 LC_BUILD_VERSION Platform (2 = iOS, 7 = iOS Simulator, 6 = Mac Catalyst…), minimum OS, SDK, and the tools (clang, swift, ld) with their versions. Older files use LC_VERSION_MIN_IPHONEOS (0x25).
0x2a LC_SOURCE_VERSION A version number packed into 64 bits (24.10.10.10.10).
0x26 LC_FUNCTION_STARTS Start address of every function.
0x29 LC_DATA_IN_CODE Ranges of data (jump tables) inside __text.
0x1d LC_CODE_SIGNATURE The code signature blob in __LINKEDIT.
0x2c LC_ENCRYPTION_INFO_64 The FairPlay-encrypted range (App Store binaries).
0x2d LC_LINKER_OPTION Linker flags embedded by auto-linking (-framework Foundation); in object files.

LC_FUNCTION_STARTS, LC_DATA_IN_CODE, LC_CODE_SIGNATURE, LC_DYLD_CHAINED_FIXUPS and LC_DYLD_EXPORTS_TRIE are all linkedit_data_commands: dataoff (u32, file offset) and datasize (u32) of a blob in the __LINKEDIT segment.

4Segments and sections

A segment is a range of the file mapped at a virtual address with one protection; a section is a named part of a segment with a type. vmaddrs are link-time addresses: with ASLR the whole image is slid by a random amount, which is why pointers in the file need fixups. For an executable, __TEXT starts at 0x100000000, after a 4 GB __PAGEZERO that catches 32-bit-truncated pointers.

segment_command_64 (72 bytes)

Offset Size Field Meaning
0x00 8 cmd, cmdsize 0x19, 72 + 80 × nsects
0x08 16 segname Name, NUL-padded (__TEXT, __DATA…).
0x18 8 vmaddr Virtual address.
0x20 8 vmsize Size in memory (can exceed filesize: zero-filled tail such as __bss).
0x28 8 fileoff File offset (relative to the slice).
0x30 8 filesize Bytes in the file.
0x38 4 maxprot Maximum protection (bits: 1 read, 2 write, 4 execute).
0x3c 4 initprot Initial protection.
0x40 4 nsects Number of section_64 records that follow.
0x44 4 flags e.g. SG_READ_ONLY (0x10) on __DATA_CONST: made read-only after fixups.

section_64 (80 bytes)

Offset Size Field Meaning
0x00 16 sectname Section name.
0x10 16 segname Owning segment.
0x20 8 addr Virtual address.
0x28 8 size Size in bytes.
0x30 4 offset File offset (0 for zero-fill sections).
0x34 4 align Alignment as a power of two.
0x38 8 reloff, nreloc Relocations (object files only).
0x40 4 flags Low byte: type (S_REGULAR, S_CSTRING_LITERALS, S_SYMBOL_STUBS, S_NON_LAZY_SYMBOL_POINTERS, S_ZEROFILL…). High bits: attributes, e.g. S_ATTR_PURE_INSTRUCTIONS (0x80000000) and S_ATTR_SOME_INSTRUCTIONS (0x400) mark code.
0x44 4 reserved1 For stub and pointer sections: first index into the indirect symbol table.
0x48 4 reserved2 For stub sections: the size of one stub.
0x4c 4 reserved3 —

The usual layout of an iOS app

Segment Prot Typical sections
__PAGEZERO --- None; 4 GB of unmapped address space, no file data.
__TEXT r-x __text (code), __stubs / __auth_stubs, __objc_stubs, __objc_methname, __objc_classname, __objc_methtype, __cstring, __oslogstring, __const, __swift5_*, __constg_swiftt, __unwind_info, __eh_frame. The Mach-O header and load commands are at the start of __TEXT.
__DATA_CONST rw- → r-- __got, __const, __cfstring, __objc_classlist, __objc_catlist, __objc_protolist, __objc_imageinfo, __objc_superrefs…: pointers fixed at load, then made read-only.
__AUTH_CONST rw- → r-- arm64e only: signed pointers (__auth_got, __auth_ptr, __const, __objc_const…).
__DATA rw- __objc_const (class_ro_t, method lists), __objc_selrefs, __objc_classrefs, __objc_ivar, __objc_data (class objects), __data, __bss, __common; in older binaries __la_symbol_ptr.
__LINKEDIT r-- No sections: the fixup data, symbol and string tables, function starts, export trie and code signature, located by the load commands.

The exact placement varies with the linker version and deployment target; read the actual segment table rather than assuming.

5Fixups: chained fixups and LC_DYLD_INFO

A pointer in the file is not yet usable: a pointer to the image's own data must be adjusted by the ASLR slide (a rebase), and a pointer to an imported symbol (_objc_msgSend, _OBJC_CLASS_$_NSString) must be filled with that symbol's address (a bind). Two encodings exist.

LC_DYLD_INFO_ONLY (older)

Ten u32s: rebase_off/size, bind_off/size, weak_bind_off/size, lazy_bind_off/size, export_off/size. Each range is a byte-code program for dyld (REBASE_OPCODE_*, BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM, BIND_OPCODE_DO_BIND…) that walks segments and writes pointers. The pointers in the file are plain unslid vmaddrs, so a reader can follow rebased pointers directly; bound ones are zero (or a stub-helper address) until dyld runs.

LC_DYLD_CHAINED_FIXUPS (iOS 15 / macOS 12 targets and later)

The fixup information is stored in the pointers themselves: each 64-bit slot holds either a rebase target or a bind ordinal, plus a next field giving the distance to the next fixup on the same page. The __LINKEDIT blob only says where each page's chain starts and lists the imports.

Offset dyld_chained_fixups_header Meaning
+0 fixups_version 0
+4 starts_offset → dyld_chained_starts_in_image
+8 imports_offset → the import table
+12 symbols_offset → symbol names (NUL-terminated strings)
+16 imports_count Number of imports
+20 imports_format 1 DYLD_CHAINED_IMPORT (4 bytes), 2 …_ADDEND (8 bytes), 3 …_ADDEND64 (16 bytes)
+24 symbols_format 0 uncompressed

starts_in_image: seg_count (u32), then one u32 offset per segment (0 = no fixups in that segment) to a starts_in_segment: size u32, page_size u16, pointer_format u16, segment_offset u64, max_valid_pointer u32, page_count u16, then page_start[page_count] u16 — the offset of the first fixup in each page, or 0xFFFF for none.

Imports: format 1 packs lib_ordinal (8 bits), weak_import (1), name_offset (23) into a u32; format 2 adds an i32 addend; format 3 uses a 16-bit lib_ordinal, a 32-bit name_offset and a u64 addend. lib_ordinal is 1-based into the LC_LOAD_DYLIB list; 0 means this image, −1 the main executable, −2 a flat lookup, −3 weak.

The tool reads the header, the imports and the pointer_format of the first segment with fixups. It does not walk the chains: it decodes each slot it needs on demand, with the rules in the next section.

6Chained pointer formats

The pointer_format decides how a 64-bit slot is split. The formats an iOS app uses:

Value Name Used by Stride of next
2 DYLD_CHAINED_PTR_64 arm64 / x86_64, target is a vmaddr 4 bytes
6 DYLD_CHAINED_PTR_64_OFFSET arm64 apps: target is an offset from the image base 4 bytes
1 DYLD_CHAINED_PTR_ARM64E arm64e, target is a vmaddr 8 bytes
9 DYLD_CHAINED_PTR_ARM64E_USERLAND arm64e user space, target is an offset 8 bytes
12 DYLD_CHAINED_PTR_ARM64E_USERLAND24 as 9, with 24-bit bind ordinals 8 bytes

DYLD_CHAINED_PTR_64 and _64_OFFSET

rebase   bits  0–35  target      vmaddr (format 2) or offset from the image base (format 6)
         bits 36–43  high8       top byte of the pointer (tagged pointers), shifted to bits 56–63
         bits 44–50  reserved
         bits 51–62  next
         bit  63     bind = 0

bind     bits  0–23  ordinal     index into the import table
         bits 24–31  reserved
         bits 32–39  addend
         bits 40–50  reserved
         bits 51–62  next
         bit  63     bind = 1

arm64e formats

Bit 63 says whether the pointer is authenticated (dyld signs it with a PAC key when it writes it), bit 62 whether it is a bind:

rebase        bits  0–42  target     vmaddr (format 1) or offset (9, 12)
(auth 0)      bits 43–50  high8
              bits 51–61  next       bit 62 bind = 0, bit 63 auth = 0

auth rebase   bits  0–31  target     always an offset from the image base
(auth 1)      bits 32–47  diversity  16-bit constant mixed into the signature
              bit  48     addrDiv    also mix in the slot's own address
              bits 49–50  key        0 IA · 1 IB · 2 DA · 3 DB
              bits 51–61  next       bit 62 bind = 0, bit 63 auth = 1

bind          bits  0–15  ordinal    (0–23 in USERLAND24)
(auth 0)      bits 32–50  addend
              bits 51–61  next       bit 62 bind = 1, bit 63 auth = 0

auth bind     bits  0–15  ordinal    (0–23 in USERLAND24)
(auth 1)      bits 32–47  diversity · bit 48 addrDiv · bits 49–50 key
              bits 51–61  next       bit 62 bind = 1, bit 63 auth = 1

A worked example (format 6, image base 0x100000000):

slot  0x0010_0000_0000_7f40   bit 63 = 0 → rebase
      target = 0x7f40, high8 = 0, next = 2 (next fixup 8 bytes on)
      → points at 0x100007f40

slot  0x8000_0000_0000_0012   bit 63 = 1 → bind, ordinal 0x12
      → imports[18], e.g. _OBJC_CLASS_$_NSURLSession from Foundation

Without chained fixups (LC_DYLD_INFO files), the tool takes the low 48 bits of a slot as a plain vmaddr.

7Symbols: LC_SYMTAB and LC_DYSYMTAB

LC_SYMTAB gives symoff, nsyms, stroff, strsize. The symbol table is an array of 16-byte nlist_64:

Offset Size Field Meaning
0 4 n_strx Offset of the name in the string table.
4 1 n_type Bits 0xe0 N_STAB (debug entry); 0x10 N_PEXT; 0x0e N_TYPE: 0 undefined, 2 absolute, 0xe defined in a section, 0xa indirect; 0x01 N_EXT (external).
5 1 n_sect 1-based section number, for N_SECT.
6 2 n_desc For undefined symbols, the library ordinal in the high byte; weak flags.
8 8 n_value The address, for defined symbols.

Names carry a leading underscore (_main, _$s5MyApp…, -[Foo bar] has none). Release App Store builds are stripped: only exported and imported symbols remain, so most functions have no name and the Objective-C and Swift metadata become the best source of names.

LC_DYSYMTAB splits the symbol table into locals, external definitions and undefined symbols (ilocalsym/nlocalsym, iextdefsym/nextdefsym, iundefsym/nundefsym), and points at the indirect symbol table (indirectsymoff, nindirectsyms): an array of u32 symbol indices, one per entry of every stub and pointer section, starting at that section's reserved1. This is how a classic reader names a stub: stub k in __stubs → indirect[reserved1 + k] → nlist → name.

The tool uses the defined (N_SECT, non-stab) symbols to name functions, and names stubs by decoding them instead (Stubs and GOT).

8Function starts, code signature, encryption

LC_FUNCTION_STARTS

A list of ULEB128 deltas: the first is the distance from the start of __TEXT to the first function, each next one the distance from the previous function; a 0 ends the list. It survives stripping, so it gives the start (and therefore the end) of every function, even unnamed ones.

blob   b0 8f 01  08  9c 02  00
       0x47b0 → first function at __TEXT + 0x47b0 = 0x1000047b0
       0x08   → 0x1000047b8
       0x11c  → 0x1000048d4
       0      → end

LC_CODE_SIGNATURE

The signature is a big-endian SuperBlob (magic 0xfade0cc0) with an index of blobs: the CodeDirectory (0xfade0c02: hashes of every 4 KB or 16 KB page, the team ID, the bundle identifier and flags), the requirements (0xfade0c01), the entitlements as an XML plist (0xfade7171) and in DER form (0xfade7172), and the CMS signature (0xfade0b01). The entitlements tell you which capabilities the app was granted: keychain access groups, app groups, associated domains, get-task-allow (debuggable builds)…

LC_ENCRYPTION_INFO_64

cryptoff (u32), cryptsize (u32), cryptid (u32), pad. With cryptid = 1 the range [cryptoff, cryptoff + cryptsize) of the file is FairPlay-encrypted: every app downloaded from the App Store is. The range starts after the load commands and covers the code and read-only data of __TEXT — the instructions, __cstring, the selector and class names in __objc_methname / __objc_classname, the Swift names. The kernel decrypts the pages on load, on a device the app is authorized for.

On an encrypted binary the disassembly and strings are random bytes, and the Objective-C and Swift lists still parse (they live in the data segments) but their names point into encrypted text. Analyse a decrypted copy (cryptid = 0), dumped from memory on a device. The tool shows an encrypted (cryptid 1) badge in the overview.

9Libraries, rpaths and the entry point

dylib_command

Offset Field Meaning
+8 name.offset lc_str: the library's install name.
+12 timestamp Unused.
+16 current_version X.Y.Z packed as 16.8.8 bits.
+20 compatibility_version Same packing.

Install names are absolute (/System/Library/Frameworks/UIKit.framework/UIKit, /usr/lib/libobjc.A.dylib, /usr/lib/swift/libswiftCore.dylib) or relative to a variable: @executable_path/, @loader_path/ (the directory of the image doing the loading), and @rpath/, which dyld tries against each LC_RPATH entry in turn. Embedded frameworks are typically @rpath/Foo.framework/Foo with an rpath of @executable_path/Frameworks.

The list is a quick inventory of what the app uses: Security, LocalAuthentication (biometrics), CryptoKit, WebKit, third-party SDKs (analytics, crash reporting, jailbreak detection, RASP). A weak library may be absent at run time; that and writable rpath directories are what library-hijacking attacks look for (mostly relevant on macOS).

LC_MAIN

entryoff (u64): offset of main from the start of the image's __TEXT (equal to its file offset in the slice), and stacksize (u64, 0 = default). dyld calls it after running initializers (__mod_init_func / __init_offsets, +load methods) — code that runs before main is a common place for anti-debugging checks.

10Stubs and GOT

Code never calls an imported function directly. A call goes to a small stub in __TEXT that loads the target from a pointer slot in data, filled by dyld.

Section Contents
__got Non-lazy pointers to imported symbols (functions and data, e.g. _OBJC_CLASS_$_NSString, ___stack_chk_guard), bound at load.
__auth_got arm64e: the same, but each pointer is signed (PAC) with an address-diversified key.
__stubs One 12-byte stub per imported function.
__auth_stubs arm64e: 16-byte stubs that authenticate the pointer as they branch.
__objc_stubs Xcode 14+: one stub per selector sent with objc_msgSend, named _objc_msgSend$selector, which loads the selector into x1 itself — so call sites no longer load it.
__la_symbol_ptr, __stub_helper Older lazy binding: the pointer first leads to the stub helper, which asks dyld to bind on the first call.
__stubs (arm64)                         __auth_stubs (arm64e)
adrp  x16, _ptr@PAGE                    adrp  x17, _ptr@PAGE
ldr   x16, [x16, _ptr@PAGEOFF]          add   x17, x17, _ptr@PAGEOFF
br    x16                               ldr   x16, [x17]
                                        braa  x16, x17       ; authenticate with the slot address

__objc_stubs
adrp  x1, selRef@PAGE
ldr   x1, [x1, selRef@PAGEOFF]          ; x1 = @selector(…)
adrp  x16, _objc_msgSend@GOTPAGE
ldr   x16, [x16, _objc_msgSend@GOTPAGEOFF]
br    x16

The tool names a call into any *stub* section by decoding the stub's first instructions: a load into x1 from __objc_selrefs makes it objc_msgSend$selector; otherwise the first pointer it loads is looked up as a chained-fixup bind (the import's name) or a known symbol.

11Objective-C metadata

The Objective-C runtime needs every class, method, ivar, property and protocol described in the binary, even when the symbols are stripped. That is why an ObjC or mixed app is so readable: the selectors and type encodings are all there. All pointers below are 8-byte slots subject to fixups.

Sections

Section Contents
__objc_imageinfo version u32, flags u32. Flags bit 6 HAS_CATEGORY_CLASS_PROPERTIES…; bits 8–15 the Swift version that built the image (pre-stable: 7 = Swift 5.x), bits 16–31 the stable Swift ABI version.
__objc_classlist Pointers to every class defined here (class_t).
__objc_nlclslist Classes with a +load method (non-lazy).
__objc_catlist Pointers to categories.
__objc_nlcatlist Categories with +load. The same category also appears in __objc_catlist.
__objc_catlist2 Categories on classes defined in the same image, attached early (newer linkers).
__objc_protolist Pointers to protocols.
__objc_selrefs One slot per selector used by the code, pointing at its name in __objc_methname. dyld uniques them so selectors compare by pointer.
__objc_classrefs Classes the code references ([NSString …]): a rebase to a local class or a bind to _OBJC_CLASS_$_Name.
__objc_superrefs Superclasses used by [super …] calls.
__objc_ivar One u32 (or u64) per ivar: its offset in the object, so the runtime can slide ivars when a superclass grows (non-fragile ivars).
__objc_data The class_t objects (class and metaclass).
__objc_const class_ro_t, method, ivar, property and protocol lists.
__objc_methname · classname · methtype C strings: selectors, class names, type encodings (in __TEXT).

class_t (objc_class)

Offset Field Meaning
0x00 isa The metaclass (which holds the class methods).
0x08 superclass Rebase to a local class, or bind to an imported one (_OBJC_CLASS_$_UIViewController).
0x10 cache Bound to __objc_empty_cache.
0x18 vtable Unused (0).
0x20 data Pointer to the class_ro_t. Low bits are flags: bit 0 Swift (legacy), bit 1 Swift (stable ABI).

Swift classes on Apple platforms are also Objective-C classes, so they are in __objc_classlist too, with a mangled name such as _TtC5MyApp14LoginViewModel, and Swift class metadata continues after these five words.

class_ro_t

Offset Field Meaning
0x00 flags u32: 0x1 META, 0x2 ROOT, 0x4 HAS_CXX_STRUCTORS, 0x10 HIDDEN, 0x20 EXCEPTION, 0x80 IS_ARC…
0x04 instanceStart u32: offset of the first ivar of this class.
0x08 instanceSize u32: object size.
0x10 ivarLayout Strong-ivar bitmap.
0x18 name Class name.
0x20 baseMethods method_list_t (instance methods, or class methods in a metaclass).
0x28 baseProtocols protocol_list_t.
0x30 ivars ivar_list_t.
0x38 weakIvarLayout Weak-ivar bitmap.
0x40 baseProperties property_list_t.

method_list_t

A u32 entsizeAndFlags and a u32 count, then the entries. Bit 31 of the first word (0x80000000) marks a relative method list (iOS 14+ deployment targets), which is smaller and needs no fixups:

classic entry (24 bytes)          relative entry (12 bytes, each field an i32 from its own address)
+0   name    SEL / char*          +0   name    → a slot in __objc_selrefs (the selector)
+8   types   char*                +4   types   → the type encoding string
+16  imp     code pointer         +8   imp     → the implementation (0 for none)

The type encoding describes the return value and arguments: v24@0:8@16 is void, total argument size 24, self (@) at 0, _cmd (:) at 8, one object argument at 16. Codes: v void, @ id (@"NSString" typed, @? block), # Class, : SEL, c/B char / BOOL, i int, q long long, Q unsigned long long, f float, d double, ^ pointer, * char *, {CGRect=…} struct.

ivar_list_t, property_list_t, protocol_list_t

List Header Entry
ivar_list_t entsize u32, count u32 offset → u32 in __objc_ivar · name · type (encoding) · alignment u32 · size u32 (32 bytes)
property_list_t entsize u32, count u32 name · attributes (16 bytes). Attributes: T@"NSString",C,N,V_token = type NSString, copy, nonatomic, backed by ivar _token; R readonly, & strong, W weak, G/S custom getter / setter, D dynamic.
protocol_list_t count u64 Pointers to protocol_t.

protocol_t and category_t

protocol_t                              category_t
+0x00  isa                              +0x00  name
+0x08  name                             +0x08  cls               (rebase or bind)
+0x10  protocols         (inherited)    +0x10  instanceMethods
+0x18  instanceMethods   (required)     +0x18  classMethods
+0x20  classMethods      (required)     +0x20  protocols
+0x28  optionalInstanceMethods          +0x28  instanceProperties
+0x30  optionalClassMethods             +0x30  classProperties
+0x38  instanceProperties
+0x40  size, flags, extendedMethodTypes…

Protocol method lists have no implementations. Categories add methods to existing classes, often system ones (NSString (Crypto), UIDevice (Jailbreak)), so they are worth reading on their own.

12Swift metadata

Swift writes compile-time descriptions of its types for reflection, dynamic casts and the runtime's type lookup. Unlike ObjC, these use relative pointers: an i32 stored at address A means A + value, so the data needs no fixups and lives in __TEXT (__const, __constg_swiftt).

Sections

Section Contents
__swift5_types An array of i32 relative pointers to the type context descriptors of every class, struct and enum defined here.
__swift5_protos Relative pointers to protocol descriptors.
__swift5_proto Relative pointers to protocol conformance descriptors: protocol (indirectable), conforming type, witness table pattern, flags. One per extension T: P.
__swift5_fieldmd Field descriptors: the stored properties of structs and classes and the cases of enums.
__swift5_reflstr The field names (C strings), referenced from field records.
__swift5_typeref Mangled type names referenced by field records.
__swift5_assocty Associated-type witnesses of conformances.
__swift5_builtin 20-byte descriptors of builtin types (type name, size, alignment and flags, stride, extra inhabitants).
__swift5_capture Closure capture descriptors.
__swift5_mpenum Multi-payload enum layouts.

Context descriptors

Every descriptor starts with the same two fields; type descriptors add a name, an accessor and the field descriptor:

Offset Field Meaning
+0 flags u32: bits 0–4 kind (0 module, 1 extension, 2 anonymous, 3 protocol, 4 opaque type, 16 class, 17 struct, 18 enum); bit 6 unique; bit 7 generic; bits 16–31 kind-specific flags.
+4 parent Relative indirectable pointer to the enclosing context (a module, a type, an extension). Following it gives the qualified name MyApp.LoginViewModel.State.
+8 name Relative pointer to the C-string name.
+12 accessFunction Relative pointer to the metadata accessor (…Ma), the function code calls to get the type's metadata.
+16 fields Relative pointer to the field descriptor.
+20 struct / enum struct: numFields, fieldOffsetVectorOffset. enum: numPayloadCasesAndPayloadSizeOffset, numEmptyCases.
+20 … +43 class superclassType (mangled name), metadata bounds (2 words), numImmediateMembers, numFields, fieldOffsetVectorOffset: 44 bytes in all.

Field descriptors

FieldDescriptor (16 bytes)            FieldRecord (fieldRecordSize, normally 12)
+0   mangledTypeName   rel            +0   flags             u32 (indirect case, var vs let)
+4   superclass        rel            +4   mangledTypeName   rel → __swift5_typeref
+8   kind              u16            +8   fieldName         rel → __swift5_reflstr
+10  fieldRecordSize   u16
+12  numFields         u32
+16  FieldRecord[numFields]

kind: 0 struct, 1 class, 2 enum, 3 multi-payload enum, 4 protocol, 5 class protocol, 6 ObjC protocol, 7 ObjC class. Mangled type names may contain symbolic references: a byte 0x01 followed by an i32 is a direct relative reference to a context descriptor, 0x02 an indirect one through a pointer slot. Otherwise the name is ordinary mangling (SS = String, Si = Int, Sb = Bool, a trailing Sg = Optional).

Class vtables and override tables

After the 44-byte class descriptor come optional trailing objects, announced by kind-specific flags: generic parameters and requirements (flag 0x80 in flags), a resilient superclass (0x2000), metadata-initialization records (bits 0–1), then:

These are the only place a stripped Swift binary lists its class methods with their implementations. Structs and enums have no vtable: their methods are called directly and only appear as code. Methods marked final are not in the vtable either.

13Swift name mangling

Swift symbols encode the full context and type of an entity. Swift 5 symbols start with $s (in the symbol table _$s; Swift 4.x used $S, older ones _T0). ObjC-visible class names use the older _TtC form: _TtC5MyApp9AppDelegate.

Building blocks

Suffix Entity Suffix Entity
F function Ma type metadata accessor
fC allocating initializer (init) Mn nominal type descriptor
fc initializer (non-allocating) MN · Mf type metadata · full metadata
fD · fd deinit Mp · Mc protocol descriptor · conformance descriptor
vg · vs property getter · setter WP · Wl protocol witness table · its lazy accessor
vM · vr modify · read coroutine TW protocol witness thunk
vW · vw didSet · willSet To @objc thunk (the ObjC entry point of a Swift method)
Z static TR · Tr reabstraction thunk
fU · fu closure TA · Tq · Tj partial apply · method descriptor · dispatch thunk

Examples

$s5MyApp4UserC4nameSSvg               MyApp.User.name.getter        (String)
$s5MyApp4UserC4nameACSS_tcfC          MyApp.User.init(name: String)
$s5MyApp0B10ControllerC5loginyyF      MyApp.AppController.login()   0B = word "App", + "Controller"
$s5MyApp0B10ControllerCMa             MyApp.AppController metadata accessor
$s5MyApp0B10ControllerC11viewDidLoadyyFTo   …viewDidLoad @objc thunk
$s3XPC0A16_TYPE_DICTIONARYs13OpaquePointerVvg   XPC.XPC_TYPE_DICTIONARY.getter

In 0B10Controller, the words collected so far are My (0, a) and App (1, b); B reuses word 1 and ends the list, and 10Controller is the literal rest. The parameter and result types between the name and the suffix (yyF = no parameters, returns ()) are skipped by the tool's demangler, which recovers the context path, the entity name and the kind — enough to read a call. Use swift demangle for the full signature.

14arm64e pointer authentication

arm64e (Apple A12 and later, used by system binaries; third-party apps are normally plain arm64) adds pointer authentication codes: a signature, computed from the pointer, a 64-bit modifier and a secret key, stored in the unused top bits of the pointer. Authenticating a pointer whose signature does not match makes it invalid (or traps, with FPAC), so an attacker cannot forge return addresses or function pointers.

Key Used for
IA Code pointers: function pointers, block invoke pointers, C++ vtable entries, __auth_got.
IB Return addresses (with SP as the modifier).
DA · DB Data pointers: ObjC isa, vtable pointers, selected data fields.
GA Generic: pacga computes a 32-bit MAC of arbitrary data.

Instructions

Instruction Effect
pacibsp · paciasp Sign LR (x30) with SP as modifier. First instruction of a function that saves LR.
autibsp · autiasp Authenticate LR before using it.
retab · retaa Authenticate LR (B / A key, SP modifier) and return, in one instruction.
braa xN, xM · brab Authenticate xN with modifier xM and branch (tail calls, stubs).
blraa xN, xM · blrab Authenticate and call (calls through function pointers, block invokes).
braaz · blraaz · retaaz… The same with a zero modifier.
pacia · pacda · autia · autda xD, xN Sign / authenticate a register with modifier xN. paciza / autiza… use zero.
xpaci · xpacd · xpaclri Strip the signature without checking it.
ldraa · ldrab Authenticate a data pointer (DA / DB, zero modifier) and load through it.
pacibsp                        ; sign the return address
stp   x29, x30, [sp, #-0x10]!
…
ldp   x29, x30, [sp], #0x10
retab                          ; authenticate and return

Before a tail call that leaves a function with an authenticated LR, the compiler checks the result explicitly, so a failure traps at once instead of later:

autibsp
eor   x16, x30, x30, lsl #1    ; bit 62 of x16 = bit 62 xor bit 63 of LR
tbz   x16, #62, 1f             ; the two top bits agree: authentication succeeded
brk   #0xc471                  ; trap
1: b  _objc_msgSend

Signed pointers in data are written by dyld from the auth chained fixups, whose key, diversity and address-diversity bits say how to sign them. In the file they hold only the target offset.

15Reading the page

What each part of the Mach-O tool shows, and which structure it comes from:

UI section Shows Read from
Overview chips and key/values Architecture, 32/64-bit, endianness, file type, load-command count, file size; magic, CPU type/subtype, flags; UUID, platform with minimum OS and SDK, source version, entry point, dynamic linker, encryption, symbol count. mach_header, LC_UUID, LC_BUILD_VERSION / LC_VERSION_MIN_*, LC_SOURCE_VERSION, LC_MAIN, LC_LOAD_DYLINKER, LC_ENCRYPTION_INFO(_64), LC_SYMTAB
Architecture buttons One per slice of a universal file; the rest of the page follows the selected slice. fat_arch
Segments & sections Each segment (vm address, vm size, file offset, file size, init / max protection, section count) and its sections (address, size, file offset, type). Hover a section for its type and attributes. LC_SEGMENT_64, section_64
Linked libraries Every library with current / compatibility version and a weak, re-export or upward tag; the install name of a dylib; the run-path search paths. LC_LOAD_*DYLIB, LC_ID_DYLIB, LC_RPATH
Objective-C Image info (ObjC flags, Swift version), counts, and a browser: classes (Swift classes nested under Swift › module), Categories, Protocols. A class's overview lists its superclass, size, ro flags, protocols, class and instance methods (selector, type encoding, implementation address), ivars (type, size, offset) and properties (attributes). __objc_imageinfo, __objc_classlist, __objc_catlist / nlcatlist / catlist2, __objc_protolist and the lists they point to
Swift Counts of types, protocols, conformances, builtin types; a browser of classes, structs and enums by module path, with their fields or cases and types; for classes, the vtable and override-table methods with implementation addresses; the protocol list. __swift5_types(2), __swift5_fieldmd, class descriptor trailing objects, __swift5_protos; conformances and builtins are counted from __swift5_proto / __swift5_builtin
Load commands Every command with its number, name, raw value and size, and its decoded fields. All load commands

The class browser

The assembly listing

Only the header and load commands are read up front; Objective-C and Swift metadata are parsed on demand from the sections that hold them, for 64-bit slices only. Binaries with LC_DYLD_INFO instead of chained fixups have their imported references (superclasses, classes referenced from code) left unresolved, because the bind opcodes are not executed. On FairPlay-encrypted binaries names and code are unreadable.

Functions, imports, strings and cross-references

For arm64 slices the tool makes one pass over all code (__text and the other executable sections, split at LC_FUNCTION_STARTS). It records every bl/b target, every address formed with adrp+add, adrp+ldr, adr or a literal load, and what each stub in __stubs / __auth_stubs / __objc_stubs stands for. That index feeds:

Annotations and keys

In the code browsers, Rename (n) names a function everywhere it appears (calls, Called by, Functions); double-clicking a variable in the decompiled view renames it in that function; Comment (;) adds a comment to the selected instruction in the Assembly view, or to the function. Annotations are kept in the browser's local storage per binary (by LC_UUID) and can be exported and imported as JSON under Functions. Other keys: g go to an address or name, x jump to Called by, Tab switch Decompiled / Assembly, Alt+←/→ back and forward through what you opened, / filter, ? list the keys. Export downloads every method of the selected class, decompiled, as Markdown.

16SwiftDemangler

lib/swift-demangle.js makes Swift mangled symbols ($s…, _$s…, $S…, _T0…) readable for the function lists and the decompiled view. It is not a full demangler: it recovers the context (module and types), the entity name and what kind of entity the symbol is (function, getter, init, metadata accessor, thunk…), following the identifier and word-substitution rules described in Swift name mangling. The libraries are JavaScript modules that export one class each; a page or a module worker imports them (paths relative to the importing file), and each module imports its own dependencies. This one has none:

import { SwiftDemangler } from "../lib/swift-demangle.js";
Method What it does
SwiftDemangler.demangle(symbol) The readable name, or null when the symbol isn't a Swift symbol or doesn't parse. Kinds that name a member are written after a dot (.getter, .init), others after a space ( metadata accessor); functions end in ().
SwiftDemangler.demangle("$s3XPC0A16_TYPE_DICTIONARYs13OpaquePointerVvg");   // "XPC.XPC_TYPE_DICTIONARY.getter"
SwiftDemangler.demangle("$s4Main3FooCMa");                                  // "Main.Foo metadata accessor"
SwiftDemangler.demangle("objc_msgSend");                                    // null

The ARM64 disassembler and decompiler that the code view uses (lib/arm64-disasm.js, lib/decompiler-core.js, lib/arm64-decompiler.js) are documented in the ELF tool guide; the decompiler imports lib/swift-demangle.js for call names and variable-name hints.

17MachOImage

lib/macho.js reads Mach-O binaries — executables, dylibs, bundles, object files and universal (fat) binaries — from a Blob with ranged reads: the header and load commands first, the metadata sections only when asked. It decodes everything described in this guide: the fat header, mach_header, load commands, segments and sections, chained fixups (all pointer formats, arm64e included), symbols, function starts, stubs and GOT, and the Objective-C and Swift metadata (64-bit slices). No DOM; the code helpers use lib/arm64-disasm.js. Counts are capped so a crafted binary cannot hang the caller.

An instance of MachOImage is one thin Mach-O (one slice of a universal binary): its parsed fields plus the methods below. The module imports lib/arm64-disasm.js (for the Swift thunk scan).

import { MachOImage } from "../lib/macho.js";
Method What it does
MachOImage.parse(blob, fileName) Promise of { fileName, fileSize, fat, arches, machos }: one MachOImage per architecture (a thin file has one). A slice that fails to parse is { arch, error }. Throws on a file that is neither Mach-O nor universal.
MachOImage.parseSlice(blob, offset, arch) Promise of one thin Mach-O at a file offset (a MachOImage). Its fields: header (magic, le, b64, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags), headerName (arm64 (arm64e)), loadCommands ({ index, cmd, cmdName, cmdsize, detail }), segments with their sections, dylibs, idDylib, rpaths, linkedit (the __LINKEDIT blobs: function starts, chained fixups, code signature…), uuid, build, sourceVersion, main, encryption, dylinker, symtab, dysymtab, dyldInfo, truncated, and blob / fileOffset for later reads.
MachOImage.isMachO(bytes) True when the first four bytes are a Mach-O (either endianness, 32 or 64-bit) or universal magic.
slice.hasObjC(), slice.hasSwift(), slice.hasMetadata() Whether the slice has Objective-C class / category / protocol lists or __swift5_* sections.
slice.loadMetadata() Reads the metadata sections (once) and sets slice.objc ({ imageInfo, classes, categories, protocols }: each class with name, rawName, isSwift, superLabel, roFlags, instanceSize, methods, metaMethods, ivars, properties, protocols; method lists are { count, small, items: [{ sel, types, imp }] }), slice.swift ({ types, protocols, counts, builtins }: each type with kindName, name, qual (qualified), fields and, for classes, the vtable / override methods with their implementations), slice.metadataInfo ({ imageBase, ptrFmt, imports }) and slice.resolver. A 32-bit slice only gets slice.metadata32 = true.
slice.resolver Reads over the loaded sections: pointer(address) → { kind: "rebase", vmaddr }, { kind: "bind", ordinal }, { kind: "null" } or { kind: "oob" } (decodes the chained-fixup format); cString(address), uint32(address), uint64(address) (BigInt), importName(ordinal), classNameAt(classAddress), cleanClassName(symbol), sectionAt(address), imageBase.
slice.sectionAt(address), slice.vaToFileOffset(address), MachOImage.isCodeSection(section) The section holding an address; the file offset of an address (-1 when it is not backed by file data); whether a section holds instructions.
slice.functionStarts() Promise of every function start from LC_FUNCTION_STARTS (cached in slice.functionStartList).
slice.symbolMap() Promise of a Map address → name of the defined (N_SECT, non-stab) symbols, leading underscore removed (cached in slice.symbols; a viewer may add names, e.g. from a .symbols file).
slice.selectorRefName(address), slice.gotName(address) The selector an __objc_selrefs slot points at; the imported (or local) symbol a GOT slot holds. Need loadMetadata.
slice.stubName(address) Promise of the function a stub in __stubs / __auth_stubs calls, or objc_msgSend$selector for __objc_stubs, by decoding the stub's instructions.
slice.swiftThunkNames() Fills slice.thunks: the native implementation each @objc Swift method thunk calls → Class.method(label:), which names functions of a stripped Swift binary.
MachOImage.swiftSelector(selector) fooWithBar:baz: → foo(bar:baz:).
MachOImage.cpuName(type, subtype), flagList(value, table), protectionString(protection), readBytes(blob, start, end) Static helpers; tables MachOImage.CPU_ARM64, FILE_TYPES, HEADER_FLAGS, SWIFT_VERSIONS.
import { MachOImage } from "../lib/macho.js";

const file = await MachOImage.parse(blob, "MyApp");
const slice = file.machos.find(m => !m.error);
console.log(slice.headerName, slice.uuid, slice.dylibs.map(d => d.name));
await slice.loadMetadata();
for (const cls of slice.objc ? slice.objc.classes : []) {
	console.log(cls.name, ":", cls.superLabel, (cls.methods ? cls.methods.items : []).map(m => m.sel));
}
const starts = await slice.functionStarts();

18MachOCrossReferences

lib/macho-xref.js indexes the code of an arm64 slice in one pass: direct calls (bl, and b leaving the function), the addresses each function computes (adrp+add, adrp+ldr, adr, literal loads) and what each stub stands for. The module imports lib/macho.js and lib/arm64-disasm.js; the class has static methods that take the slice (a MachOImage), and the results are cached on the slice.

import { MachOCrossReferences } from "../lib/macho-xref.js";
Method What it does
MachOCrossReferences.index(slice, onProgress) Promise of { starts, calls, refs }: function starts (LC_FUNCTION_STARTS, else symbols and method implementations), calls (target → [[function, site]]) and refs (address → [[function, site]]). Yields to the event loop while scanning and reports onProgress(fraction).
MachOCrossReferences.callersOf(slice, function, selector) [{ fn, site, how }]: who calls the function ("call"), takes its address ("ref") or, with a selector, sends that message through objc_msgSend$selector stubs or selector references ("send").
MachOCrossReferences.stringList(slice) Every C string (__cstring), os_log string, UTF-16 string (__ustring) and CFString, { addr, s, kind, uses: [{ fn, site }] }, with the functions that address it.
MachOCrossReferences.importList(slice) Imported functions (from the stubs) with their call sites, sorted by name.
MachOCrossReferences.stubIndex(slice) { byAddr, byName }: every stub and the import or objc_msgSend$selector it stands for.
MachOCrossReferences.functionContaining(slice, address) The start of the function containing an address.
MachOCrossReferences.sectionBytes(slice, section) A section's bytes (one read per section, cached).
await MachOCrossReferences.index(slice);
const strings = await MachOCrossReferences.stringList(slice);
for (const item of strings.filter(s => /https?:/.test(s.s))) {
	console.log(item.s, item.uses.map(use => "0x" + use.fn.toString(16)));
}
const callers = await MachOCrossReferences.callersOf(slice, implementationAddress, "viewDidLoad");

19SymbolsFile

lib/symbols-file.js reads Apple .symbols files: the files Xcode puts in an IPA's Symbols/ folder when an app is exported with “Upload your app's symbols”, one per binary, named after its UUID. Each holds what CoreSymbolication extracted from the binary's dSYM: segments and sections, every symbol (name, address, size), inlined calls with their call sites, and address → file:line tables. The format is not documented; the reader follows files written by Xcode 16–26. A module with no dependencies:

import { SymbolsFile } from "../lib/symbols-file.js";
Method What it does
SymbolsFile.parse(bytes) A SymbolsFile with { uuid, cpu, arch, created, dsymPath, bundle, binaryName, base, segments, sections, symbols: [{ addr, size, name, raw, flags, func, ext, file, line }], inlined, lines, files: [{ path, name, functions, lines }], counts, errors }. Throws when the bytes are not a .symbols file.
symbols.linesIn(address, end), symbols.inlinedIn(address, end) The line entries / inlined calls in [address, end).
symbols.symbolAt(address) The symbol containing an address, or null.
SymbolsFile.isSymbols(bytes), SymbolsFile.header(bytes) Whether the bytes start like a .symbols file; just the header { uuid, cpu, arch, created, dsymPath, bundle, binaryName }.
SymbolsFile.machoUUIDs(read) Promise of the LC_UUIDs of a Mach-O (thin or universal), [{ cpu, arch, uuid }], to match .symbols files to binaries; read(offset, length) returns a Promise of bytes.
SymbolsFile.MAGIC The file's magic number, 0xff01ff02.
const symbols = SymbolsFile.parse(new Uint8Array(await file.arrayBuffer()));
console.log(symbols.binaryName, symbols.uuid, symbols.counts.functions);
const symbol = symbols.symbolAt(0x100004440);
console.log(symbol.name, symbol.file + ":" + symbol.line, symbols.linesIn(symbol.addr, symbol.addr + symbol.size));