[英]Problems with getcwd syscall on OSX
有沒有人知道如何使用 NASM 在 OSX 中獲取當前工作目錄? 系統調用 getcwd 在 osx 上不可用,並且 dtruss pwd 返回大量 stat 系統調用。 但是在手冊中我找不到 stat 的哪個結構變量返回當前工作目錄。 謝謝。
這個答案有點晚了,但仍然可以使用 2 個系統調用來實現。
open_nocancel
0x2000018e (or open
0x2000005) 打開當前目錄的文件描述符fcntl_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
syscall
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.