-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwrapper.c
61 lines (49 loc) · 1.1 KB
/
wrapper.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
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
int loadbin(char *prog, void *binstart)
{
unsigned int *pa;
size_t binsize;
int filedes;
struct stat statbuf;
if ((filedes = open(prog, O_RDONLY)) == -1)
{
perror("open error :");
return 1;
}
if (fstat (filedes,&statbuf) < 0)
{
perror("fstat error");
return 1;
}
binsize = statbuf.st_size;
if ((pa = mmap(binstart, binsize, PROT_READ|PROT_EXEC, MAP_SHARED | MAP_FIXED, filedes, 0)) == MAP_FAILED)
{
printf("errno:0x%x\n", errno);
perror("mmap error :");
return 1;
}
return 0;
}
int main(int argc, char *argv[])
{
void *binstart;
void (*binoep)();
binstart = (void*)0x10000;
binoep = (void(*))0x10020;
if (argc != 2)
{
printf("Usage %%prog <name>\n");
return 0;
}
printf("Loading %s\n", argv[1]);
loadbin(argv[1], binstart);
printf("Execution resumed at oep\n");
(binoep)();
return 0;
}