-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (55 loc) · 1.54 KB
/
main.cpp
File metadata and controls
67 lines (55 loc) · 1.54 KB
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
#include "idasdk.h"
#include <sstream>
#include <triton/context.hpp>
#include <triton/basicBlock.hpp>
#include <triton/x86Specifications.hpp>
using namespace triton;
using namespace triton::arch;
bool main(size_t)
{
constexpr const ea_t FUNC_EA = 0x400000;
msg_clear();
auto f = get_func(FUNC_EA);
if (f == nullptr)
{
msg("Can't find test function @ %a!\n", FUNC_EA);
return false;
}
/* Init the triton context */
triton::Context ctx;
ctx.setArchitecture(ARCH_X86_64);
func_item_iterator_t ffi;
BasicBlock bb;
for (bool ok = ffi.set(f); ok; ok = ffi.next_code())
{
auto ea = ffi.current();
insn_t insn;
if (decode_insn(&insn, ea) == 0)
{
msg("Failed to decode at %a\n", ea);
return false;
}
unsigned char buf[32];
get_bytes(buf, qmin(sizeof(buf), insn.size), ea);
// Setup opcode
Instruction inst;
inst.setOpcode(buf, insn.size);
inst.setAddress(triton::uint64(ea));
bb.add(inst);
}
ctx.disassembly(bb, FUNC_EA);
std::ostringstream ostr;
ostr << bb;
msg("----------------\n"
"Original:\n"
"----------------\n"
"%s\n", ostr.str().c_str());
ostr.str("");
auto simplified_bb = ctx.simplify(bb);
ostr << simplified_bb;
msg("----------------\n"
"Simplified:\n"
"----------------\n"
"%s\n", ostr.str().c_str());
return true;
}