簡體   English   中英

sys_open的ptrace%edx不一致

[英]ptrace %edx for sys_open inconsistent

我正在嘗試使用ptrace從sys_open系統調用中獲取文件名。 我得到了文件路徑指針,並且能夠從該地址獲取正確的數據,但是,我需要一種方法來知道要獲取多少數據,即文件名的長度。 我以為這個值應該在edx中,但是在這里似乎並非如此。 有什么想法嗎?

        orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * ORIG_EAX, NULL);
        if(orig_eax == __NR_open){
            ptrace(PTRACE_GETREGS, child, NULL, &regs);
            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

我一直喜歡在Linux系統調用表中檢查這種情況,然后在此頁面中查看更多詳細信息。

事實是,對於sys_open%edx不存儲文件名的長度。 它存儲文件權限

知道文件名長度的唯一方法是檢索文件名並將其傳遞給strlen()之后 ,它將返回字符串的大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM