forked from samunders-core/le_disasm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdis_info.h
42 lines (33 loc) · 1.2 KB
/
dis_info.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
#ifndef LE_DISASM_DIS_INFO_H_
#define LE_DISASM_DIS_INFO_H_
#include <dis-asm.h>
extern "C" int print_insn_i386_att(bfd_vma pc, disassemble_info *info);
#include "insn.h"
class DisInfo : disassemble_info {
static void callbackPrintAddress(bfd_vma address, disassemble_info *info) {
info->fprintf_func(info->stream, "0x00%lx", address);
((Insn *)info->stream)->memoryAddress = address;
}
public:
DisInfo() {
init_disassemble_info(this, NULL, &Insn::callbackResetTypeAndText);
print_address_func = callbackPrintAddress;
}
void disassemble(uint32_t addr, const void *data, size_t length, Insn &insn) {
buffer = (bfd_byte *)data;
buffer_length = length;
buffer_vma = addr;
stream = &insn;
mach = insn.bitness() == BITNESS_32BIT ? bfd_mach_i386_i386 : bfd_mach_i386_i8086;
insn.reset();
int size = print_insn_i386_att(addr, this);
if (size < 0) { // FIXME: dump arguments to error
throw Error() << "Failed to disassemble instruction";
}
insn.setSize(size);
if (size > 0) {
insn.setTargetAndType(addr, data);
}
}
};
#endif /* LE_DISASM_DIS_INFO_H_ */