【问题标题】:Deleting/Unlinking a file in nasm assembly on mac 64 bit在mac 64位上的nasm程序集中删除/取消链接文件
【发布时间】:2021-11-29 15:34:58
【问题描述】:

我正在尝试删除或取消链接文件。取消链接意味着删除,我认为(从我所读到的)。

我读过documentation 和另一个documentation。他们都说取消链接需要1个参数。 const char * pathname.

我已经这样做了,但是我要删除的文件没有被删除。有谁知道为什么?这是我的代码:

global start

section .text
    start:
        ;This is the deleting/unlinking part
        mov rax, 0x2000010; unlinking
        mov rdi, file ; contains path and the file. If you look down more in section .data you can see the file and path      
        syscall
       
        ;This part is not important: Its just exiting
        mov rax, 0x2000001       ;Exiting
        xor rdi, rdi         
        syscall          

section .data
    file: db "/Users/daniel.yoffe/desktop/assembly/CoolFile.txt", 0

我还查看了 linux 中的一个示例。就是这样。有什么我做错了吗?取消链接甚至会删除文件吗?我是否遗漏了什么可能是另一个论点?

我们将不胜感激。

【问题讨论】:

  • 是的,取消链接会删除文件。检查你得到什么错误代码。使用您的系统调用跟踪器。
  • @Jester 没有错误。
  • 您能否在问题中包含 dtruss 输出?
  • @Yoffdan 你怎么知道?你甚至都不检查是否有一个。

标签: macos assembly x86-64 nasm system-calls


【解决方案1】:

您使用了错误的十进制和十六进制混合。对于您想要的系统调用10

;This is the deleting/unlinking part
        mov rax, 0x200000a; unlinking
        mov rdi, file ; contains path and the file. If you look down more in section .data you can see the file and path      
        syscall

附带说明ret 而不是您的第二个系统退出系统调用应该足以满足现代 Mach-o MacOS 可执行文件。

【讨论】:

  • 太棒了!这样可行!你能帮我一个忙并解释为什么它是 0x200000a 而不是 0x2000010 吗?我一直在使用系统调用,例如 0x2000001、0x2000003、0x2000004 等,为什么最后会有一个 a?
  • 选择任何十进制 十六进制计算器以熟悉十进制和十六进制之间的双向转换以及数字在每个数字系统中的表示方式。十进制 10 是十六进制的 0xa,十进制 11 是十六进制的 0xb 等等
  • 谢谢!这清除了很多事情
猜你喜欢
  • 2017-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-23
  • 2014-01-02
  • 2023-01-11
  • 1970-01-01
  • 2012-03-07
相关资源
最近更新 更多