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.
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.
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. ...