edi is argc, rsi is argv
0x0000000000400535 <+8>: mov %edi,-0x4(%rbp)
0x0000000000400538 <+11>: mov %rsi,-0x10(%rbp)
here I get argv pointer
(gdb) x/8x $rbp-0x10
0x7ffdb7cac380: 0xb7cac478 0x00007ffd 0x00000000 0x00000003
0x7ffdb7cac390: 0x00000000 0x00000000 0x1f130b45 0x00007ff3
Pointer 0x7ffdb7cac478
So my argv[2] is here:
(gdb) x/8x 0x7ffdb7cac478+16
0x7ffdb7cac488: 0xb7cacd8a 0x00007ffd 0x00000000 0x00000000
At address 0x7ffdb7cacd8a
I need to get the address of argv[2], so I want to write this assembler code:
Pseudocode:
x - load 8 bytes from address $rbp-0x10 // (pointer to argv)
y - load 8 bytes from x value+16 // (pointer to argv[2])
I need later to jmp to y.
How do I write in assembler x64? Which register I can use to for x and y?
I hope it is understandable. I am a beginner.
I ask here since I don't know where to start doing my research.
UPDATE:
Tried with this:
bits 64
ldr r8, rbp, #0x10
ldr r9, r8, #0x10
jmp r9
But it doesn't even compile .... I am using nasm.
I guess above was for ARM arch, for amd64 (x64) below should do this. Is it correct?
UPDATE 2:
bits 64
lea r8, [rbp-0x10]
lea r9, [r8+0x10]
jmp r9
UPDATE 3:
Also doesn't work ...
bits 64
lea r8, [rbp-0x10]
mov r9, [r8]
mov r10, [r9+0x10]
jmp r10