本文介绍了OSX上的getcwd syscall问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何使用NASM在OSX中获取当前的工作目录吗? osx上无法使用syscall getcwd,而dtruss pwd返回大量的stat sys调用.但是在手册中,我找不到stat的哪个结构变量返回当前工作目录.谢谢.
Does anyone have an idea how to get the current working directory in OSX with NASM? The syscall getcwd isn't available on osx and dtruss pwd return lots of stat sys calls. However in the manual I can't find which structure variable of stat returns the current working directory.Thanks.
推荐答案
这是有点的答案,但是仍然可以使用2个syscall来实现.
That's a bit late answer, but nonetheless this can be achieved using 2 syscalls.
-
open_nocancel
0x2000018e(或open
0x2000005)打开当前目录的文件描述符 -
fcntl_nocancel
0x20000196(或fcntl
0x2000005c)以读取实际路径
open_nocancel
0x2000018e (oropen
0x2000005) opening a file descriptor for current dirfcntl_nocancel
0x20000196 (orfcntl
0x2000005c) for reading the actual path
示例:
#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
syscall
这篇关于OSX上的getcwd syscall问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!