I am a newbie in this, and I am trying to add a program header to a simple ELF64 "Hello World" program on Ubuntu. All in changing the binary data of the ELF.
I went to the end of the program headers (Start of program headers + (Size of program headers * Number of program headers)
) and inserted a 56 byte length program header of a valid address in the file. I then increased the Number of programs headers
by 1, and increased the Entry point address
and the Start of section headers
by 56.
Is there anything I am still missing? I get errors while trying to run readelf
on my modified ELF and it clearly shows that I messed something up.
I get many errors when using -a (most of them is: readelf: Error: Reading 16 bytes extends past end of file for version need aux (3)
). When I am trying to run my modified ELF, it gives me segmentation fault at the beginning:
>strace ./helloWorld-modified
execve("./helloWorld-modified", ["./helloWorld-modified"], 0x7fffbb83ddb0 /* 25 vars */) = -1 EINVAL (Invalid argument)
--- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=NULL} ---
+++ killed by SIGSEGV +++
Segmentation fault
Please tell if I need to add more context here. I am adding the original readelf -h
:
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: 6448 (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
This is the program header data I added:
LOAD 0x00000000000020a8 0x0000000000010000 0x0000000000000000
0x0000000000000020 0x0000000000000020 R 0x0