-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathiokernelrw.h
49 lines (41 loc) · 1.53 KB
/
iokernelrw.h
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
#ifndef LIBIOKERNELRW_H
#define LIBIOKERNELRW_H
#include <mach/mach.h>
#include <IOKit/IOKitLib.h>
static inline io_connect_t iokernelrw_open(void)
{
io_service_t service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("IOKernelRW"));
if(!MACH_PORT_VALID(service))
{
return MACH_PORT_NULL;
}
io_connect_t client = MACH_PORT_NULL;
kern_return_t ret = IOServiceOpen(service, mach_task_self(), 0, &client);
IOObjectRelease(service);
if(ret != KERN_SUCCESS)
{
return MACH_PORT_NULL;
}
return client;
}
static inline kern_return_t iokernelrw_read(io_connect_t client, uint64_t from, void *to, uint64_t len)
{
uint64_t in[] = { from, (uint64_t)to, len };
return IOConnectCallScalarMethod(client, 0, in, 3, NULL, NULL);
}
static inline kern_return_t iokernelrw_write(io_connect_t client, void *from, uint64_t to, uint64_t len)
{
uint64_t in[] = { (uint64_t)from, to, len };
return IOConnectCallScalarMethod(client, 1, in, 3, NULL, NULL);
}
static inline kern_return_t iokernelrw_read_phys(io_connect_t client, uint64_t from, void *to, uint64_t len, uint8_t align)
{
uint64_t in[] = { from, (uint64_t)to, len, align };
return IOConnectCallScalarMethod(client, 2, in, 4, NULL, NULL);
}
static inline kern_return_t iokernelrw_write_phys(io_connect_t client, void *from, uint64_t to, uint64_t len, uint8_t align)
{
uint64_t in[] = { (uint64_t)from, to, len, align };
return IOConnectCallScalarMethod(client, 3, in, 4, NULL, NULL);
}
#endif /* LIBIOKERNELRW_H */