Advertisement
Guest User

Untitled

a guest
Jan 14th, 2014
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
  2.  
  3. int main()
  4. {
  5. int i;
  6. for(i = 0; i < 10; i++)
  7. {
  8. printf("Hello Worldn");
  9. sleep(5);
  10. }
  11.  
  12. return 0;
  13. }
  14.  
  15. #include <sys/ptrace.h>
  16. #include <sys/types.h>
  17. #include <sys/wait.h>
  18. #include <unistd.h>
  19. #include <sys/user.h> // For user_regs_struct
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23. pid_t traced_process;
  24. struct user_regs_struct regs;
  25.  
  26. if(argc != 2)
  27. {
  28. printf("Usage: %s <pid to be traced>n", argv[0], argv[1]);
  29. exit(1);
  30. }
  31.  
  32. traced_process = atoi(argv[1]);
  33.  
  34. long t = 0;
  35. t = ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
  36.  
  37. if(t < 0)
  38. printf("-1n");
  39.  
  40. wait(NULL);
  41.  
  42. ptrace(PTRACE_GETREGS, traced_process, NULL, &regs);
  43. long ins = ptrace(PTRACE_PEEKTEXT, traced_process, regs.eip, NULL);
  44.  
  45. if(ins < 0)
  46. printf("-1n");
  47.  
  48. printf("EIP: %lx Instruction executed: %lxn", regs.eip, ins);
  49.  
  50. ptrace(PTRACE_DETACH, traced_process, NULL, NULL);
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement