ios-reverse-engineering-skill iOS Reverse & Tweak Engineering Suite

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.

Get the skill Extract the APIs

Run the teardown


bash scripts/teardown.sh app.ipa

The header


otool -hv <binary>
FieldMeaning
magicMH_MAGIC_64 is a 64-bit file
cputypeARM64 is a device build, X86_64 is a simulator build
filetypeEXECUTE is an app, DYLIB is a library, BUNDLE is a framework
flagsPIE means the address space is randomized

The load commands


otool -l <binary>
Load commandMeaning
LC_SEGMENT_64A segment that holds the sections
LC_SYMTABThe symbol table. The nsyms value holds the count.
LC_DYSYMTABThe import table and the export table
LC_LOAD_DYLIBA linked library
LC_ID_DYLIBThe install name of a library
LC_UUIDThe build identifier
LC_BUILD_VERSIONThe minimum OS and the SDK
LC_ENCRYPTION_INFO_64The encryption state. A cryptid of 1 means the code is encrypted.
LC_CODE_SIGNATUREThe code signature
LC_RPATHA runtime search path
LC_MAINThe entry point of an executable

The segments and the sections

SegmentSectionContent
__TEXT__textThe machine code
__TEXT__cstringThe C string literals. This section holds the URLs.
__TEXT__constThe constant data
__TEXT__swift5_reflstrThe Swift reflection strings
__TEXT__swift5_typesThe Swift type descriptors
__TEXT__objc_classnameThe Objective-C class names
__TEXT__objc_methnameThe Objective-C selector names
__DATA__objc_classlistThe list of the class pointers
__DATA__objc_selrefsThe pointers to the selector strings
__DATA__gotThe 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
EntitlementMeaning
application-identifierThe bundle identifier of the team
com.apple.security.application-groupsThe shared containers
keychain-access-groupsThe shared keychain items
com.apple.developer.associated-domainsThe universal links
aps-environmentThe push environment. development means a debug build.
com.apple.developer.healthkitThe HealthKit access
com.apple.developer.in-app-paymentsThe 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
cryptidMeaning
1The code is encrypted. The strings are unreadable.
0The code is decrypted. The strings are readable.

The architectures


lipo -archs <binary>
file <binary>
ArchitectureMeaning
arm64A device build
arm64eA device build with pointer authentication
armv7An old device build
x86_64A simulator build

Always analyze the arm64 slice.