-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from p-x9/feature/enhance-prebuilt-loader
Enhance prebuilt loader
- Loading branch information
Showing
6 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Sources/MachOKit/Model/DyldCache/Loader/ObjCBinaryInfo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// ObjCBinaryInfo.swift | ||
// MachOKit | ||
// | ||
// Created by p-x9 on 2024/11/16 | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
public struct ObjCBinaryInfo: LayoutWrapper { | ||
public typealias Layout = objc_binary_info | ||
|
||
public var layout: Layout | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
Sources/MachOKit/Model/DyldCache/Loader/SectionLocations.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// SectionLocations.swift | ||
// MachOKit | ||
// | ||
// Created by p-x9 on 2024/11/16 | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
public struct SectionLocations: LayoutWrapper { | ||
public typealias Layout = section_locations | ||
|
||
public var layout: Layout | ||
} | ||
|
||
extension SectionLocations { | ||
// [dyld implementation](https://github.com/apple-oss-distributions/dyld/blob/65bbeed63cec73f313b1d636e63f243964725a9d/include/mach-o/dyld_priv.h#L62) | ||
public enum SectionKind: Int, CaseIterable { | ||
// TEXT: | ||
case text_swift5_protos | ||
case text_swift5_proto | ||
case text_swift5_types | ||
case text_swift5_replace | ||
case text_swift5_replace2 | ||
case text_swift5_ac_funcs | ||
|
||
// DATA*: | ||
case objc_image_info | ||
case data_sel_refs | ||
case data_msg_refs | ||
case data_class_refs | ||
case data_super_refs | ||
case data_protocol_refs | ||
case data_class_list | ||
case data_non_lazy_class_list | ||
case data_stub_list | ||
case data_category_list | ||
case data_category_list2 | ||
case data_non_lazy_category_list | ||
case data_protocol_list | ||
case data_objc_fork_ok | ||
case data_raw_isa | ||
|
||
// ~~ version 1 ~~ | ||
} | ||
} | ||
|
||
extension SectionLocations { | ||
public struct Section { | ||
public let offset: Int | ||
public let size: Int | ||
public let kind: SectionKind | ||
} | ||
} | ||
|
||
extension SectionLocations { | ||
public func section(for kind: SectionKind) -> Section { | ||
var offsets = layout.offsets | ||
var sizes = layout.sizes | ||
let offset = withUnsafePointer(to: &offsets) { | ||
UnsafeRawPointer($0) | ||
.assumingMemoryBound(to: UInt64.self) | ||
.advanced(by: kind.rawValue).pointee | ||
} | ||
let size = withUnsafePointer(to: &sizes) { | ||
UnsafeRawPointer($0) | ||
.assumingMemoryBound(to: UInt64.self) | ||
.advanced(by: kind.rawValue).pointee | ||
} | ||
return .init( | ||
offset: numericCast(offset), | ||
size: numericCast(size), | ||
kind: kind | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters