forked from bitblaze-fuzzball/fuzzball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibasmir.idl
244 lines (197 loc) · 7.37 KB
/
libasmir.idl
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
Low level interface to libasmir. Avoid using this directly. Instead, use
the Asmir module.
*/
typedef [abstract] void* Exp;
typedef [abstract] void* Stmt;
typedef [abstract] void* asm_function_t;
typedef [abstract] void* asm_program_t;
typedef [abstract] void* vine_block_t;
typedef [abstract] void* vine_blocks_t;
typedef [abstract] void* dyn_function_t;
typedef [abstract] void* dyn_functions_t;
typedef [abstract] void* memory_cell_data_t;
typedef [abstract] void* memory_data_t;
typedef [abstract] void *instmap_t;
/* typedef [abstract] void* instmap_t_map;
typedef [ref] struct instmap_s {
[ref] asm_program_t *prog;
[abstract] instmap_t_map imap;
} *instmap_t; */
#include "../libasmir/config.h"
#if SIZEOF_BFD_VMA == 4
typedef [int64] unsigned long address_t;
#else
typedef unsigned long long int address_t;
#endif
typedef struct _raw_inst_t {
address_t address;
int length;
[size_is(length)] unsigned char *bytes;
} raw_inst_t;
//typedef [abstract] void* raw_insts_t;
enum asmir_arch {
asmir_arch_x86,
asmir_arch_x64, /* AKA AMD64, x86_64, x86-64, Intel 64 */
asmir_arch_arm,
};
typedef struct _vine_symbol_t {
[string] char *name;
address_t addr;
int is_function;
int is_dynamic;
} vine_symbol_t;
typedef struct _cflow_t {
int ctype;
address_t target;
} cflow_t;
typedef [abstract] void* vine_symbols_t;
enum exp_type_t {
BINOP, UNOP, CONSTANT, MEM, TEMP, PHI, CAST,
NAME, UNKNOWN, LET, ITE, EXTENSION };
enum reg_t { REG_1, REG_8, REG_16, REG_32, REG_64 };
enum binop_type_t {
PLUS = 0, MINUS , TIMES , DIVIDE,
MOD, LSHIFT, RSHIFT, ARSHIFT,
LROTATE, RROTATE, LOGICAND, LOGICOR,
BITAND, BITOR, XOR, EQ,
NEQ, GT, LT, GE,
LE,SDIVIDE, SMOD };
enum unop_type_t {NEG, NOT};
typedef __int64 const_val_t;
enum cast_t {
CAST_UNSIGNED, CAST_SIGNED, CAST_HIGH, CAST_LOW,
CAST_FLOAT, CAST_INTEGER, CAST_RFLOAT, CAST_RINTEGER };
enum stmt_type_t { JMP, CJMP, SPECIAL, MOVE, COMMENT, LABEL, EXPSTMT, VARDECL, CALL, RETURN, FUNCTION, ASSERT};
enum exp_type_t exp_type( [in] Exp e);
enum binop_type_t binop_type([in] Exp e);
Exp binop_lhs([in] Exp e);
Exp binop_rhs([in] Exp e);
enum unop_type_t unop_type([in] Exp e);
Exp unop_subexp([in] Exp e);
Exp mem_addr([in] Exp e);
enum reg_t mem_regtype([in] Exp e);
const_val_t constant_val([in] Exp e);
enum reg_t constant_regtype([in] Exp e);
[string] char* phi_phiname([in] Exp e);
int phi_numnodes([in] Exp e);
Exp phi_nodeat([in] Exp e, int i);
enum reg_t temp_regtype([in] Exp e);
[string] char* temp_name([in] Exp e);
[string] char* unknown_str([in] Exp e);
enum reg_t cast_width([in] Exp e);
enum cast_t cast_casttype([in] Exp e);
Exp cast_subexp([in] Exp e);
[string] char* name_string([in] Exp e);
Exp let_var([in] Exp e);
Exp let_exp([in] Exp e);
Exp let_in([in] Exp e);
Exp ite_cond([in] Exp e);
Exp ite_true_e([in] Exp e);
Exp ite_false_e([in] Exp e);
enum stmt_type_t stmt_type([in] Stmt s);
Exp move_lhs([in] Stmt s);
Exp move_rhs([in] Stmt s);
[string] char* label_string([in] Stmt s);
[string] char* special_string([in] Stmt s);
[string] char* comment_string([in] Stmt s);
Exp jmp_target([in] Stmt s);
Exp cjmp_cond([in] Stmt s);
Exp cjmp_ttarget([in] Stmt s);
Exp cjmp_ftarget([in] Stmt s);
Exp expstmt_exp([in] Stmt s);
[string] char* vardecl_name([in]Stmt s);
enum reg_t vardecl_type([in]Stmt s);
boolean call_has_lval([in] Stmt s);
Exp call_lval_opt([in] Stmt s);
Exp call_fnname([in] Stmt s);
[null_terminated] Exp* call_params([in] Stmt s);
boolean ret_has_exp([in] Stmt s);
Exp ret_exp([in] Stmt s);
[string] const char* func_name(Stmt s);
boolean func_has_rv(Stmt s);
enum reg_t func_rt(Stmt s);
[null_terminated] Stmt* func_params(Stmt s);
boolean func_is_external(Stmt s);
[null_terminated] Stmt* func_body(Stmt s);
Exp assert_cond(Stmt s);
// generated functions for eflags thunks
[null_terminated] Stmt* gen_eflags_helpers_c();
asm_program_t disassemble_program([string] char *filename);
asm_program_t instmap_to_asm_program(instmap_t instmap);
/* functions for disassembling a program and retrieving the IR on a
per-address basis */
/* interface with an elf directly */
instmap_t filename_to_instmap([string] char *filename);
vine_blocks_t instmap_translate_address_range(instmap_t instmap,
address_t start_addr,
address_t end_addr);
vine_block_t instmap_translate_address(instmap_t instmap,
address_t addr);
int instmap_has_address(instmap_t instmap, address_t addr);
//cflow_t instmap_control_flow_type(instmap_t instmap, address_t addr);
address_t get_last_segment_address([string] char *filename,
address_t addr);
vine_blocks_t asmir_asmprogram_to_vine(asm_program_t prog);
int asmir_vine_blocks_size(vine_blocks_t bs);
vine_block_t asmir_vine_blocks_get(vine_blocks_t bs, int i);
void destroy_vine_block(vine_block_t bs);
void destroy_vine_blocks(vine_blocks_t bs);
int asmir_vine_block_size(vine_block_t b);
address_t asmir_vine_block_address(vine_block_t b);
Stmt asmir_vine_block_get(vine_block_t b, int i);
void free_asm_function(asm_function_t f);
void free_asm_program(asm_program_t p);
vine_block_t asm_addr_to_ir(asm_program_t p, address_t addr);
[string] char* string_blockinsn(asm_program_t prog, vine_block_t block);
/*
vine_block_t
byte_insn_to_ir_c(address_t addr, [size_is(len)] char *bb_bytes, int len);
*/
dyn_functions_t get_synthetic_symbols([string] char *filename);
int dyn_functions_size(dyn_functions_t ds);
dyn_function_t dyn_functions_get(dyn_functions_t ds, int i);
[string] char* dyn_functions_name(dyn_function_t d)
quote(dealloc, "free(_res);");
address_t dyn_functions_addr(dyn_function_t d);
void destroy_dyn_functions(dyn_functions_t ds);
vine_symbols_t get_symbols_of_file([string] char *filename);
int symbols_size(vine_symbols_t ds);
vine_symbol_t *symbols_get(vine_symbols_t ds, int i) ;
void destroy_symbols(vine_symbols_t ds);
address_t memory_cell_data_address(memory_cell_data_t md);
int memory_cell_data_value(memory_cell_data_t md);
memory_data_t get_rodata(asm_program_t prog);
memory_data_t get_bssdata(asm_program_t prog);
int memory_data_size(memory_data_t md);
memory_cell_data_t memory_data_get(memory_data_t md, int i);
void destroy_memory_data(memory_data_t md);
/*
raw_insts_t raw_insts_of_file([string] char *ptr);
int raw_insts_size(raw_insts_t ri);
raw_inst_t * raw_insts_get([in] raw_insts_t ri, [in] int i);
void destroy_raw_insts(raw_insts_t ri);
*/
void set_use_eflags_thunks(boolean v);
// Return eflags thunk translation setting.
boolean get_use_eflags_thunks();
/// if set to true, calls/ret in assembly are translated as calls/returns
/// Deprecated
void set_call_return_translation(boolean v);
// Returns the architecture of a program
enum asmir_arch asmprogram_arch(asm_program_t prog);
void set_disasm_format_intel(boolean is_intel);
// Prints to stdout the disassembly string for the given architecture and addr
void print_disasm_rawbytes(enum asmir_arch arch,
address_t addr,
[size_is(size)] char *buf, int size);
// Returns the disassembly string for the given architecture and addr
[string] char* sprintf_disasm_rawbytes(enum asmir_arch arch,
boolean is_intel,
address_t addr,
[size_is(size)] char *buf, int size);
// returns a special asm_program which contains only the given instruction
// takes a char array for historical reasons
asm_program_t
byte_insn_to_asmp(enum asmir_arch arch, address_t addr,
[size_is(len)/*,string*/] char *bb_bytes, int len);