forked from fi01/backdoor_mmap_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backdoor_mmap.c
63 lines (47 loc) · 1.13 KB
/
backdoor_mmap.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
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include "backdoor_mmap.h"
#define MMAP_DEVICE "/dev/ptmx"
#define KERNEL_BASE_ADDRESS 0xc0008000
static int ptmx_mmap_fd = -1;
static void *ptmx_mmap_address;
void *
backdoor_convert_to_kernel_address(void *address)
{
return address - BACKDOOR_MMAP_ADDRESS + KERNEL_BASE_ADDRESS;
}
void *
backdoor_convert_to_mmaped_address(void *address)
{
return address - KERNEL_BASE_ADDRESS + BACKDOOR_MMAP_ADDRESS;
}
bool
backdoor_open_mmap(void)
{
if (ptmx_mmap_fd >= 0)
return false;
ptmx_mmap_fd = open(MMAP_DEVICE, O_RDWR);
if (ptmx_mmap_fd < 0) {
return false;
}
ptmx_mmap_address = mmap((void *)BACKDOOR_MMAP_ADDRESS, BACKDOOR_MMAP_SIZE,
PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, ptmx_mmap_fd, 0);
if (ptmx_mmap_address == MAP_FAILED) {
close(ptmx_mmap_fd);
ptmx_mmap_fd = -1;
return false;
}
return true;
}
bool
backdoor_close_mmap(void)
{
if (ptmx_mmap_fd < 0)
return false;
munmap(ptmx_mmap_address, BACKDOOR_MMAP_SIZE);
close(ptmx_mmap_fd);
ptmx_mmap_fd = -1;
return true;
}