MachOSwiftSection
A Swift library that recovers Swift metadata — types, protocols, conformances, field layouts — from Mach-O files and dyld shared caches without loading them into a process. It carries its own demangler, symbolic references included, and reimplements the Swift runtime's own reading logic.
On top of that model it generates complete Swift interfaces, diffs a module's ABI between two builds or tracks it across many versions, and computes field offsets and enum layouts statically. The companion swift-section CLI exposes all of it, and covers the Objective-C side of a binary as well.
[!NOTE]
This library is developed as an extension of MachOKit for Swift
Requirements
- Swift 6.3+
- Xcode 26.4+
- macOS 10.15+ / iOS 13+ / tvOS 13+ / watchOS 6+ / visionOS 1+
MachOSwiftSection Library
Roadmap
Swift Package Manager
Add the package to your Package.swift:
dependencies: [
.package(url: "https://github.com/MxIris-Reverse-Engineering/MachOSwiftSection", from: "0.25.0"),
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "MachOSwiftSection", package: "MachOSwiftSection"),
// Optional higher-level products:
.product(name: "SwiftSymbols", package: "MachOSwiftSection"),
.product(name: "SwiftInspection", package: "MachOSwiftSection"),
.product(name: "SwiftDump", package: "MachOSwiftSection"),
.product(name: "SwiftInterface", package: "MachOSwiftSection"),
]
),
]
Declare every product whose module you import. In particular, MachOSwiftSection does not re-export the symbol index (since 0.19.0): a file that uses SwiftSymbolIndexStore or DemangledSymbol needs import SwiftSymbols and the SwiftSymbols product on its target.
Since 0.25.0 the Mach-O layer underneath — MachOBase, MachOFoundation, MachODependencies, MachOSymbols, MachOCaches, MachOPointers, MachOReading, MachOResolving — comes from MachOKitExtensions 2.0.0 and later, under the same module names. Code that uses one of them directly (DependencyClosure, for instance, is in MachODependencies) declares that product with package: "MachOKitExtensions".
The ABI model and the Mach-O layer
| Product | Purpose |
|---|
MachOSwiftSection | The ABI model: the __swift5_* sections, every descriptor in them, and the wrappers built from them (Struct, Enum, Class, Protocol, ProtocolConformance, …). Depends on MachOBase only — no symbol index, no demangler. |
SwiftSymbols | The Swift symbol index: SwiftSymbolIndexStore demangles and classifies an image's Swift symbols, queried by offset, by name and by type member. |
MachOSwiftSection re-exports MachOKitExtensions' MachOBase (reading, address resolution and relative pointers — everything the ABI model sees). MachOBase, MachOFoundation and MachODependencies used to be products of this package; since 0.25.0 they are provided by MachOKitExtensions.
Analysis
| Product | Purpose |
|---|
SwiftInspection | Symbol attribution and runtime metadata analysis — SymbolicDemangler (formerly MetadataReader), EnumLayoutCalculator. |
SwiftObjCInterop | The Objective-C side of Swift types: @objc @implementation classes, Swift classes renamed for the ObjC runtime, @objc protocols declared in Swift, ObjC method tables and ancestor chains, ClassHierarchyDumper. Split out of SwiftInspection in 0.25.0. |
SwiftLayout | The static layout engine: field offsets, type layouts and enum layouts computed offline, the way the runtime computes them at load time. |
SwiftThunkAnalysis | Reads a type stored behind a metadata accessor thunk (availability-conditional opaque types, noncopyable fields) by evaluating its ARM64 code instead of running it, and ties a class's ObjC method table to its Swift members. |
CrossReferenceAnalysis | What each function of a loaded arm64 image calls and references — functions, Objective-C classes, Swift types — read from its machine code. MachOImage only. |
SwiftSpecialization | Runtime specialization of generic types (GenericSpecializer). |
TypeIndexing | Attributes __C types to their real module (__C.NSString → Foundation.NSString) through SDK module interfaces and APINotes. macOS only. |
Declarations and output