I'm trying to put a reference to my stack pointer into the %rsi register so that the syscall will get the struct from i's second parameter.
here is the code :
01: mov $0x2a, %al
02 : mov $3, %rdi
03 : push $0x02
04 : push $0x0068
05 : push $0x5c11
06 : push $0xa8c0
07 : push $0x1401
08 : mov (%rsp), %r13
09 : mov %r13, %rsi # this is where I get lost
10 : mov $0x10, %dl
11 : syscall
strace ./helloWorld give me this :
connect(3, 0x5c11, 16)
exit(0)
My question is : how can I pass a struct that I have put on the stack to the rsi register (by passing the pointer of the stack)
What I have tryied so far :
- Reading about GNU syntax
- passing the reference directly without intermediate register
08 : #mov (%rsp), %r13 09 : mov %rsi, (%rsp) - using pointer deplacement
03 : mov $0x02 (%rsp) 04 : movw $0x0068 2(%rsp) 05 : movw $0x5c11 4(%rsp) 06 : movw $0xa8c0 6(%rsp) 07 : movw $0x1401 8(%rsp) 08 : # mov (%rsp), %r13 09 : mov (%rsp), %rsi strace ./hellowWorld: ... connect(3, 0xa8c05c1100680002, 16) ...
Every time I have in the second argument is the value of the registers or the stacks, not a pointer.
Using NASM syntax, Everything is ok.
I am using theses resources :
- http://6.s081.scripts.mit.edu/sp18/x86-64-architecture-guide.html
- https://syscalls.w3challs.com/?arch=x86_64
- Youtube : x86-64 GNU Assembler Crash-Course From "Write your own Operating System"
- Youtube : How to Write Shellcode playlist From "Tactical Network Solutions"