Recover Swift Symbols from a Stripped iOS Binary
An App Store build removes the symbol table. The binary keeps the type names, because the Objective-C runtime and the Swift runtime need those names at execution time. The recovery step mines that metadata and rebuilds an address to name index.
Why the names survive the strip
| Source | The section | The content |
|---|---|---|
| Objective-C metadata | __TEXT.__objc_classname | The class names |
| Objective-C metadata | __TEXT.__objc_methname | The selector names |
| Objective-C metadata | __DATA.__objc_selrefs | The pointers to the selectors |
| Swift reflection | __TEXT.__swift5_reflstr | The field names |
| Swift reflection | __TEXT.__swift5_types | The type descriptors |
| Compiler | __TEXT.__cstring | Every string literal |
Run the recovery
bash scripts/recover-names.sh app-teardown/binary/main.arm64 app-teardown/names
The step writes the files below.
| File | Content |
|---|---|
objc-classes.tsv | The Objective-C class names |
objc-methods.tsv | The class, the selector, and the address |
swift-types.txt | The demangled Swift type names |
swift-fields.txt | The field names from the reflection metadata |
swift-symbols.txt | The demangled Swift symbols |
mapping.tsv | The address, the name, and the kind |
mapping.json | The same data as JSON |
by_module/ | One file per module |
The selector pointer chain
A method list holds a pointer to the selector. That pointer points into __objc_selrefs. That section holds a pointer to the selector string. The string lives in __objc_methname. The chain has two hops.
method list → __objc_selrefs → __objc_methname → the selector text
The Swift demangling
A Swift class that inherits from NSObject keeps an Objective-C name. The name holds the Swift mangling.
| Mangled name | Demangled name |
|---|---|
_TtC7AlDente9Debouncer | AlDente.Debouncer |
_TtCV7AlDente12KeyPressView | AlDente.KeyPressView |
_TtP7AlDente13MyProtocol | AlDente.MyProtocol |
echo '_TtC7AlDente9Debouncer' | swift-demangle
The module name is the most valuable fact. The module name separates the first-party code from the third-party code.
Query the index
# Search a name
bash scripts/lookup-name.sh app-teardown/names LoginService
# Resolve an address
bash scripts/lookup-name.sh app-teardown/names --addr 0x10002d314
# List a module
bash scripts/lookup-name.sh app-teardown/names --module AlDente
# Search a source folder
bash scripts/lookup-name.sh app-teardown/names --grep 'login' ./sources
Real output from a stripped release build:
_TtC7AlDente32EnableHighPowerModeIntentHandler handleEnableHighPowerMode:completion: 0x10002d314
TtC7AlDente9Debouncer → AlDente.Debouncer
Combine the index with Ghidra
The index turns FUN_00101234 into a real name inside the decompiler.
- Run the teardown with the
--decompileoption. - Run
recover-names.shon the same slice. - Read the address in the decompiler.
- Run
lookup-name.sh --addrto get the name. - Read the class with the recovered name.
- The step finds the classes that the Objective-C runtime sees. A Swift struct or a Swift enum does not appear.
- The step does not restore the protocol conformances. The protocol list of the class dump holds that information.
- The step does not name the C functions. The C functions keep the
FUN_prefix in the decompiler. - The step does not restore the local variable names. No data in the binary holds those names.