有人知道如何使用NASM在OSX中获取当前工作目录吗?syscall getcwd在osx上不可用,dtruss pwd会返回大量的stat sys调用。然而,在手册中,我找不到stat的哪个结构变量返回当前的工作目录。谢谢。
发布于 2019-10-01 16:56:17
这是一个有点晚的答案,但尽管如此,这仍然可以通过使用2个syscall来实现。
open_nocancel 0x2000018e (或open 0x2000005)打开当前dirfcntl_nocancel 0x20000196 (或fcntl 0x2000005c)的文件描述符以读取实际路径示例:
#define F_GETPATH 50 ; from <sys/fcntl.h>
currentDirConstant:
db ".",0 ; needs segment read permission
outputPath:
resb 1000 ; needs segment write permission
mov rdi,currentDirConstant; input path 1st argument
xor esi, esi ; int flags 2nd argument, just use 0
xor edx, edx ; int mode 3rd argument, just use 0
mov eax, 0x2000018e ; open_nocancel syscall number
syscall
mov edi,eax ; file descriptor 1st argument of current dir from previous syscall
mov esi,F_GETPATH ; fcntl cmd 2nd argument
mov rdx, outputPath ; output buffer 3rd argument
mov eax, 0x20000196 ; fcntl_nocancel syscall number
syscallhttps://stackoverflow.com/questions/32715311
复制相似问题