如何在Linux程序集中创建文件

时间:2022-11-27 02:50:05

I have the following code:

我有以下代码:

section .text
    global _start       ;must be declared for using gcc
_start:                     ;tell linker entry point
    mov ecx, 2      ;read-write perms
    mov ebx, name       ;name of file
    mov eax, 8      ;system call number (sys_creat)
    int 0x80        ;call kernel
    mov eax, 1      ;system call number (sys_exit)
    int 0x80        ;call kernel

section .data
name    db  'C:\\test.txt',0xa  

It is meant to create a file (test.txt) in the C drive however doesn't work, what is the correct way to do this?

它意味着在C驱动器中创建一个文件(test.txt)但是不起作用,这样做的正确方法是什么?

1 个解决方案

#1


First, syscall=8 is sys_creat, not write.

首先,syscall = 8是sys_creat,而不是write。

But the easiest way to find out what is happening is looking at the strace output of the program. There you can see if the syscall succeeded, and if not, what is the error value. (errno)

但是找出正在发生的事情的最简单方法是查看程序的strace输出。在那里你可以看到系统调用是否成功,如果没有,那么错误值是多少。 (错误)

Afaik creat(2) is not used anymore, and Open(2) with O_CREAT in the second argument is used nowadays.

Afaik creat(2)不再使用,现在使用第二个参数中带有O_CREAT的Open(2)。

#1


First, syscall=8 is sys_creat, not write.

首先,syscall = 8是sys_creat,而不是write。

But the easiest way to find out what is happening is looking at the strace output of the program. There you can see if the syscall succeeded, and if not, what is the error value. (errno)

但是找出正在发生的事情的最简单方法是查看程序的strace输出。在那里你可以看到系统调用是否成功,如果没有,那么错误值是多少。 (错误)

Afaik creat(2) is not used anymore, and Open(2) with O_CREAT in the second argument is used nowadays.

Afaik creat(2)不再使用,现在使用第二个参数中带有O_CREAT的Open(2)。