-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtritonhelper.cpp
100 lines (90 loc) · 2.51 KB
/
tritonhelper.cpp
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
#include "pch.h"
#include "tritonhelper.hpp"
triton::engines::symbolic::SharedSymbolicVariable get_symbolic_var(const triton::ast::SharedAbstractNode &node)
{
return node->getType() == triton::ast::VARIABLE_NODE ?
std::dynamic_pointer_cast<triton::ast::VariableNode>(node)->getSymbolicVariable() : nullptr;
}
std::set<triton::ast::SharedAbstractNode> collect_symvars(const triton::ast::SharedAbstractNode &parent)
{
std::set<triton::ast::SharedAbstractNode> result;
if (!parent)
return result;
if (parent->getChildren().empty() && parent->isSymbolized())
{
// this must be variable node right?
assert(parent->getType() == triton::ast::VARIABLE_NODE);
result.insert(parent);
}
for (const triton::ast::SharedAbstractNode &child : parent->getChildren())
{
if (!child->getChildren().empty())
{
// go deep if symbolized
if (child->isSymbolized())
{
auto _new = collect_symvars(child);
result.insert(_new.begin(), _new.end());
}
}
else if (child->isSymbolized())
{
// this must be variable node right?
assert(child->getType() == triton::ast::VARIABLE_NODE);
result.insert(child);
}
}
return result;
}
bool is_unary_operation(const triton::arch::Instruction &triton_instruction)
{
switch (triton_instruction.getType())
{
case triton::arch::x86::ID_INS_INC:
case triton::arch::x86::ID_INS_DEC:
case triton::arch::x86::ID_INS_NEG:
case triton::arch::x86::ID_INS_NOT:
return true;
default:
return false;
}
}
bool is_binary_operation(const triton::arch::Instruction &triton_instruction)
{
switch (triton_instruction.getType())
{
case triton::arch::x86::ID_INS_ADD:
case triton::arch::x86::ID_INS_SUB:
case triton::arch::x86::ID_INS_SHL:
case triton::arch::x86::ID_INS_SHR:
case triton::arch::x86::ID_INS_RCR:
case triton::arch::x86::ID_INS_RCL:
case triton::arch::x86::ID_INS_ROL:
case triton::arch::x86::ID_INS_ROR:
case triton::arch::x86::ID_INS_AND:
case triton::arch::x86::ID_INS_OR:
case triton::arch::x86::ID_INS_XOR:
case triton::arch::x86::ID_INS_CMP:
case triton::arch::x86::ID_INS_TEST:
return true;
case triton::arch::x86::ID_INS_IMUL:
{
// imul can have 3 operands but eh
return triton_instruction.operands.size() == 2;
}
default:
return false;
}
}
bool is_mov_operation(const triton::arch::Instruction& triton_instruction)
{
switch (triton_instruction.getType())
{
case triton::arch::x86::ID_INS_MOV:
case triton::arch::x86::ID_INS_MOVSX:
case triton::arch::x86::ID_INS_MOVZX:
return true;
default:
return false;
}
}