Mach-O Binary Teardown
A Mach-O teardown reads the structure of an iOS or macOS binary. The teardown gives you the header, the load commands, the segment and section table, the linked libraries, the build version, the code signature, the entitlements, and the encryption state.
Run the teardown
bash scripts/teardown.sh app.ipa
The header
otool -hv <binary>
| Field | Meaning |
magic | MH_MAGIC_64 is a 64-bit file |
cputype | ARM64 is a device build, X86_64 is a simulator build |
filetype | EXECUTE is an app, DYLIB is a library, BUNDLE is a framework |
flags | PIE means the address space is randomized |
The load commands
otool -l <binary>
| Load command | Meaning |
LC_SEGMENT_64 | A segment that holds the sections |
LC_SYMTAB | The symbol table. The nsyms value holds the count. |
LC_DYSYMTAB | The import table and the export table |
LC_LOAD_DYLIB | A linked library |
LC_ID_DYLIB | The install name of a library |
LC_UUID | The build identifier |
LC_BUILD_VERSION | The minimum OS and the SDK |
LC_ENCRYPTION_INFO_64 | The encryption state. A cryptid of 1 means the code is encrypted. |
LC_CODE_SIGNATURE | The code signature |
LC_RPATH | A runtime search path |
LC_MAIN | The entry point of an executable |
The segments and the sections
| Segment | Section | Content |
__TEXT | __text | The machine code |
__TEXT | __cstring | The C string literals. This section holds the URLs. |
__TEXT | __const | The constant data |
__TEXT | __swift5_reflstr | The Swift reflection strings |
__TEXT | __swift5_types | The Swift type descriptors |
__TEXT | __objc_classname | The Objective-C class names |
__TEXT | __objc_methname | The Objective-C selector names |
__DATA | __objc_classlist | The list of the class pointers |
__DATA | __objc_selrefs | The pointers to the selector strings |
__DATA | __got | The global offset table |
__LINKEDIT | — | The symbol table, the string table, the code signature |
The __TEXT.__cstring section is the most important section for the endpoint scan.
The entitlements
codesign -d --entitlements - --xml app.app
| Entitlement | Meaning |
application-identifier | The bundle identifier of the team |
com.apple.security.application-groups | The shared containers |
keychain-access-groups | The shared keychain items |
com.apple.developer.associated-domains | The universal links |
aps-environment | The push environment. development means a debug build. |
com.apple.developer.healthkit | The HealthKit access |
com.apple.developer.in-app-payments | The Apple Pay access |
The runtime search paths
otool -l <binary> | grep -A2 LC_RPATH
@executable_path/Frameworks means the app ships its own frameworks. /usr/lib/swift means the app uses the system libraries.
The encryption state
otool -l <binary> | grep -A6 LC_ENCRYPTION_INFO
cryptid | Meaning |
| 1 | The code is encrypted. The strings are unreadable. |
| 0 | The code is decrypted. The strings are readable. |
The architectures
lipo -archs <binary>
file <binary>
| Architecture | Meaning |
arm64 | A device build |
arm64e | A device build with pointer authentication |
armv7 | An old device build |
x86_64 | A simulator build |
Always analyze the arm64 slice.