我写了一个简单的程序来在屏幕上打印一些东西,如下所示:
ebra@him:/tmp/tuts$ cat sample.c
#include <stdio.h>
int main()
{
puts("Sample!");
}
ebra@him:/tmp/tuts$ gcc sample.c -o sample
ebra@him:/tmp/tuts$
ebra@him:/tmp/tuts$ ./sample
Sample!
然后我反汇编了可执行文件,看看幕后发生了什么:
ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep "<main>:" -A 10
0000000000001149 <main>:
1149: f3 0f 1e fa endbr64
114d: 55 push rbp
114e: 48 89 e5 mov rbp,rsp
1151: 48 8d 3d ac 0e 00 00 lea rdi,[rip+0xeac] # 2004 <_IO_stdin_used+0x4>
1158: e8 f3 fe ff ff call 1050 <puts@plt>
115d: b8 00 00 00 00 mov eax,0x0
1162: 5d pop rbp
1163: c3 ret
1164: 66 2e 0f 1f 84 00 00 nop WORD PTR cs:[rax+rax*1+0x0]
116b: 00 00 00
正如你在上面看到的,在调用puts
函数之前,我们有lea rdi,[rip+0xeac]
. 我假设这[rip+0xeac]
是硬编码文本的地址(即“示例!”)。
由于在执行线时rip
等于,因此 的值将为。0x1151
mov
[rip + 0xeac]
0x1151 + 0xeac = 0x1ffd
但是在反汇编的程序中找不到这个地址:
ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep -i 1ffd
ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep -i "Sample!"
ebra@him:/tmp/tuts$
为什么?