【发布时间】:2020-07-31 12:35:41
【问题描述】:
我编写了以下简单的 C 程序
#include <stdio.h>
int main()
{
printf("Hello\n");
return 0;
}
编译后我在 GDB 中加载这个程序并继续如下
> catch syscall brk
*run and wait for GDB to catch syscall*
> info proc mappings
Start Addr End Addr Size Offset
0x8000000 0x8001000 0x1000 0x0 <--- this region is r-xp, so this is the code in memory
0x8200000 0x8202000 0x2000 0x0 <--- this region is rw-p, so this is the data in memory
> dump binary memory testdump 0x8000000 0x8001000
(我在 brk 上设置一个 catchpoint 的原因是因为这个系统调用在程序执行之前被调用,但是程序加载到内存中)
在内存转储上使用 readelf 会得到以下输出
$ readelf -h testdump
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x530
Start of program headers: 64 (bytes into file)
Start of section headers: 6440 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 29
Section header string table index: 28
readelf: Error: Reading 1856 bytes extends past end of file for section headers
readelf: Error: Section headers are not available!
我想知道如何修复这些错误并从这个内存转储中生成一个可执行的 ELF 二进制文件,它与原始程序运行相同。请注意,我只想使用 hexeditor(例如 hexedit)而不使用原始二进制文件来执行此操作。
【问题讨论】:
标签: linux debugging binary reverse-engineering elf