![](/img/trans.png)
[英]In elf binary, Is there any simple method to get memory address from offset?
[英]Constructing working ELF binary from memory dump
我編寫了以下簡單的 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 上設置一個捕捉點的原因是因為這個系統調用在程序執行之前被調用,但是程序加載到內存中)
在 memory 轉儲上使用readelf會得到以下 output
$ 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!
我想知道如何修復這些錯誤並從這個與原始程序運行相同的 memory 轉儲生成可執行的 ELF 二進制文件。 請注意,我只想使用 hexeditor(例如hexedit )而不使用原始二進制文件來執行此操作。
dump binary memory testdump 0x8000000 0x8001000
要制作可運行的程序,您還需要轉儲數據。
您的測試二進制文件是動態鏈接的,這會使您的任務變得非常復雜。 我建議從完全靜態的二進制文件開始。
我只想用一個 hexeditor 來做這個
這項任務實際上並非易事,我懷疑您是否能夠使用 GDB 完成它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.