-
Notifications
You must be signed in to change notification settings - Fork 73
/
offsets.m
354 lines (280 loc) · 11.6 KB
/
offsets.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <stdio.h>
#import <stdlib.h>
#import <string.h>
#import <sys/sysctl.h>
#import <sys/utsname.h>
#import "offsets.h"
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
int* offsets = NULL;
int kstruct_offsets_13_0[] = {
0xb, // KSTRUCT_OFFSET_TASK_LCK_MTX_TYPE,
0x10, // KSTRUCT_OFFSET_TASK_REF_COUNT,
0x14, // KSTRUCT_OFFSET_TASK_ACTIVE,
0x28, // KSTRUCT_OFFSET_TASK_VM_MAP,
0x30, // KSTRUCT_OFFSET_TASK_NEXT,
0x38, // KSTRUCT_OFFSET_TASK_PREV,
0x108, // KSTRUCT_OFFSET_TASK_ITK_SELF,
0x320, // KSTRUCT_OFFSET_TASK_ITK_SPACE,
#if __arm64e__
0x388, // KSTRUCT_OFFSET_TASK_BSD_INFO,
#else
0x380, // KSTRUCT_OFFSET_TASK_BSD_INFO,
#endif
0x0, // KSTRUCT_OFFSET_IPC_PORT_IO_BITS,
0x4, // KSTRUCT_OFFSET_IPC_PORT_IO_REFERENCES,
0x40, // KSTRUCT_OFFSET_IPC_PORT_IKMQ_BASE,
0x50, // KSTRUCT_OFFSET_IPC_PORT_MSG_COUNT,
0x60, // KSTRUCT_OFFSET_IPC_PORT_IP_RECEIVER,
0x68, // KSTRUCT_OFFSET_IPC_PORT_IP_KOBJECT,
0x88, // KSTRUCT_OFFSET_IPC_PORT_IP_PREMSG,
0x90, // KSTRUCT_OFFSET_IPC_PORT_IP_CONTEXT,
0xa0, // KSTRUCT_OFFSET_IPC_PORT_IP_SRIGHTS,
0x10, // KSTRUCT_OFFSET_PROC_TASK,
0x68, // KSTRUCT_OFFSET_PROC_PID,
0x108, // KSTRUCT_OFFSET_PROC_P_FD
0x0, // KSTRUCT_OFFSET_FILEDESC_FD_OFILES
0x10, // KSTRUCT_OFFSET_FILEPROC_F_FGLOB
0x38, // KSTRUCT_OFFSET_FILEGLOB_FG_DATA
0x10, // KSTRUCT_OFFSET_SOCKET_SO_PCB
0x10, // KSTRUCT_OFFSET_PIPE_BUFFER
0x14, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE_SIZE
0x20, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE
0x28, // KSTRUCT_OFFSET_IPC_SPACE_IS_TASK
0x7c, // KFREE_ADDR_OFFSET
0xdd0, // IOSURFACE_CREATE_OUTSIZE
};
int kstruct_offsets_12_0[] = {
0xb, // KSTRUCT_OFFSET_TASK_LCK_MTX_TYPE,
0x10, // KSTRUCT_OFFSET_TASK_REF_COUNT,
0x14, // KSTRUCT_OFFSET_TASK_ACTIVE,
0x20, // KSTRUCT_OFFSET_TASK_VM_MAP,
0x28, // KSTRUCT_OFFSET_TASK_NEXT,
0x30, // KSTRUCT_OFFSET_TASK_PREV,
0xd8, // KSTRUCT_OFFSET_TASK_ITK_SELF,
0x300, // KSTRUCT_OFFSET_TASK_ITK_SPACE,
#if __arm64e__
0x368, // KSTRUCT_OFFSET_TASK_BSD_INFO,
#else
0x358, // KSTRUCT_OFFSET_TASK_BSD_INFO,
#endif
0x0, // KSTRUCT_OFFSET_IPC_PORT_IO_BITS,
0x4, // KSTRUCT_OFFSET_IPC_PORT_IO_REFERENCES,
0x40, // KSTRUCT_OFFSET_IPC_PORT_IKMQ_BASE,
0x50, // KSTRUCT_OFFSET_IPC_PORT_MSG_COUNT,
0x60, // KSTRUCT_OFFSET_IPC_PORT_IP_RECEIVER,
0x68, // KSTRUCT_OFFSET_IPC_PORT_IP_KOBJECT,
0x88, // KSTRUCT_OFFSET_IPC_PORT_IP_PREMSG,
0x90, // KSTRUCT_OFFSET_IPC_PORT_IP_CONTEXT,
0xa0, // KSTRUCT_OFFSET_IPC_PORT_IP_SRIGHTS,
0x10, // KSTRUCT_OFFSET_PROC_TASK,
0x60, // KSTRUCT_OFFSET_PROC_PID,
0x100, // KSTRUCT_OFFSET_PROC_P_FD
0x0, // KSTRUCT_OFFSET_FILEDESC_FD_OFILES
0x10, // KSTRUCT_OFFSET_FILEPROC_F_FGLOB
0x38, // KSTRUCT_OFFSET_FILEGLOB_FG_DATA
0x10, // KSTRUCT_OFFSET_SOCKET_SO_PCB
0x10, // KSTRUCT_OFFSET_PIPE_BUFFER
0x14, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE_SIZE
0x20, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE
0x28, // KSTRUCT_OFFSET_IPC_SPACE_IS_TASK
0x7c, // KFREE_ADDR_OFFSET
0xdd0, // IOSURFACE_CREATE_OUTSIZE
};
int kernel_offsets_11_3[] = {
0xb, // KSTRUCT_OFFSET_TASK_LCK_MTX_TYPE
0x10, // KSTRUCT_OFFSET_TASK_REF_COUNT
0x14, // KSTRUCT_OFFSET_TASK_ACTIVE
0x20, // KSTRUCT_OFFSET_TASK_VM_MAP
0x28, // KSTRUCT_OFFSET_TASK_NEXT
0x30, // KSTRUCT_OFFSET_TASK_PREV
0x308, // KSTRUCT_OFFSET_TASK_ITK_SPACE
0x368, // KSTRUCT_OFFSET_TASK_BSD_INFO
0x3a8, // KSTRUCT_OFFSET_TASK_ALL_IMAGE_INFO_ADDR
0x3b0, // KSTRUCT_OFFSET_TASK_ALL_IMAGE_INFO_SIZE
0x3a0, // KSTRUCT_OFFSET_TASK_TFLAGS
0x0, // KSTRUCT_OFFSET_TASK_LOCK
0x0, // KSTRUCT_OFFSET_IPC_PORT_IO_BITS
0x4, // KSTRUCT_OFFSET_IPC_PORT_IO_REFERENCES
0x40, // KSTRUCT_OFFSET_IPC_PORT_IKMQ_BASE
0x50, // KSTRUCT_OFFSET_IPC_PORT_MSG_COUNT
0x60, // KSTRUCT_OFFSET_IPC_PORT_IP_RECEIVER
0x68, // KSTRUCT_OFFSET_IPC_PORT_IP_KOBJECT
0x88, // KSTRUCT_OFFSET_IPC_PORT_IP_PREMSG
0x90, // KSTRUCT_OFFSET_IPC_PORT_IP_CONTEXT
0xa0, // KSTRUCT_OFFSET_IPC_PORT_IP_SRIGHTS
0x10, // KSTRUCT_OFFSET_PROC_PID
0x108, // KSTRUCT_OFFSET_PROC_P_FD
0x18, // KSTRUCT_OFFSET_PROC_TASK
0x100, // KSTRUCT_OFFSET_PROC_UCRED
0x0, // KSTRUCT_OFFSET_PROC_P_LIST
0x2a8, // KSTRUCT_OFFSET_PROC_P_CSFLAGS
0x410, // KSTRUCT_OFFSET_PROC_P_MEMSTAT_STATE
0x58, // KSTRUCT_OFFSET_PROC_MLOCK
0xf0, // KSTRUCT_OFFSET_PROC_UCRED_MLOCK
0x40, // KSTRUCT_OFFSET_PROC_SVUID
0x44, // KSTRUCT_OFFSET_PROC_SVGID
0x0, // KSTRUCT_OFFSET_FILEDESC_FD_OFILES
0x8, // KSTRUCT_OFFSET_FILEPROC_F_FGLOB
0x38, // KSTRUCT_OFFSET_FILEGLOB_FG_DATA
0x10, // KSTRUCT_OFFSET_SOCKET_SO_PCB
0x10, // KSTRUCT_OFFSET_PIPE_BUFFER
0x14, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE_SIZE
0x20, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE
0xd8, // KSTRUCT_OFFSET_VNODE_V_MOUNT
0x78, // KSTRUCT_OFFSET_VNODE_VU_SPECINFO
0x0, // KSTRUCT_OFFSET_VNODE_V_LOCK
0xe0, // KSTRUCT_OFFSET_VNODE_V_DATA
0x10, // KSTRUCT_OFFSET_SPECINFO_SI_FLAGS
0x70, // KSTRUCT_OFFSET_MOUNT_MNT_FLAG
0x8f8, // KSTRUCT_OFFSET_MOUNT_MNT_DATA
0x18, // KSTRUCT_OFFSET_MOUNT_MNT_MLOCK
0x10, // KSTRUCT_OFFSET_HOST_SPECIAL
0x10, // KSTRUCT_OFFSET_UCRED_CR_REF
0x18, // KSTRUCT_OFFSET_UCRED_CR_UID
0x1c, // KSTRUCT_OFFSET_UCRED_CR_RUID
0x20, // KSTRUCT_OFFSET_UCRED_CR_SVUID
0x24, // KSTRUCT_OFFSET_UCRED_CR_NGROUPS
0x28, // KSTRUCT_OFFSET_UCRED_CR_GROUPS
0x68, // KSTRUCT_OFFSET_UCRED_CR_RGID
0x6c, // KSTRUCT_OFFSET_UCRED_CR_SVGID
0x70, // KSTRUCT_OFFSET_UCRED_CR_GMUID
0x74, // KSTRUCT_OFFSET_UCRED_CR_FLAGS
0x78, // KSTRUCT_OFFSET_UCRED_CR_LABEL
0x0, // KSTRUCT_OFFSET_LABEL_L_FLAGS
0x8, // KSTRUCT_OFFSET_LABEL_L_PERPOLICY
0x18, // KSTRUCT_SIZE_IPC_ENTRY
0x8, // KSTRUCT_OFFSET_IPC_ENTRY_IE_BITS
0x54, // KSTRUCT_OFFSET_VNODE_V_FLAG
0x1F, // KVTABLE_OFFSET_OSDICTIONARY_SETOBJECTWITHCHARP
0x26, // KVTABLE_OFFSET_OSDICTIONARY_GETOBJECTWITHCHARP
0x23, // KVTABLE_OFFSET_OSDICTIONARY_MERGE
0x1E, // KVTABLE_OFFSET_OSARRAY_MERGE
0x20, // KVTABLE_OFFSET_OSARRAY_REMOVEOBJECT
0x22, // KVTABLE_OFFSET_OSARRAY_GETOBJECT
0x05, // KVTABLE_OFFSET_OSOBJECT_RELEASE
0x03, // KVTABLE_OFFSET_OSOBJECT_GETRETAINCOUNT
0x04, // KVTABLE_OFFSET_OSOBJECT_RETAIN
0x11, // KVTABLE_OFFSET_OSSTRING_GETLENGTH
0x6c, // KFREE_ADDR_OFFSET
};
int kernel_offsets_11_0[] = {
0xb, // KSTRUCT_OFFSET_TASK_LCK_MTX_TYPE
0x10, // KSTRUCT_OFFSET_TASK_REF_COUNT
0x14, // KSTRUCT_OFFSET_TASK_ACTIVE
0x20, // KSTRUCT_OFFSET_TASK_VM_MAP
0x28, // KSTRUCT_OFFSET_TASK_NEXT
0x30, // KSTRUCT_OFFSET_TASK_PREV
0x308, // KSTRUCT_OFFSET_TASK_ITK_SPACE
0x368, // KSTRUCT_OFFSET_TASK_BSD_INFO
0x3a8, // KSTRUCT_OFFSET_TASK_ALL_IMAGE_INFO_ADDR
0x3b0, // KSTRUCT_OFFSET_TASK_ALL_IMAGE_INFO_SIZE
0x3a0, // KSTRUCT_OFFSET_TASK_TFLAGS
0x0, // KSTRUCT_OFFSET_TASK_LOCK
0x0, // KSTRUCT_OFFSET_IPC_PORT_IO_BITS
0x4, // KSTRUCT_OFFSET_IPC_PORT_IO_REFERENCES
0x40, // KSTRUCT_OFFSET_IPC_PORT_IKMQ_BASE
0x50, // KSTRUCT_OFFSET_IPC_PORT_MSG_COUNT
0x60, // KSTRUCT_OFFSET_IPC_PORT_IP_RECEIVER
0x68, // KSTRUCT_OFFSET_IPC_PORT_IP_KOBJECT
0x88, // KSTRUCT_OFFSET_IPC_PORT_IP_PREMSG
0x90, // KSTRUCT_OFFSET_IPC_PORT_IP_CONTEXT
0xa0, // KSTRUCT_OFFSET_IPC_PORT_IP_SRIGHTS
0x10, // KSTRUCT_OFFSET_PROC_PID
0x108, // KSTRUCT_OFFSET_PROC_P_FD
0x18, // KSTRUCT_OFFSET_PROC_TASK
0x100, // KSTRUCT_OFFSET_PROC_UCRED
0x0, // KSTRUCT_OFFSET_PROC_P_LIST
0x2a8, // KSTRUCT_OFFSET_PROC_P_CSFLAGS
0x410, // KSTRUCT_OFFSET_PROC_P_MEMSTAT_STATE
0x58, // KSTRUCT_OFFSET_PROC_MLOCK
0xf0, // KSTRUCT_OFFSET_PROC_UCRED_MLOCK
0x40, // KSTRUCT_OFFSET_PROC_SVUID
0x44, // KSTRUCT_OFFSET_PROC_SVGID
0x0, // KSTRUCT_OFFSET_FILEDESC_FD_OFILES
0x8, // KSTRUCT_OFFSET_FILEPROC_F_FGLOB
0x38, // KSTRUCT_OFFSET_FILEGLOB_FG_DATA
0x10, // KSTRUCT_OFFSET_SOCKET_SO_PCB
0x10, // KSTRUCT_OFFSET_PIPE_BUFFER
0x14, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE_SIZE
0x20, // KSTRUCT_OFFSET_IPC_SPACE_IS_TABLE
0xd8, // KSTRUCT_OFFSET_VNODE_V_MOUNT
0x78, // KSTRUCT_OFFSET_VNODE_VU_SPECINFO
0x0, // KSTRUCT_OFFSET_VNODE_V_LOCK
0xe0, // KSTRUCT_OFFSET_VNODE_V_DATA
0x10, // KSTRUCT_OFFSET_SPECINFO_SI_FLAGS
0x70, // KSTRUCT_OFFSET_MOUNT_MNT_FLAG
0x8f8, // KSTRUCT_OFFSET_MOUNT_MNT_DATA
0x18, // KSTRUCT_OFFSET_MOUNT_MNT_MLOCK
0x10, // KSTRUCT_OFFSET_HOST_SPECIAL
0x10, // KSTRUCT_OFFSET_UCRED_CR_REF
0x18, // KSTRUCT_OFFSET_UCRED_CR_UID
0x1c, // KSTRUCT_OFFSET_UCRED_CR_RUID
0x20, // KSTRUCT_OFFSET_UCRED_CR_SVUID
0x24, // KSTRUCT_OFFSET_UCRED_CR_NGROUPS
0x28, // KSTRUCT_OFFSET_UCRED_CR_GROUPS
0x68, // KSTRUCT_OFFSET_UCRED_CR_RGID
0x6c, // KSTRUCT_OFFSET_UCRED_CR_SVGID
0x70, // KSTRUCT_OFFSET_UCRED_CR_GMUID
0x74, // KSTRUCT_OFFSET_UCRED_CR_FLAGS
0x78, // KSTRUCT_OFFSET_UCRED_CR_LABEL
0x0, // KSTRUCT_OFFSET_LABEL_L_FLAGS
0x8, // KSTRUCT_OFFSET_LABEL_L_PERPOLICY
0x18, // KSTRUCT_SIZE_IPC_ENTRY
0x8, // KSTRUCT_OFFSET_IPC_ENTRY_IE_BITS
0x54, // KSTRUCT_OFFSET_VNODE_V_FLAG
0x1F, // KVTABLE_OFFSET_OSDICTIONARY_SETOBJECTWITHCHARP
0x26, // KVTABLE_OFFSET_OSDICTIONARY_GETOBJECTWITHCHARP
0x23, // KVTABLE_OFFSET_OSDICTIONARY_MERGE
0x1E, // KVTABLE_OFFSET_OSARRAY_MERGE
0x20, // KVTABLE_OFFSET_OSARRAY_REMOVEOBJECT
0x22, // KVTABLE_OFFSET_OSARRAY_GETOBJECT
0x05, // KVTABLE_OFFSET_OSOBJECT_RELEASE
0x03, // KVTABLE_OFFSET_OSOBJECT_GETRETAINCOUNT
0x04, // KVTABLE_OFFSET_OSOBJECT_RETAIN
0x11, // KVTABLE_OFFSET_OSSTRING_GETLENGTH
0x6c, // KFREE_ADDR_OFFSET
};
int koffset(enum kstruct_offset offset) {
if (offsets == NULL) {
printf("[-] Please call init_offsets() prior to querying offsets\n");
return 0;
}
return offsets[offset];
}
uint32_t create_outsize;
int init_offsets() {
if (SYSTEM_VERSION_GREATER_THAN(@"13.5")) {
printf("[-] iOS version too high, 13.4.x or lower required\n");
return 1;
}
else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0")) {
printf("[i] Offsets selected for iOS 13.0 or above\n");
offsets = kstruct_offsets_13_0;
return 0;
}
else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"12.0")) {
printf("[i] Offsets selected for iOS 12.0 or above\n");
offsets = kstruct_offsets_12_0;
return 0;
}
else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.3")) {
printf("[i] Offsets selected for iOS 11.3 or above\n");
offsets = kernel_offsets_11_3;
return 0;
}
else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.0")) {
printf("[i] Offsets selected for iOS 11.0 or above\n");
offsets = kernel_offsets_11_0;
return 0;
}
else {
printf("[-] iOS version too low, 11.0 or higher required\n");
return 2;
}
}