I'm writing in assembly and I'm trying to figure out how to perform an execve syscall, but instead of having the output printed to the terminal, I'd like to know where it's stored so I can use it later, kind of like piping commands.
For instance, here's assembly for executing the command 'which' via execve, essentially executing the command '$ which ls':
GLOBAL _start
SECTION .TEXT
_start:
XOR EAX,EAX
PUSH EAX
PUSH 0x68636968
PUSH 0x772f6e69
PUSH 0x622f7273
PUSH 0x752f2f2f
MOV EBX, ESP
PUSH EAX
PUSH 0x736c
MOV ESI, ESP
XOR EDX, EDX
PUSH EDX
PUSH ESI
PUSH EBX
MOV ECX, ESP
MOV AL, 0x0B; EXECVE SYSCALL NUMBER
INT 0x80
Lines 7-10 push the address of /usr/bin/which onto the stack, and line 13 pushes the argument ls onto the stack. It then pushes the arguments array onto the stack and stores that in the ECX, has the EBX pointing to the address of the location of /usr/bin/which, and the EAX set to the syscall number 0xb (11) for the execve syscall. When executed, it returns /bin/ls, the location of ls that we asked it to find.
How do I store that result of /bin/ls somewhere for other use? Like if I wanted to keep writing code and use what's returned here as a part of the next piece of code, how do I keep the returned value in either a register or on the stack?