2016-03-06 78 views
1

我用這個回答了https://stackoverflow.com/a/12016223/2536878如何在ARM上用ptrace阻止系統調用?

而且正在使用x86。

我已經嘗試ARM電話上的此代碼,並不工作(系統調用錯誤)。

我猜ORIG_EAX對ARM來說是無效的,所以用什麼值代替ORIG_EAX?

現在我有這樣的代碼(在x86作品):

#include <signal.h> 
#include <syscall.h> 
#include <sys/ptrace.h> 
#include <sys/types.h> 
#include <sys/wait.h> 
#include <unistd.h> 
#include <errno.h> 
#include <sys/user.h> 
#include <sys/reg.h> 
#include <sys/syscall.h> 
#include <stdio.h> 
#include <string.h> 

int main(int argc, char **argv) 
{ 
     int i; 
     pid_t child; 
     int status; 
     long orig_eax; 
     int kill_ret = 0; 
    char c[100]; 

     child = fork(); 

     if(child == 0) 
     { 
     ptrace(PTRACE_TRACEME, 0, NULL, NULL); 
     execvp(argv[1], argv + 1); 
     } 
     else 
     { 
       i = 0; 
       while(1) 
       { 
         wait(&status); 
         if (WIFEXITED(status) || WIFSIGNALED(status)) 
           break; 

         orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * ORIG_EAX, NULL); 
         if (orig_eax == 2) 
         { 
           fprintf(stderr, "Got it\n"); 
           kill_ret = kill(child, SIGKILL); 
           if (kill_ret == -1) 
           { 
            fprintf(stderr, "Failed to kill ---> %s\n", strerror(errno)); 
           } 
         } 
         printf("%d time, system call %ld\n", i++, orig_eax); 
         syscall_prompt: 
      printf("Allow syscall? Y/N: "); 
      fflush(stdout); 
      read(0, c, 100); 
      if(c[0] != 'Y' && c[0] != 'N') {printf("\n"); goto syscall_prompt;} 
      if(c[0] == 'N') { kill_ret = kill(child, SIGKILL); if(kill_ret < 0) { fprintf(stderr, "Cannot kill child\n"); } exit(1); } 
      ptrace(PTRACE_SYSCALL, child, NULL, NULL); 
       } 
     } 
    printf("return\n"); 
     return 0; 
} 

回答