I am trying to read the contents of a file using x86 assembly on Linux. The question is, what we should put into edx
– the “permissions” register for sys_open.
I’ve used open()
of C before; but there wasn’t any “permissions” field. I am trying to read a file belongs to the same owner of the executable. The file’s permissions are set to 0400
(-r--------
). I’ve tried opening the file with edx
: empty (0), 0666
and 0400
. All of them returns “-13” to eax
which seems to be EACCES
.
Sample code:
mov eax, 0x5; //sys_open push 0x6362612f //file name in hex, let's say "/abc" mov ebx, esp; //filename to ebx xor ecx, ecx; //O_RDONLY mov edx, 0666o; //permissions in octal for nasm int 0x80; //call it
What should edx
to be to open a file, in general (or in this read-only case)? File’s current permissions, an empty, an arbitrary?
Thanks!
Advertisement
Answer
if neither O_CREAT nor O_TMPFILE is specified, then mode is ignored.
As such it doesn’t matter what you put in edx
if you are opening an existing file for reading. The cause of your problems is something else.