-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbase.c
68 lines (52 loc) · 1.66 KB
/
base.c
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
#include <stdio.h>
#include <mach/mach_init.h>
#include <sys/sysctl.h>
#include <mach/mach_vm.h>
#include <unistd.h>
int main() {
mach_port_t process_to_write;
kern_return_t error;
int pid;
if(getuid() && geteuid()) {
printf("You need to be root to vm_write!\n");
} else{
printf("PID: ");
scanf("%d", &pid);
error = task_for_pid(mach_task_self(), pid, &process_to_write);
if ((error != KERN_SUCCESS) || !MACH_PORT_VALID(process_to_write)) {
printf("Error getting the process!\n");
}
mach_port_name_t task;
vm_map_offset_t vmoffset;
vm_map_size_t vmsize;
uint32_t nesting_depth = 0;
struct vm_region_submap_info_64 vbr;
mach_msg_type_number_t vbrcount = 16;
kern_return_t kr;
if ((kr = mach_vm_region_recurse(process_to_write, &vmoffset, &vmsize,
&nesting_depth,
(vm_region_recurse_info_t)&vbr,
&vbrcount)) != KERN_SUCCESS)
{
printf("Error");
}
printf("%p\n", (void *) (uintptr_t)vmoffset);
int sz;
int sz2;
vm_offset_t dataPointer = 0;
vm_offset_t dataPointer2 = 0;
void **bytes;
void **bytes2;
error = vm_read(process_to_write, (vm_address_t)(0x7FFE43081B40 + vmoffset), sizeof(vm_address_t), &dataPointer, &sz);
if (error == KERN_SUCCESS) {
bytes = (void *)dataPointer;
printf("%p\n", *bytes);
error = vm_read(process_to_write, (void *) (uintptr_t)(*bytes-0x14), sizeof(int), &dataPointer2, &sz2);
if (error == KERN_SUCCESS) {
bytes2 = (void *)dataPointer2;
printf("%d\n", *bytes2);
}
}
}
return 0;
}