No luck getting my test.elf to run yet, gotta start prepping for work too, Here's what I'm currently using for my execution code:
Code:
unsigned char txt_exit[] = {
0xB8, 0, 0, 0, __NR_exit,
0x0F, 5,
0xC3
};
unsigned char txt_start[] = {
0xB9, 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}};
And this is the resulting output:
Code:
make check (in directory: /home/zxuiji/Desktop/mitsy)
clang -D_LARGEFILE64_SOURCE -D_MITSY_TEST_ELF=test.elf -Wall -o mitsy.o -c mitsy.c
clang -o mitsy.elf mitsy.o memory.o
./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: EXEC (Executable file)
Machine: None
Version: 0x1
Entry point address: 0x2f4
Start of program headers: 64 (bytes into file)
Start of section headers: 288 (bytes into file)
Flags: 0x0
Size of this header: 0 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 4
Size of section headers: 64 (bytes)
Number of section headers: 4
Section header string table index: 1
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .shstrtab STRTAB 0000000000000220 00000220
000000000000002c 0000000000000001 A 0 0 1
[ 2] .symtab SYMTAB 000000000000024c 0000024c
00000000000000a8 0000000000000018 A 1 7 8
[ 3] .text PROGBITS 0000000100000000 000002f4
0000000000000012 0000000000000000 WAX 0 0 18
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
NULL 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0
PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040
0x00000000000000e0 0x00000000000000e0 R 0x8
LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x00000000000002f4 0x00000000000002f4 R E 0x1
LOAD 0x00000000000002f4 0x0000000100000000 0x0000000100000000
0x0000000000000012 0x0000000000000012 RWE 0x12
Section to Segment mapping:
Segment Sections...
00
01
02 .shstrtab .symtab
03 .text
There is no dynamic section in this file.
There are no relocations in this file.
The decoding of unwind sections for machine type None is not currently supported.
Symbol table '.symtab' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000220 0 SECTION GLOBAL DEFAULT 1 .shstrtab
2: 000000000000024c 0 SECTION GLOBAL DEFAULT 2 .symtab
3: 00000000000002f4 0 SECTION GLOBAL DEFAULT 3 .text
4: 00000000000002f4 0 FILE GLOBAL DEFAULT 1 test.c
5: 00000000000002f4 10 FUNC GLOBAL DEFAULT 1 _start
6: 00000000000002fe 8 FUNC GLOBAL DEFAULT 1 exit
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
/bin/bash: /home/zxuiji/Desktop/mitsy/test.elf: cannot execute binary file: Exec format error
/bin/bash: /home/zxuiji/Desktop/mitsy/test.elf: Success
(gdb) quit
During startup program exited with code 126.
./test.elf
./test.elf: 1: ./test.elf: ELF\Uffffffff not found
makefile:46: recipe for target 'check' failed
./test.elf: 2: ./test.elf: Syntax error: Unterminated quoted string
make: *** [check] Error 2
Compilation failed.