int main(int argc, char **argv){ printf("The filename is %s\n",filename); parse_system_call_name(filename); int pid; int i = 1; i+=2; pid = atoi(argv[1]); //printf("Hello, world (i=%d)!\n", pid); jint stat=0; jint res=0; long syscall; printf("Attaching to a process %d",pid); if ((ptrace(PTRACE_ATTACH, pid, NULL, NULL)) != 0) { printf("Could not attach to process, errno is %d",errno); } res = waitpid(pid, &stat, WUNTRACED); __android_log_print(ANDROID_LOG_INFO,LOG_TAG,"Status of the traced process %d\n",stat); ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACESYSGOOD); while(1){ if(trace_syscall(pid)!=0) break; #ifdef __arm__ print_syscall_arm(pid); #else print_syscall(pid); if(trace_syscall(pid)!=0) break; get_return_value(pid); #endif } cleanup_syscall_tabel(); return 0; }
int main (int argc, char *argv[]) { pid_t pid; int status = 1; struct tracer *tracer = NULL; struct process *process = NULL; if (argc < 2) return 1; pid = fork (); if (pid < 0) { perror ("fork"); return 2; } if (pid == 0) fork_and_trace_child (argv); if (wait_for_stopped (pid, false, &status)) { fprintf (stderr, "child process unexpectedly dead\n"); return 3; } /* When delivering syscall traps, set bit 7 in the signal number (i.e., deliver SIGTRAP | 0x80). This makes it easy for the tracer to tell the difference between normal traps and those caused by a syscall. (PTRACE_O_TRACESYSGOOD may not work on all architectures.) */ if (ptrace (PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACESYSGOOD) == -1) return 5; status = 1; if (!(tracer = tracer_alloc ())) { fprintf (stderr, "Can not allocate tracer\n"); goto end; } if (!(process = process_alloc (pid))) { fprintf (stderr, "Can not allocate process\n"); goto end; } if (tracer_add_process (tracer, process) == -1) { fprintf (stderr, "Cannot add process to tracer\n"); goto end; } /* process = NULL should be here (!) */ for (;;) { struct user_regs_struct state1; struct user_regs_struct state2; if (wait_for_break (pid, &state1, &status)) break; if (wait_for_break (pid, &state2, &status)) break; trace_syscall (process, &state1, &state2); } process = NULL; status &= 0xff; end: if (process) process_destroy (process); if (tracer) tracer_destroy (tracer); return status; }