如何使用系统调用来读取Mac OS X下程序集中目录的内容?我尝试使用以下内容打开目录:
;; Open the current working directory for reading
;;
push dword 0 ; O_RDONLY (Mode = 0) as directory already exists
push dword 0 ; flags
push dword testdir ; Defined in .data as: testdir db "test", 0
mov eax, 0x05 ; Open system call
sub esp, 4 ; OS X (and BSD) system calls need extra space on stack
int 0x80
jc exit_error_after_call_16
add esp, byte 16 ; 3 args * 4 bytes/arg + 4 bytes extra space = 16 bytes
然后我尝试访问读取文件内容的目录的内容(所有目录也是文件?)到缓冲区。
push dword MAXFNAMELEN ; input length
push dword tempFName ; buffer
push dword eax ; file descriptor value
mov eax, 0x03 ; Execute read system call
sub esp, 4
int 0x80
add esp, byte 16
; Check if file could be read without error or EOF
jc exit_error ; CF set = error --> exit
test eax, eax
jz exit_noerror ; If EAX is 0 then EOF reached (stack breakdown at exit)
然后我尝试打印缓冲区进行调试,但没有得到内容:
push dword eax ; The length of the buffer to print
push dword tempFName ; The buffer to print
push dword 1 ; File descriptor value
mov eax, 0x04
sub esp, 4
int 0x80
add esp, byte 16
有什么想法吗?此外,在旧的DOS时代,有两个DOS函数FindFirst(0x4E)和FindNext。系统调用中是否有相应的内容?
感谢您的帮助。