-
Notifications
You must be signed in to change notification settings - Fork 0
/
elf_loader.hpp
55 lines (49 loc) · 1.29 KB
/
elf_loader.hpp
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
#pragma once
/* C standard library */
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
/* POSIX */
#include <unistd.h>
#include <sys/user.h>
#include <sys/wait.h>
#include <libelf.h>
#include <gelf.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/* Linux */
#include <syscall.h>
#include <sys/ptrace.h>
/*C++ headers*/
#include <iostream>
#include <string>
#include <map>
//@macros
#define DIE_elf(...) \
do \
{ \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
exit(EXIT_FAILURE); \
} while (0)
//@ function prototypes
typedef struct struct_elf
{
Elf *elf; // the elf given
Elf_Scn *symtab; // used for symbol table
Elf_Scn *dynsym; // used for dynamic symbol table
size_t shstrtab_index; // used for section string table
bool is_stripped;
Elf_Data *text;
long unsigned text_start = 0;
long unsigned text_end = 0;
} elf_file;
/*
function that loads the elf in the elf_file struct using libelf
*/
void load_elf(const char *filename, elf_file *elf);
void debug_symbols(elf_file *elf, std::map<std::string, long> *symbol_mappings);