Skip to main content
Be Bitwise

iOS App Structure & Code Signing

iOS Internals · Mobile Internals track

6 min read

In this module

The IPA Package

iOS apps ship as IPA files. Fancy extension, ordinary contents — an IPA is a ZIP archive with a specific layout inside. Knowing that layout matters for both security work and reverse engineering, because everything you'll want to poke at lives at known paths.

bash
# Unzipping an IPA reveals its structure
MyApp.ipa (ZIP archive)
Payload/
MyApp.app/ # The application bundle
MyApp # Mach-O executable binary
Info.plist # Application metadata
_CodeSignature/ # Code signature directory
CodeResources # Signed resource manifest
embedded.mobileprovision # Provisioning profile
Assets.car # Compiled asset catalogue
Base.lproj/ # Localised resources
Frameworks/ # Embedded frameworks

Payload/ holds exactly one .app bundle — a directory that macOS and iOS treat as a single first-class object. Inside you'll find the compiled binary, the resources, and the signatures iOS will check before it lets any of it run.

The Mach-O Binary

The executable inside the bundle is a Mach-O (Mach Object) file. It's the native binary format across all of Apple's platforms. Every iOS binary opens with a header that pins down its format and target architecture.

c
// Mach-O 64-bit header structure
struct mach_header_64 {
uint32_t magic; // 0xFEEDFACF (64-bit Mach-O)
int32_t cputype; // CPU_TYPE_ARM64
int32_t cpusubtype; // CPU_SUBTYPE_ARM64_ALL
uint32_t filetype; // MH_EXECUTE, MH_DYLIB, etc.
uint32_t ncmds; // Number of load commands
uint32_t sizeofcmds; // Size of all load commands
uint32_t flags; // Flags (PIE, MH_TWOLEVEL, etc.)
uint32_t reserved; // Reserved (64-bit padding)
};

0xFEEDFACF is 64-bit Mach-O. The 32-bit cousin is 0xFEEDFACE. A file can also be a fat (universal) binary that bundles several architectures: it opens with 0xCAFEBABE and a table pointing at a complete Mach-O for each slice, so tools pick a slice first (lipo -info lists them). After the header come load commands, the recipe for getting this binary into memory. Between them they spell out:

  • Segments: Contiguous regions of the binary mapped into memory. The three primary segments are:
    • __TEXT - executable code and read-only constants (mapped r-x)
    • __DATA - mutable global variables and pointers (mapped rw-)
    • __LINKEDIT - symbol tables, string tables, and code signature data
  • Library dependencies: Which dynamic libraries (dylibs) the binary links against.
  • Code signature location: Where the signature data lives within the file.
  • Encryption info: In App Store apps, LC_ENCRYPTION_INFO_64 marks a range of __TEXT as FairPlay-encrypted (cryptid 1). The kernel decrypts it at load time on an authorised device, but on disk it's ciphertext, so class-dump and disassemblers see garbage until you dump the decrypted image from a running process.

Click through the header fields and the load commands a typical arm64 app binary carries. Each one shows the bytes it starts with, so you'll recognise them in a hex editor:

Mach-O (Apple)

Click a section to explore its structure and purpose

Mach-O Format

Mach-O is the executable format across Apple's platforms. A 64-bit file opens with 0xFEEDFACF, then a stream of load commands describing segments (__TEXT, __DATA, __LINKEDIT), library dependencies, and the code signature. Every iOS reverse-engineering session ends up reading one.

Code Signing and AMFI

iOS enforces mandatory code signing with no third-party escape hatch. Every page of executable code must be signed by a trusted certificate, and the check doesn't stop at install time. Each page is re-verified at page-in — every time it's pulled from disk into memory.

The enforcer is AMFI (Apple Mobile File Integrity), a kernel extension wired into the virtual memory subsystem. When the VM goes to page in some code, AMFI:

  1. Computes a hash of the page content.
  2. Compares it against the hash stored in the code signature's CodeDirectory.
  3. Verifies the CodeDirectory is signed by a trusted Apple certificate.
  4. Allows or denies the page mapping based on the result.

Tamper with a binary on disk and the modified page fails verification when it tries to load. The same design also rules out runtime-generated code: JIT compilation is off-limits for third-party apps because nobody outside Apple holds the keys to sign new pages. The exceptions are gated behind special entitlements: Apple's own WebKit content processes (which run JavaScript for Safari and every app's web views), and, since iOS 17.4 in the EU, approved alternative browser engines.

The dyld Dynamic Linker

At launch, the kernel maps the Mach-O into memory and passes the baton to dyld, the dynamic linker. From there, dyld handles:

  1. Mapping the binary's segments into the process's address space with ASLR (address space layout randomisation) applied.
  2. Loading all dependent dynamic libraries (dylibs) referenced in the Mach-O load commands.
  3. Binding symbol references - resolving function calls across library boundaries.
  4. Running initialisers - calling constructors and +load methods before main() executes.
bash
# Inspecting a Mach-O binary's dependencies
$ otool -L MyApp.app/MyApp
MyApp:
/usr/lib/libobjc.A.dylib
/usr/lib/libSystem.B.dylib
/System/Library/Frameworks/UIKit.framework/UIKit
/System/Library/Frameworks/Foundation.framework/Foundation

Modern iOS leans on the dyld shared cache: one giant pre-linked blob containing every system library. It runs to several gigabytes and gets mapped into every process, sparing the kernel from loading dylibs one by one. For researchers, pulling the cache apart is a rite of passage. It's how you find the system library code you actually want to read.

Security Implications

Stack the IPA structure, Mach-O, and mandatory code signing together and you get:

  • Every binary on the device traces a chain of trust back to Apple.
  • No unsigned code runs. Full stop. Not from disk, not from memory, not synthesised at runtime.
  • Tampering is caught page by page, not just at install time.
  • Reverse engineering demands fluency in Mach-O load commands, segment layout, and the dyld shared cache before you can even find the code you want to read.

That's why iOS exploitation looks nothing like desktop exploitation. On a Mac or PC, an attacker compiles a payload and runs it. On iOS, just getting your own code to execute at all is a research project in itself.