I have disassembled a C program with Radare2. Inside this program there are many calls to scanf
like the following:
0x000011fe 488d4594 lea rax, [var_6ch]
0x00001202 4889c6 mov rsi, rax
0x00001205 488d3df35603. lea rdi, [0x000368ff] ; "%d" ; const char *format
0x0000120c b800000000 mov eax, 0
0x00001211 e86afeffff call sym.imp.__isoc99_scanf ; int scanf(const char *format)
0x00001216 8b4594 mov eax, dword [var_6ch]
0x00001219 83f801 cmp eax, 1 ; rsi ; "ELF\x02\x01\x01"
0x0000121c 740a je 0x1228
Here scanf
has the address of the string "%d"
passed to it from the line lea rdi, [0x000368ff]
. I'm assuming 0x000368ff
is the location of "%d"
in the exectable file because if I restart Radare2 in debugging mode (r2 -d ./exec
) then lea rdi, [0x000368ff]
is replaced by lea rdi, [someMemoryAddress]
.
If lea rdi, [0x000368ff]
is whats hard coded in the file then how does the instruction change to the actual memory address when run?