Shared low-level extensions on top of MachOKit, used by both MachOSwiftSection and MachOObjCSection.
This code started life as the MachOKitExtensions target inside MachOSwiftSection. Because
MachOSwiftSection already depends on MachOObjCSection, MachOObjCSection could not depend back on
it without forming a package-level cycle — so the ObjC side had to go without the address
arithmetic, cache resolution and load-command helpers that the Swift side took for granted.
Extracting the target into its own package breaks that cycle: both packages now depend on
MachOKitExtensions, and neither depends on the other.
| Area | Highlights |
|---|---|
| Address arithmetic | address(forOffset:), addressString(forOffset:), resolveOffset(at:) |
| Pointer tagging | stripPointerTags(of:) and the architecture-specific vmaddrMask |
| Dyld shared cache | cache(for:), cacheAndFileOffset(for:), cacheAndFileOffset(fromStart:), machOFile(by:) |
| Bind / rebase | resolveRebase(fileOffset:), resolveBind(fileOffset:), isBind(fileOffset:) |
| Load commands | Typed accessors for __TEXT, __DATA, __DATA_CONST, __AUTH, __AUTH_CONST, build version |
| Protocols | MachORepresentableWithCache, LocatableLayoutWrapper, MachOTargetIdentifier |
.package(url: "https://github.com/MxIris-Reverse-Engineering/MachOKitExtensions", from: "0.1.0")import MachOKit
import MachOKitExtensions
let machOFile: MachOFile = // …
// Turn a file offset into the address it will have once loaded.
let address = machOFile.addressString(forOffset: 0x1000)macOS 10.15+, iOS 13+, watchOS 6+, tvOS 13+, visionOS 1+, and Linux.
Linux support matters here because MachOObjCSection supports Linux, and it would have regressed had this package pulled in Apple-only dependencies. The package therefore depends only on MachOKit and AssociatedObject — the latter routes through swift-object-association on non-Objective-C platforms.
MachOKitExtensions is released under the MIT License. See LICENSE.