Is it possible changing few bytes for converting an elf binary from PIE to No-PIE (ELF)?
I know that in the header if e_type
is:
- 3 then the program is PIE
- 2 then the program is No-PIE
So I tried to change that byte and in fact readelf -h
shows me:
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: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x630
Start of program headers: 64 (bytes into file)
Start of section headers: 6576 (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
Then I changed the e_entry
from 0x630
to 0x400630
.
readelf -h
output:
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: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x400630
Start of program headers: 64 (bytes into file)
Start of section headers: 6576 (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
However if I try to launch the program it crashes.
$ strace ./elf-patched.exe
execve("./elf-patched.exe", ["./elf-patched.exe"], 0x7ffe0c2b88c0 /* 66 vars */) = -1 EPERM (Operation not permitted)
+++ killed by SIGSEGV +++
[1] 7239 segmentation fault (core dumped) strace ./elf-patched.exe
What other bytes should I change (If it's possible with few modifications) ?