-
Notifications
You must be signed in to change notification settings - Fork 0
/
freorder.h
66 lines (49 loc) · 1.7 KB
/
freorder.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
62
63
64
65
66
#ifndef F_REORDER_H
#define F_REORDER_H
#include <elf.h>
/* struct containgin function name and offset in file*/
typedef struct{
char *name;
int offset;
} func_t;
typedef struct{
char *fname;
char *cfname;
int ins_off;
int ins_val;
} call_graph_t;
/* Returns program header of the segment containg text section */
Elf32_Phdr *get_seg_text_phdr(char *elf_file);
/* Return call graph */
call_graph_t *get_call_graph(char *elf_file);
void resolve_func_calls(char *elf_file, call_graph_t *cgraph);
/** Re-orders text segment according to given function order
*
* params: elf_file - ELF file to re-order
* params: new_function_order - Given function order
*
*/
void reorder_seg_text(char *elf_file, func_t *new_func_order);
/* Update symble table with new function offset */
void update_sym_tab(char *elf_file, func_t *new_funcs, int len);
/** Returns a list of all the functions from text section
*
* param: elf_file - ELF file
* param: len - Pointer to get number of functions
*
* returns: pointer pointing to an array of func_t
*/
func_t *get_func_list(char *elf_file, int *len);
/* Sorts list of functions according to offset */
void sort_func_list(func_t *funcs, int len);
/* Comparison function for sort_func_list() */
int compare_func(const void *a, const void *b);
/* Prints a list of functions in stdout */
void print_func_list(func_t *funcs, int len);
/* Search a function in a list of functions */
int search_func_in_list(func_t *funcs, int len, const char *key);
/* Prints raw bytes in stdout */
void print_hex(const unsigned char *content, int len);
func_t *get_func_from_file(char *name, int *len);
int write_funcs_to_file(func_t *funcs, int len, char *fname);
#endif