forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 12
/
vdso-transplant-main.c
36 lines (32 loc) · 1 KB
/
vdso-transplant-main.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
// Run a process but replace the vdso with the one in the given file.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/personality.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <signal.h>
#include "debug.h"
#include "ptutil.h"
#include "transplant.h"
int main(int argc, char *const argv[]) {
char *const envp[] = {NULL};
int pid = start_tracee(AT_FDCWD, argv[2], argv + 2, envp);
int vdso_fd = trycall(open(argv[1], O_RDONLY), "open vdso");
struct stat statbuf;
trycall(fstat(vdso_fd, &statbuf), "stat vdso");
size_t vdso_size = statbuf.st_size;
void *vdso = mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, vdso_fd, 0);
if (vdso == MAP_FAILED) {
perror("mmap vdso"); exit(1);
}
transplant_vdso(pid, vdso, vdso_size);
trycall(kill(pid, SIGSTOP), "pause process");
printf("attach debugger to %d\n", pid);
return 0;
}