-
Notifications
You must be signed in to change notification settings - Fork 0
/
elf.h
60 lines (51 loc) · 1.03 KB
/
elf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef ELF_H
#define ELF_H
#include "types.h"
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFCLASSNONE 0
#define ELFCLASS32 1
#define ELFCLASS64 2
enum {
ELF_ERR_NONE,
ELF_ERR_WRONG_MAGIC,
ELF_ERR_WRONG_CLASS,
ELF_ERR_NO_PROGRAM_HEADER
};
typedef struct {
uint8_t e_ident[16];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
uint32_t e_entry;
uint32_t e_phoff;
uint32_t e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} elf_header_t;
typedef struct {
uint32_t type;
uint32_t offset;
uint32_t vaddr;
uint32_t paddr;
uint32_t filesize;
uint32_t memsize;
uint32_t flags;
uint32_t align;
} elf_ph_t;
#define PF_R 0x4 /* p_flags */
#define PF_W 0x2
#define PF_X 0x1
/*
* Loads the elf-file and their segments to whereever they need to be and returns the start-address
*/
uint32_t elf_load_executable(void* file);
uint32_t elf_last_error();
#endif