1 2 3 | #include <sys/ptrace.h> long int ptrace(enum __ptrace_request request, pid_t pid, \ void * addr, void * data); |
1 2 3 4 5 6 7 8 | #include <stdio.h> #include <stdlib.h> #include <sys/ptrace.h> #include <sys/wait.h> #include <linux/user.h> #include <sys/socket.h> #include <sys/un.h> #include <linux/net.h> |
1 2 3 4 5 6 | int main (int argc, char *argv[]) { int status; int syscall_entry = 0; int traced_process; struct user_regs_struct u_in; |
1 2 3 4 | traced_process = atoi(argv[1]); /* 从命令行得到监视进程的PID */ ptrace(PTRACE_ATTACH, traced_process, NULL, NULL); wait(&status); /* 等待被监视进程状态变化 */ ptrace(PTRACE_SYSCALL, traced_process, NULL, NULL); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | While (1) { /* 等待被监视程序调用系统调用或是发生其它状态变化 */ wait(&status); /* 如果被监视进程退出,函数返回真。程序退出 */ if ( WIFEXITED(status) ) break; ptrace(PTRACE_GETREGS, traced_process, 0, &u_in); if (u_in.orig_eax == 102 && u_in.ebx == SYS_SENDTO) { if (syscall_entry == 0) { /* syscall entry */ insyscall = 1; printf("call sendto()\n"); } else { /* Syscall exit */ Syscall_entry = 0; } } ptrace(PTRACE_SYSCALL, traced_process, NULL, NULL); } /* while */ return 0; } /* main */ |
1 2 3 4 | .long sys_fstatfs /* 100 */ .long sys_ioperm .long sys_socketcall .long sys_syslog |
1 | if (u_in.orig_eax == 102 && u_in.ebx == SYS_SENDTO) |
1 2 3 4 | #include <sys/types.h> #include <sys/socket.h> size_t sendto(int s, const void *msg, size_t len, int flags, \ const struct sockaddr *to, socket len_t tolen); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |