File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
Sources/MachOKit/LoadCommand Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -45,13 +45,17 @@ extension ThreadCommand {
45
45
return count
46
46
}
47
47
48
- public func state ( cmdsStart: UnsafeRawPointer ) -> Data ? {
48
+ public func stateData ( cmdsStart: UnsafeRawPointer ) -> Data ? {
49
49
guard let count = count ( cmdsStart: cmdsStart) else {
50
50
return nil
51
51
}
52
+
52
53
let stateSizeExpected = Int ( count) * MemoryLayout< UInt32> . size
53
54
let stateSize = Int ( layout. cmdsize) - layoutSize - 2 * MemoryLayout< UInt32> . size
54
- guard stateSizeExpected == stateSize else { return nil }
55
+
56
+ // consider alignment
57
+ guard stateSizeExpected <= stateSize else { return nil }
58
+
55
59
let ptr = cmdsStart
56
60
. advanced ( by: offset)
57
61
. advanced ( by: layoutSize)
@@ -89,13 +93,17 @@ extension ThreadCommand {
89
93
return count
90
94
}
91
95
92
- public func state ( in machO: MachOFile ) -> Data ? {
96
+ public func stateData ( in machO: MachOFile ) -> Data ? {
93
97
guard let count = count ( in: machO) else {
94
98
return nil
95
99
}
100
+
96
101
let stateSizeExpected = Int ( count) * MemoryLayout< UInt32> . size
97
102
let stateSize = Int ( layout. cmdsize) - layoutSize - 2 * MemoryLayout< UInt32> . size
98
- guard stateSizeExpected == stateSize else { return nil }
103
+
104
+ // consider alignment
105
+ guard stateSizeExpected <= stateSize else { return nil }
106
+
99
107
let offset = machO. cmdsStartOffset + offset + layoutSize + 2 * MemoryLayout< UInt32> . size
100
108
101
109
return machO. fileHandle. readData (
Original file line number Diff line number Diff line change @@ -473,7 +473,7 @@ extension MachOFilePrintTests {
473
473
) ? . description ?? " unknown "
474
474
)
475
475
print ( " Count: " , command. count ( in: machO) ?? 0 )
476
- if let state = command. state ( in: machO) {
476
+ if let state = command. stateData ( in: machO) {
477
477
print (
478
478
" State: " ,
479
479
state. withUnsafeBytes {
Original file line number Diff line number Diff line change @@ -400,7 +400,7 @@ extension MachOPrintTests {
400
400
) ? . description ?? " unknown "
401
401
)
402
402
print ( " Count: " , command. count ( cmdsStart: machO. cmdsStartPtr) ?? 0 )
403
- if let state = command. state ( cmdsStart: machO. cmdsStartPtr) {
403
+ if let state = command. stateData ( cmdsStart: machO. cmdsStartPtr) {
404
404
print (
405
405
" State: " ,
406
406
state. withUnsafeBytes {
You can’t perform that action at this time.
0 commit comments