Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <string.h>
- #include <sys/mman.h>
- #include <sys/ptrace.h>
- struct region
- {
- int count;
- char buf[10000];
- int id;
- };
- int main ( int argc, char *argv[] )
- {
- struct sigaction act;
- struct region *rptr;
- pid_t child;
- int fd;
- fd = shm_open("/myregion", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
- if (ftruncate(fd, 0) == -1) return -1;
- rptr = mmap(NULL, sizeof(struct region), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- if (rptr == MAP_FAILED) return -1;
- child = fork();
- if(child == 0)
- {
- ptrace(PTRACE_TRACEME, 0, NULL, NULL);
- fprintf(stderr, "rptr: %d\n", rptr->count);
- fprintf(stderr, "rptr: %d\n", rptr->count);
- fprintf(stderr, "rptr: %d %s\n", rptr->count, rptr->buf);
- fprintf(stderr, "rptr: %d %s\n", rptr->count, rptr->buf);
- fprintf(stderr, "rptr: %d\n", rptr->count);
- fprintf(stderr, "rptr: %d 0x%x\n", rptr->count, rptr->id);
- fprintf(stderr, "rptr: %d\n", rptr->count);
- }
- else
- {
- struct region mydata = { 0, "test tmp", 0xdeadbeef };
- int status = ~0;
- size_t i;
- while(!WIFEXITED(status))
- {
- if(!WIFSTOPPED(status) || WSTOPSIG(status) != SIGBUS)
- {
- ptrace(PTRACE_CONT, child, NULL, NULL);
- wait(&status);
- continue;
- }
- mydata.count++;
- lseek(fd, 0, SEEK_SET);
- write(fd, &mydata, sizeof(mydata));
- ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);
- wait(&status);
- if (ftruncate(fd, 0) == -1) return -1;
- ptrace(PTRACE_CONT, child, NULL, NULL);
- wait(&status);
- }
- }
- shm_unlink("/myregion");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement