I am trying to output a file in Assembly using cat with the execve syscall, but I am having a bit of trouble and I don't know why.
section .text
global _start
_start:
mov al, 59 ; Syscall number
xor rdx, rdx ; No enviornment variables
push rdx
; Add arg1
mov rdi, "/bin/cat"
push rdi
mov rdi, rsp
push rdx
; Add arg2
mov si, "xt"
push rsi
mov rsi, "//file.t"
push rsi
mov rsi, rsp
; Call execve
syscall
I checked to make sure /file.txt exists. Then looked at the stack with GDB before the syscall is done, and everything also looks correct:
0x00007fffc25f8628│+0x0000: "//file.txt" ← $rsp, $rsi
0x00007fffc25f8630│+0x0008: 0x0000000000007478 ("xt"?)
0x00007fffc25f8638│+0x0010: 0x0000000000000000
0x00007fffc25f8640│+0x0018: "/bin/cat" ← $rdi
How can I call execve correctly?
Here is an 64-bit example, written in nasm, that runs an external command with arguments and this works for me.
Best regards.