Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
- int main()
- {
- int i;
- for(i = 0; i < 10; i++)
- {
- printf("Hello Worldn");
- sleep(5);
- }
- return 0;
- }
- #include <sys/ptrace.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <sys/user.h> // For user_regs_struct
- int main(int argc, char *argv[])
- {
- pid_t traced_process;
- struct user_regs_struct regs;
- if(argc != 2)
- {
- printf("Usage: %s <pid to be traced>n", argv[0], argv[1]);
- exit(1);
- }
- traced_process = atoi(argv[1]);
- long t = 0;
- t = ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
- if(t < 0)
- printf("-1n");
- wait(NULL);
- ptrace(PTRACE_GETREGS, traced_process, NULL, ®s);
- long ins = ptrace(PTRACE_PEEKTEXT, traced_process, regs.eip, NULL);
- if(ins < 0)
- printf("-1n");
- printf("EIP: %lx Instruction executed: %lxn", regs.eip, ins);
- ptrace(PTRACE_DETACH, traced_process, NULL, NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement