首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OSX上的getcwd syscall问题

OSX上的getcwd syscall问题
EN

Stack Overflow用户
提问于 2015-09-22 19:09:28
回答 1查看 516关注 0票数 2

有人知道如何使用NASM在OSX中获取当前工作目录吗?syscall getcwd在osx上不可用,dtruss pwd会返回大量的stat sys调用。然而,在手册中,我找不到stat的哪个结构变量返回当前的工作目录。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-10-01 16:56:17

这是一个有点晚的答案,但尽管如此,这仍然可以通过使用2个syscall来实现。

  1. open_nocancel 0x2000018e (或open 0x2000005)打开当前dir
  2. fcntl_nocancel 0x20000196 (或fcntl 0x2000005c)的文件描述符以读取实际路径

示例:

代码语言:javascript
复制
#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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32715311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档