-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.h
61 lines (46 loc) · 1.55 KB
/
loader.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
61
#ifndef LOADER_H
#define LOADER_H
#include <elf.h>
#include <stdio.h>
/* Structure containing function name and address */
typedef struct{
char *name;
Elf32_Addr addr;
} lib_func_t;
/* Returns size of a fiel */
size_t file_sz(FILE *fp);
/* Loads file into memory */
void *load_file(const char *name, size_t *fsize);
/* Write data to file */
int write_file(char *elf_file, int fsize, char *name);
/*
* Maps loadable segments into memory and returns
* pointer to memory
*/
void *load_image(char *elf_file, size_t size);
/* Loads an ELF binary into memory and returns entry point */
void *load_bin_image(char *elf_file, size_t size);
/*
* Loads an ELF shared library into memory and returns loaded
* address of all the functions
*/
lib_func_t *load_sh_lib_image(char *lib_file, size_t size,
int *nfunc);
/* Find library functions that are used in binary */
lib_func_t *get_bin_functions(char *bin_file, int *nfunc);
/* Resolves function addresses in GOT */
void resolve_elf_got(char *bin_file, size_t size,
lib_func_t *funcs, int funcs_len);
/* Returns memory address of a symbol */
void *find_sym(const char *name, Elf32_Shdr *shdr,
const char *strtbl, const char *elf,
const char *mem);
/* Returns section index */
int sec_index_from_name(char *elf_file,
Elf32_Ehdr *ehdr,
char *name);
/* Returns section header */
Elf32_Shdr *sec_from_name(char *elf_file, char *name);
/* Prints GOT */
void print_got(char *bin_file);
#endif