-
Notifications
You must be signed in to change notification settings - Fork 50
/
imports_obj.h
158 lines (143 loc) · 3.09 KB
/
imports_obj.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* naken_asm assembler.
* Author: Michael Kohn
* Email: [email protected]
* Web: https://www.mikekohn.net/
* License: GPLv3
*
* Copyright 2010-2023 by Michael Kohn
*
*/
#ifndef NAKEN_ASM_IMPORTS_OBJ_H
#define NAKEN_ASM_IMPORTS_OBJ_H
typedef struct _elf_header32
{
uint8_t e_ident[4];
uint8_t e_ident_class;
uint8_t e_ident_data;
uint8_t e_ident_version;
uint8_t e_ident_osabi;
uint8_t e_ident_abiversion;
uint8_t e_ident_pad[7];
uint8_t e_type[2];
uint8_t e_machine[2];
uint8_t e_version[4];
uint8_t e_entry[4];
uint8_t e_phoff[4];
uint8_t e_shoff[4];
uint8_t e_flags[4];
uint8_t e_ehsize[2];
uint8_t e_phentsize[2];
uint8_t e_phnum[2];
uint8_t e_shentsize[2];
uint8_t e_shnum[2];
uint8_t e_shstrndx[2];
} ElfHeader32;
typedef struct _elf_header64
{
uint8_t e_ident[4];
uint8_t e_ident_class;
uint8_t e_ident_data;
uint8_t e_ident_version;
uint8_t e_ident_osabi;
uint8_t e_ident_abiversion;
uint8_t e_ident_pad[7];
uint8_t e_type[2];
uint8_t e_machine[2];
uint8_t e_version[4];
uint8_t e_entry[8];
uint8_t e_phoff[8];
uint8_t e_shoff[8];
uint8_t e_flags[4];
uint8_t e_ehsize[2];
uint8_t e_phentsize[2];
uint8_t e_phnum[2];
uint8_t e_shentsize[2];
uint8_t e_shnum[2];
uint8_t e_shstrndx[2];
} ElfHeader64;
typedef struct _elf_program32
{
uint8_t p_type[4];
uint8_t p_offset[4];
uint8_t p_vaddr[4];
uint8_t p_paddr[4];
uint8_t p_filesz[4];
uint8_t p_memsz[4];
uint8_t p_flags[4];
uint8_t p_palign[4];
} ElfProgram32;
typedef struct _elf_program64
{
uint8_t p_type[4];
uint8_t p_flags[4];
uint8_t p_offset[8];
uint8_t p_vaddr[8];
uint8_t p_paddr[8];
uint8_t p_filesz[8];
uint8_t p_memsz[8];
uint8_t p_palign[8];
} ElfProgram64;
typedef struct _elf_section32
{
uint8_t sh_name[4];
uint8_t sh_type[4];
uint8_t sh_flags[4];
uint8_t sh_addr[4];
uint8_t sh_offset[4];
uint8_t sh_size[4];
uint8_t sh_link[4];
uint8_t sh_info[4];
uint8_t sh_addralign[4];
uint8_t sh_entsize[4];
} ElfSection32;
typedef struct _elf_section64
{
uint8_t sh_name[4];
uint8_t sh_type[4];
uint8_t sh_flags[8];
uint8_t sh_addr[8];
uint8_t sh_offset[8];
uint8_t sh_size[8];
uint8_t sh_link[4];
uint8_t sh_info[4];
uint8_t sh_addralign[8];
uint8_t sh_entsize[8];
} ElfSection64;
typedef struct _elf_symbol32
{
uint8_t st_name[4];
uint8_t st_value[4];
uint8_t st_size[4];
uint8_t st_info;
uint8_t st_other;
uint8_t st_shndx[2];
} ElfSymbol32;
typedef struct _elf_relocation32
{
uint8_t r_offset[4];
uint8_t r_info[4];
} ElfRelocation32;
typedef struct _elf_symbol64
{
uint8_t st_name[4];
uint8_t st_info;
uint8_t st_other;
uint8_t st_shndx[2];
uint8_t st_value[8];
uint8_t st_size[8];
} ElfSymbol64;
int imports_obj_verify(const uint8_t *buffer, int file_size);
int imports_obj_find_code_from_symbol(
uint8_t *buffer,
int file_size,
const char *symbol,
uint32_t *function_offset,
uint32_t *function_size,
uint32_t *file_offset);
const char *imports_obj_find_name_from_offset(
const uint8_t *buffer,
int file_size,
uint32_t function_offset,
uint32_t local_offset);
#endif