I got a segfault which means I finally managed to execute my byte code ¦), for everyone's reference this is what I used:
Code:
/* Fill remaining init header information */
fill_elf64_header:
init64.e_ident[EI_MAG0] = 0x7F;
init64.e_ident[EI_MAG1] = 'E';
init64.e_ident[EI_MAG2] = 'L';
init64.e_ident[EI_MAG3] = 'F';
init64.e_ident[EI_CLASS] = ELFCLASS64;
init64.e_ident[EI_DATA] = ELFDATA2LSB;
init64.e_ident[EI_VERSION] = EV_CURRENT;
init64.e_ident[EI_OSABI] = ELFOSABI_NONE;
init64.e_ehsize = sizeof(elf64_init_header_t);
init64.e_type = ET_DYN;
init64.e_machine = EM_X86_64;
init64.e_version = EV_CURRENT;
Offsets & counts are unimportant for using this as a reference.
Now for the bit I actually need help with, resolving my segfault, since the original thread I posted the byte code in requires clicking to get too I'll add it to this post:
Code:
unsigned char txt_exit[] = {
0xB8, __NR_exit, 0, 0, 0,
0x0F, 5,
0xC3
};
unsigned char txt_start[] = {
0xBF, 0, 0, 0, 0,
0xE8, 0, 0, 0, 0
};
data_t test_c[] = {
{ 0,"test.c", NULL },
{ sizeof(txt_start), "_start", txt_start },
{ sizeof(txt_exit), "exit", txt_exit },
{0}};
Now for my output from start finish (I added a means of ignoring headers as much as possible so this is the result)
Code:
make check (in directory: /home/zxuiji/Desktop/mitsy)
./mitsy.elf
cd ./gede-2.14.1 && make
make[1]: Entering directory '/home/zxuiji/Desktop/mitsy/gede-2.14.1'
./build.py --verbose
make[2]: Entering directory '/home/zxuiji/Desktop/mitsy/gede-2.14.1/src'
make[2]: Nothing to be done for 'first'.
make[2]: Leaving directory '/home/zxuiji/Desktop/mitsy/gede-2.14.1/src'
Compiling (please wait)
make[1]: Leaving directory '/home/zxuiji/Desktop/mitsy/gede-2.14.1'
readelf -all test.elf
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: 0x78
Start of program headers: 64 (bytes into file)
Start of section headers: 0 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 1
Size of section headers: 0 (bytes)
Number of section headers: 0
Section header string table index: 0
There are no sections in this file.
There are no sections to group in this file.
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
NULL 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x000000000000008a 0x000000000000008a R E 0x0
There is no dynamic section in this file.
There are no relocations in this file.
The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.
Dynamic symbol information is not available for displaying symbols.
No version information found in this file.
gdb -ex run --args ./test.elf
GNU gdb (Ubuntu 8.2-0ubuntu1~18.04) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test.elf...(no debugging symbols found)...done.
Starting program: /home/zxuiji/Desktop/mitsy/test.elf
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000078 in ?? ()
(gdb) quit
A debugging session is active.
Inferior 1 [process 3937] will be killed.
Quit anyway? (y or n) [answered Y; input not from terminal]
./test.elf
makefile:46: recipe for target 'check' failed
make: *** [check] Segmentation fault (core dumped)
Compilation failed.