-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.m
More file actions
130 lines (92 loc) · 2.03 KB
/
main.m
File metadata and controls
130 lines (92 loc) · 2.03 KB
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
#include <stdint.h>
#include <string.h>
#include <mach/mach.h>
#include <mach/host_priv.h>
#include <mach/kern_return.h>
#include <mach/mach_host.h>
#include <mach/mach_types.h>
#include <mach/port.h>
#include <mach/vm_types.h>
#include <getopt.h>
#include "kernel_memory.h"
#include "slide.h"
#include "patchfinder.h"
#include "tasks.h"
#include "hsp4.h"
static mach_port_t tfp0;
static struct option options[] =
{
{"gadgets", required_argument, 0, 'g'},
{"hsp4", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
int main(int argc, char *argv[], char *envp[]) {
bool ok;
kern_return_t kr;
int c;
bool hsp4;
char *gadget_file = NULL;
opterr = 0;
do
{
int opt_index = 0;
c = getopt_long(argc, argv, "g:h", options, &opt_index);
if(c == -1)
break;
switch(c)
{
case 0:
if(options[opt_index].flag != 0)
break;
printf("option %s", options[opt_index].name);
if(optarg)
printf(" with argument %s", optarg);
printf("\n");
break;
case 'g':
gadget_file = optarg;
break;
case 'h':
hsp4 = true;
break;
}
} while(c != -1);
kr = task_for_pid(mach_task_self(), 0, &tfp0);
if(kr == KERN_SUCCESS)
{
printf("Got kernel task port!\n");
} else {
fprintf(stderr, "tfp0 failure!\n");
return -1;
}
kernel_task_port = tfp0;
ok = kernel_slide_init();
if(!ok)
{
fprintf(stderr, "%s failed!\n", "kernel_slide_init()");
return -1;
}
ok = patchfinder_init(gadget_file);
if(!ok)
{
fprintf(stderr, "%s failed\n", "patchfinder_init()");
return -1;
}
ok = kernel_tasks_init();
if(!ok)
{
fprintf(stderr, "%s failed!\n", "kernel_tasks_init()");
return -1;
}
mach_port_t fake_tfp0;
if(hsp4)
{
ok = perform_hsp4_patch(&fake_tfp0);
if(!ok)
{
fprintf(stderr, "%s failed!\n", "perform_hsp4_patch()");
return -1;
}
}
return 1;
}