我正在尝试使用 ptrace 从 sys_open 系统调用中获取文件名。我获得了文件路径指针,并且能够从该地址获得正确的数据,但是,我需要一种方法来知道要获得多少数据,即文件名的长度。我认为这个值应该在 edx 中,但这里似乎并非如此。有什么想法吗?
orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * ORIG_EAX, NULL);
if(orig_eax == __NR_open){
ptrace(PTRACE_GETREGS, child, NULL, ®s);
if(regs.eax > 0){
filepath = (char *)calloc((regs.edx+1), sizeof(char));
getdata(child, regs.ebx, filepath, regs.edx);
printf("Open eax %ld ebx %ld ecx %ld filepath %s\n",regs.eax, regs.ebx, regs.ecx, filepath);
free(filepath);
}
}
样本输出:
Open eax 3 ebx 2953895 edx 438 filepath /etc/localtime
Open eax 3 ebx 143028320 edx 384 filepath /var/log/vsftpd.log
Open eax 4 ebx 2957879 edx 438 filepath /etc/nsswitch.conf
Segmentation Fault
只是edx:
edx 438
edx 384
edx 438
//seg fault here
edx -1217013808
edx 0
edx 143035796
edx 0
edx 0