Appending a File with int 0x80 (Access bits?)

2019-08-21 08:11发布

In my NASM textbook, "Guide to Assembly Programming in Linux" by Dandamundi, system call 5 (opening a file) is described with the following parameters.

EAX = 5
EBX = file name
ECX = file access mode (read, write, read/write)
EDX = file permissions

It does not clarify what the access codes (octal, I'm assuming) actually are. 0200Q and 02000Q assumedly do not work. I am trying to append the contents of one file onto another file.

标签: assembly nasm
2条回答
来,给爷笑一个
2楼-- · 2019-08-21 08:25

I think this is the sys_open syscall, so the parameters should map one-to-one to those of open(2):

The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read-only, write-only, or read/write, respectively. In addition, zero or more file creation flags and file status flags can be bitwise-or'd in flags. The file creation flags are O_CREAT, O_EXCL, O_NOCTTY, and O_TRUNC. ...

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-21 08:40

After looking at /usr/include/asm/unistd_32.h, it's clear that system call number 5 resolves to open. In turn, looking at man 2 open says that the second parameter must include O_RDONLY (00), O_WRONLY (01) or O_RDWR (02). It may also include a number of extra flags by ORing them together, which are documented on the said manual page.

In your case, you probably want to be able to write to a file and append to it. Therefore, O_WRONLY | O_APPEND would be desirable. After looking at the header files, that operation yields the value 02001 and this is what you should put in the ecx register.

查看更多
登录 后发表回答