Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 1.95 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ptrace_detach, SIGINT and trace/breakpoint trap (core dumped)
  2. void sig_int()
  3. {
  4.     if (ptrace(PTRACE_DETACH, pid, NULL, NULL) == -1)
  5.         my_perror("ptrace / DETACH", strerror(errno));
  6. }
  7.        
  8. if ((ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) == -1))                                                                                                
  9.    my_perror("ptrace / SINGLESTEP", strerror(errno));
  10. if (wait4(pid, &(l->status), 0, 0) == -1)
  11.    my_perror("wait4", strerror(errno));
  12. if (ptrace(PTRACE_GETREGS, pid, 0, &(l->reg)) == -1)
  13.    my_perror("ptrace / GETREGS", strerror(errno));
  14. if ((l->opcode = ptrace(PTRACE_PEEKTEXT, pid, l->reg.rip, NULL)) == -1)
  15.    my_perror("ptrace / PEEKTEXT", strerror(errno));
  16.        
  17. void            int_sig()
  18.  {
  19.   if (stop == 0)
  20.     {
  21.       printf("Interrupting!n");
  22.       ptrace(PTRACE_CONT, pid, NULL, NULL);
  23.       exit(0);
  24.     }
  25.  }
  26.        
  27. void            do_step(t_list *l)                                                                                                                        
  28. {
  29.   if ((ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) == -1))
  30.    my_perror("ptrace / SINGLESTEP", strerror(errno));
  31.   if (wait4(pid, &(l->status), 0, 0) == -1)
  32.     my_perror("wait4", strerror(errno));
  33.  if (ptrace(PTRACE_GETREGS, pid, 0, &(l->reg)) == -1)
  34.   my_perror("ptrace / GETREGS", strerror(errno));
  35.  if ((l->opcode = ptrace(PTRACE_PEEKTEXT, pid, l->reg.rip, NULL)) == -1)
  36.    my_perror("ptrace / PEEKTEXT", strerror(errno));
  37. }
  38.  
  39. void            do_next_step(t_list *l, t_strace *t)
  40.  {
  41.   stop = 1;
  42.   if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) == -1 ||
  43.       (wait4(pid, &(l->status), 0, 0) == -1))
  44.      my_perror("ERROR", strerror(errno));
  45.   if (!WIFSTOPPED(l->status) || WIFEXITED(l->status))
  46.      {
  47.        printf("?n");
  48.       exit(0);
  49.     }
  50.  if (ptrace(PTRACE_GETREGS, pid, 0, &(l->reg)) == -1)
  51.    my_perror("ptrace / GETREGS", strerror(errno));
  52.  if (t->ret == 1)
  53.   printf("%dn", (int)l->reg.rax);
  54.    else
  55.     printf("%#lxn", l->reg.rax);
  56.    stop = 0;
  57.  }