File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 6
6
//
7
7
//
8
8
9
+ import CoreFoundation // for CFByteOrderGetCurrent (Linux)
9
10
import Foundation
10
11
#if compiler(>=6.0) || (compiler(>=5.10) && hasFeature(AccessLevelOnImport))
11
12
internal import FileIO
@@ -118,6 +119,15 @@ public class MachOFile: MachORepresentable {
118
119
}
119
120
}
120
121
122
+ extension MachOFile {
123
+ public var endian : Endian {
124
+ let hostIsLittleEndian = CFByteOrderGetCurrent ( ) == CFByteOrderLittleEndian . rawValue
125
+ return hostIsLittleEndian
126
+ ? ( isSwapped ? . big : . little)
127
+ : ( isSwapped ? . little : . big)
128
+ }
129
+ }
130
+
121
131
extension MachOFile {
122
132
public var rpaths : [ String ] {
123
133
loadCommands
Original file line number Diff line number Diff line change 6
6
//
7
7
//
8
8
9
+ import CoreFoundation // for CFByteOrderGetCurrent (Linux)
9
10
import Foundation
10
11
11
12
/// Structure for `MachO` representation loaded from memory.
@@ -145,6 +146,19 @@ extension MachOImage {
145
146
}
146
147
}
147
148
149
+ extension MachOImage {
150
+ public var endian : Endian {
151
+ switch CFByteOrderGetCurrent ( ) {
152
+ case numericCast ( CFByteOrderLittleEndian . rawValue) :
153
+ return . little
154
+ case numericCast ( CFByteOrderBigEndian . rawValue) :
155
+ return . big
156
+ default :
157
+ fatalError ( " Unexpected byte order value: \( CFByteOrderGetCurrent ( ) ) " )
158
+ }
159
+ }
160
+ }
161
+
148
162
extension MachOImage {
149
163
public var dependencies : [ DependedDylib ] {
150
164
var dependencies = [ DependedDylib] ( )
Original file line number Diff line number Diff line change
1
+ //
2
+ // Endian.swift
3
+ // MachOKit
4
+ //
5
+ // Created by p-x9 on 2025/07/09
6
+ //
7
+ //
8
+
9
+ public enum Endian {
10
+ case little
11
+ case big
12
+ }
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ public protocol MachORepresentable {
39
39
/// Sequence of load commands
40
40
var loadCommands : LoadCommands { get }
41
41
42
+ /// Byte Order of this binary
43
+ var endian : Endian { get }
44
+
42
45
/// List of runpaths
43
46
var rpaths : [ String ] { get }
44
47
/// List of depended dynamic libraries
You can’t perform that action at this time.
0 commit comments