为什么在反汇编程序中找不到硬编码字符串?

逆向工程 拆卸 C
2021-06-23 18:35:52

我写了一个简单的程序来在屏幕上打印一些东西,如下所示:

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等于,因此 的值将为0x1151mov[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$

为什么?

1个回答

搜索字符串,你不能使用 disassemble-all

look at the bytes in both commands if you disassemble how can you find the string

objdump -s sample.exe |grep -i sample
sample.exe:     file format pei-i386
 404040 00000000 53616d70 6c652100 20634000  ....Sample!. c@.

objdump -M intel --disassemble-all sample.exe  --start-address=0x404044 --stop-address=0x40404f

sample.exe:     file format pei-i386


Disassembly of section .rdata:

00404044 <.rdata>:
  404044:       53                      push   ebx
  404045:       61                      popa
  404046:       6d                      ins    DWORD PTR es:[edi],dx
  404047:       70 6c                   jo     4040b5 <.rdata+0x45>
  404049:       65 21 00                and    DWORD PTR gs:[eax],eax

0040404c <_GS_ExceptionPointers>:
  40404c:       20 63 40                and    BYTE PTR [ebx+0x40],ah