libTriton  version 0.7 build 1398
astContext.hpp
Go to the documentation of this file.
1 /*
3 ** Copyright (C) - Triton
4 **
5 ** This program is under the terms of the BSD License.
6 */
7 
8 #ifndef TRITON_AST_CONTEXT_H
9 #define TRITON_AST_CONTEXT_H
10 
11 #include <map>
12 #include <vector>
13 
14 #include <triton/ast.hpp>
16 #include <triton/dllexport.hpp>
17 #include <triton/exceptions.hpp>
18 
19 
20 
22 namespace triton {
28  /* Forward declarations */
29  namespace engines {
30  namespace symbolic {
31  class SymbolicExpression;
32  using SharedSymbolicExpression = std::shared_ptr<triton::engines::symbolic::SymbolicExpression>;
33 
34  class SymbolicVariable;
35  using SharedSymbolicVariable = std::shared_ptr<triton::engines::symbolic::SymbolicVariable>;
36  };
37  };
38 
40  namespace ast {
47 
49  class AstContext {
50  private:
53 
55  std::map<std::string, std::pair<triton::ast::SharedAbstractNode, triton::uint512>> valueMapping;
56 
57  public:
59  TRITON_EXPORT AstContext();
60 
62  TRITON_EXPORT AstContext(const AstContext& other);
63 
65  TRITON_EXPORT ~AstContext();
66 
68  TRITON_EXPORT AstContext& operator=(const AstContext& other);
69 
71  TRITON_EXPORT SharedAbstractNode assert_(const SharedAbstractNode& expr);
72 
74  TRITON_EXPORT SharedAbstractNode bv(triton::uint512 value, triton::uint32 size);
75 
77  TRITON_EXPORT SharedAbstractNode bvadd(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
78 
80  TRITON_EXPORT SharedAbstractNode bvand(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
81 
83  TRITON_EXPORT SharedAbstractNode bvashr(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
84 
86  TRITON_EXPORT SharedAbstractNode bvfalse(void);
87 
89  TRITON_EXPORT SharedAbstractNode bvlshr(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
90 
92  TRITON_EXPORT SharedAbstractNode bvmul(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
93 
95  TRITON_EXPORT SharedAbstractNode bvnand(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
96 
98  TRITON_EXPORT SharedAbstractNode bvneg(const SharedAbstractNode& expr);
99 
101  TRITON_EXPORT SharedAbstractNode bvnor(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
102 
104  TRITON_EXPORT SharedAbstractNode bvnot(const SharedAbstractNode& expr);
105 
107  TRITON_EXPORT SharedAbstractNode bvor(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
108 
110  TRITON_EXPORT SharedAbstractNode bvrol(triton::uint32 rot, const SharedAbstractNode& expr);
111 
113  TRITON_EXPORT SharedAbstractNode bvrol(const SharedAbstractNode& rot, const SharedAbstractNode& expr);
114 
116  TRITON_EXPORT SharedAbstractNode bvror(triton::uint32 rot, const SharedAbstractNode& expr);
117 
119  TRITON_EXPORT SharedAbstractNode bvror(const SharedAbstractNode& rot, const SharedAbstractNode& expr);
120 
122  TRITON_EXPORT SharedAbstractNode bvsdiv(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
123 
125  TRITON_EXPORT SharedAbstractNode bvsge(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
126 
128  TRITON_EXPORT SharedAbstractNode bvsgt(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
129 
131  TRITON_EXPORT SharedAbstractNode bvshl(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
132 
134  TRITON_EXPORT SharedAbstractNode bvsle(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
135 
137  TRITON_EXPORT SharedAbstractNode bvslt(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
138 
140  TRITON_EXPORT SharedAbstractNode bvsmod(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
141 
143  TRITON_EXPORT SharedAbstractNode bvsrem(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
144 
146  TRITON_EXPORT SharedAbstractNode bvsub(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
147 
149  TRITON_EXPORT SharedAbstractNode bvtrue(void);
150 
152  TRITON_EXPORT SharedAbstractNode bvudiv(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
153 
155  TRITON_EXPORT SharedAbstractNode bvuge(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
156 
158  TRITON_EXPORT SharedAbstractNode bvugt(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
159 
161  TRITON_EXPORT SharedAbstractNode bvule(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
162 
164  TRITON_EXPORT SharedAbstractNode bvult(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
165 
167  TRITON_EXPORT SharedAbstractNode bvurem(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
168 
170  TRITON_EXPORT SharedAbstractNode bvxnor(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
171 
173  TRITON_EXPORT SharedAbstractNode bvxor(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
174 
176  template <typename T> SharedAbstractNode compound(const T& exprs) {
177  SharedAbstractNode node = std::make_shared<CompoundNode>(exprs, *this);
178  if (node == nullptr)
179  throw triton::exceptions::Ast("Node builders - Not enough memory");
180  node->init();
181  return node;
182  }
183 
185  TRITON_EXPORT SharedAbstractNode concat(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
186 
188  template <typename T> SharedAbstractNode concat(const T& exprs) {
189  SharedAbstractNode node = std::make_shared<ConcatNode>(exprs, *this);
190  if (node == nullptr)
191  throw triton::exceptions::Ast("Node builders - Not enough memory");
192  node->init();
193  return node;
194  }
195 
197  TRITON_EXPORT SharedAbstractNode decimal(triton::uint512 value);
198 
200  TRITON_EXPORT SharedAbstractNode declare(const SharedAbstractNode& var);
201 
203  TRITON_EXPORT SharedAbstractNode distinct(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
204 
206  TRITON_EXPORT SharedAbstractNode equal(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
207 
209  TRITON_EXPORT SharedAbstractNode extract(triton::uint32 high, triton::uint32 low, const SharedAbstractNode& expr);
210 
212  TRITON_EXPORT SharedAbstractNode iff(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
213 
215  TRITON_EXPORT SharedAbstractNode ite(const SharedAbstractNode& ifExpr, const SharedAbstractNode& thenExpr, const SharedAbstractNode& elseExpr);
216 
218  TRITON_EXPORT SharedAbstractNode land(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
219 
221  template <typename T> SharedAbstractNode land(const T& exprs) {
222  SharedAbstractNode node = std::make_shared<LandNode>(exprs, *this);
223  if (node == nullptr)
224  throw triton::exceptions::Ast("Node builders - Not enough memory");
225  node->init();
226  return node;
227  }
228 
230  TRITON_EXPORT SharedAbstractNode let(std::string alias, const SharedAbstractNode& expr2, const SharedAbstractNode& expr3);
231 
233  TRITON_EXPORT SharedAbstractNode lnot(const SharedAbstractNode& expr);
234 
236  TRITON_EXPORT SharedAbstractNode lor(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
237 
239  template <typename T> SharedAbstractNode lor(const T& exprs) {
240  SharedAbstractNode node = std::make_shared<LorNode>(exprs, *this);
241  if (node == nullptr)
242  throw triton::exceptions::Ast("Node builders - Not enough memory");
243  node->init();
244  return node;
245  }
246 
249 
251  TRITON_EXPORT SharedAbstractNode string(std::string value);
252 
254  TRITON_EXPORT SharedAbstractNode sx(triton::uint32 sizeExt, const SharedAbstractNode& expr);
255 
258 
260  TRITON_EXPORT SharedAbstractNode zx(triton::uint32 sizeExt, const SharedAbstractNode& expr);
261 
263  TRITON_EXPORT void initVariable(const std::string& name, const triton::uint512& value, const SharedAbstractNode& node);
264 
266  TRITON_EXPORT void updateVariable(const std::string& name, const triton::uint512& value);
267 
269  SharedAbstractNode getVariableNode(const std::string& name);
270 
272  TRITON_EXPORT const triton::uint512& getVariableValue(const std::string& varName) const;
273 
275  TRITON_EXPORT void setRepresentationMode(triton::uint32 mode);
276 
278  TRITON_EXPORT triton::uint32 getRepresentationMode(void) const;
279 
281  TRITON_EXPORT std::ostream& print(std::ostream& stream, AbstractNode* node);
282  };
283 
285  };
287 };
288 
289 #endif /* TRITON_AST_CONTEXT_H */
TRITON_EXPORT SharedAbstractNode assert_(const SharedAbstractNode &expr)
AST C++ API - assert node builder.
Definition: astContext.cpp:41
TRITON_EXPORT SharedAbstractNode iff(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - iff node builder.
Definition: astContext.cpp:424
TRITON_EXPORT SharedAbstractNode bvnor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvnor node builder.
Definition: astContext.cpp:131
TRITON_EXPORT void setRepresentationMode(triton::uint32 mode)
Sets the representation mode for this astContext.
Definition: astContext.cpp:593
TRITON_EXPORT SharedAbstractNode string(std::string value)
AST C++ API - string node builder.
Definition: astContext.cpp:495
TRITON_EXPORT SharedAbstractNode distinct(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - distinct node builder.
Definition: astContext.cpp:391
TRITON_EXPORT const triton::uint512 & getVariableValue(const std::string &varName) const
Gets a variable value from its name.
Definition: astContext.cpp:584
TRITON_EXPORT SharedAbstractNode land(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - land node builder.
Definition: astContext.cpp:442
Abstract node.
Definition: ast.hpp:63
TRITON_EXPORT SharedAbstractNode ite(const SharedAbstractNode &ifExpr, const SharedAbstractNode &thenExpr, const SharedAbstractNode &elseExpr)
AST C++ API - ite node builder.
Definition: astContext.cpp:433
TRITON_EXPORT SharedAbstractNode let(std::string alias, const SharedAbstractNode &expr2, const SharedAbstractNode &expr3)
AST C++ API - let node builder.
Definition: astContext.cpp:455
AST Context - Used as AST builder.
Definition: astContext.hpp:49
TRITON_EXPORT SharedAbstractNode declare(const SharedAbstractNode &var)
AST C++ API - declare node builder.
Definition: astContext.cpp:382
TRITON_EXPORT SharedAbstractNode bvsdiv(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsdiv node builder.
Definition: astContext.cpp:194
SharedAbstractNode compound(const T &exprs)
AST C++ API - compound node builder.
Definition: astContext.hpp:176
The Triton namespace.
Definition: api.cpp:225
TRITON_EXPORT SharedAbstractNode lnot(const SharedAbstractNode &expr)
AST C++ API - lnot node builder.
Definition: astContext.cpp:464
The exception class used by all AST nodes.
Definition: exceptions.hpp:341
TRITON_EXPORT SharedAbstractNode bvslt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvslt node builder.
Definition: astContext.cpp:239
TRITON_EXPORT SharedAbstractNode bvand(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvand node builder.
Definition: astContext.cpp:68
TRITON_EXPORT SharedAbstractNode bvsrem(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsrem node builder.
Definition: astContext.cpp:257
TRITON_EXPORT SharedAbstractNode reference(const triton::engines::symbolic::SharedSymbolicExpression &expr)
AST C++ API - reference node builder.
Definition: astContext.cpp:486
TRITON_EXPORT SharedAbstractNode bvurem(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvurem node builder.
Definition: astContext.cpp:329
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
Definition: ast.hpp:57
TRITON_EXPORT SharedAbstractNode bvuge(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvuge node builder.
Definition: astContext.cpp:293
TRITON_EXPORT SharedAbstractNode bvnot(const SharedAbstractNode &expr)
AST C++ API - bvnot node builder.
Definition: astContext.cpp:140
TRITON_EXPORT SharedAbstractNode extract(triton::uint32 high, triton::uint32 low, const SharedAbstractNode &expr)
AST C++ API - extract node builder.
Definition: astContext.cpp:409
TRITON_EXPORT SharedAbstractNode bvxnor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvxnor node builder.
Definition: astContext.cpp:338
TRITON_EXPORT SharedAbstractNode sx(triton::uint32 sizeExt, const SharedAbstractNode &expr)
AST C++ API - sx node builder.
Definition: astContext.cpp:504
TRITON_EXPORT ~AstContext()
Destructor.
Definition: astContext.cpp:29
TRITON_EXPORT SharedAbstractNode bvor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvor node builder.
Definition: astContext.cpp:149
TRITON_EXPORT SharedAbstractNode bvadd(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvadd node builder.
Definition: astContext.cpp:59
SharedAbstractNode land(const T &exprs)
AST C++ API - land node builder.
Definition: astContext.hpp:221
SharedAbstractNode concat(const T &exprs)
AST C++ API - concat node builder.
Definition: astContext.hpp:188
TRITON_EXPORT SharedAbstractNode bvashr(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvashr node builder.
Definition: astContext.cpp:77
TRITON_EXPORT void updateVariable(const std::string &name, const triton::uint512 &value)
Updates a variable value in this context.
Definition: astContext.cpp:568
TRITON_EXPORT SharedAbstractNode bv(triton::uint512 value, triton::uint32 size)
AST C++ API - bv node builder.
Definition: astContext.cpp:50
TRITON_EXPORT void initVariable(const std::string &name, const triton::uint512 &value, const SharedAbstractNode &node)
Initializes a variable in the context.
Definition: astContext.cpp:559
TRITON_EXPORT SharedAbstractNode bvmul(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvmul node builder.
Definition: astContext.cpp:104
TRITON_EXPORT SharedAbstractNode bvsmod(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsmod node builder.
Definition: astContext.cpp:248
TRITON_EXPORT SharedAbstractNode bvneg(const SharedAbstractNode &expr)
AST C++ API - bvneg node builder.
Definition: astContext.cpp:122
TRITON_EXPORT SharedAbstractNode concat(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - concat node builder.
Definition: astContext.cpp:360
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition: ast.hpp:38
TRITON_EXPORT AstContext()
Constructor.
Definition: astContext.cpp:19
TRITON_EXPORT SharedAbstractNode zx(triton::uint32 sizeExt, const SharedAbstractNode &expr)
AST C++ API - zx node builder.
Definition: astContext.cpp:544
TRITON_EXPORT SharedAbstractNode bvxor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvxor node builder.
Definition: astContext.cpp:347
std::uint32_t uint32
unisgned 32-bits
Definition: tritonTypes.hpp:31
SharedAbstractNode lor(const T &exprs)
AST C++ API - lor node builder.
Definition: astContext.hpp:239
TRITON_EXPORT SharedAbstractNode bvlshr(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvlshr node builder.
Definition: astContext.cpp:95
TRITON_EXPORT SharedAbstractNode bvnand(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvnand node builder.
Definition: astContext.cpp:113
TRITON_EXPORT SharedAbstractNode equal(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - equal node builder.
Definition: astContext.cpp:400
TRITON_EXPORT SharedAbstractNode bvsge(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsge node builder.
Definition: astContext.cpp:203
TRITON_EXPORT triton::uint32 getRepresentationMode(void) const
Gets the representations mode of this astContext.
Definition: astContext.cpp:598
TRITON_EXPORT SharedAbstractNode bvtrue(void)
AST C++ API - bvtrue node builder.
Definition: astContext.cpp:275
std::shared_ptr< triton::engines::symbolic::SymbolicVariable > SharedSymbolicVariable
Shared Symbolic variable.
Definition: ast.hpp:41
TRITON_EXPORT SharedAbstractNode bvrol(triton::uint32 rot, const SharedAbstractNode &expr)
AST C++ API - bvrol node builder.
Definition: astContext.cpp:158
TRITON_EXPORT SharedAbstractNode bvudiv(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvudiv node builder.
Definition: astContext.cpp:284
TRITON_EXPORT SharedAbstractNode bvult(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvult node builder.
Definition: astContext.cpp:320
TRITON_EXPORT SharedAbstractNode bvshl(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvshl node builder.
Definition: astContext.cpp:221
TRITON_EXPORT SharedAbstractNode bvule(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvule node builder.
Definition: astContext.cpp:311
TRITON_EXPORT SharedAbstractNode variable(const triton::engines::symbolic::SharedSymbolicVariable &symVar)
AST C++ API - variable node builder.
Definition: astContext.cpp:519
TRITON_EXPORT SharedAbstractNode bvugt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvugt node builder.
Definition: astContext.cpp:302
TRITON_EXPORT AstContext & operator=(const AstContext &other)
Operator.
Definition: astContext.cpp:34
TRITON_EXPORT SharedAbstractNode bvsgt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsgt node builder.
Definition: astContext.cpp:212
boost::multiprecision::uint512_t uint512
unsigned 512-bits
Definition: tritonTypes.hpp:43
TRITON_EXPORT std::ostream & print(std::ostream &stream, AbstractNode *node)
Print the given node with this context representation.
Definition: astContext.cpp:603
TRITON_EXPORT SharedAbstractNode bvsub(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsub node builder.
Definition: astContext.cpp:266
TRITON_EXPORT SharedAbstractNode bvror(triton::uint32 rot, const SharedAbstractNode &expr)
AST C++ API - bvror node builder.
Definition: astContext.cpp:176
TRITON_EXPORT SharedAbstractNode decimal(triton::uint512 value)
AST C++ API - decimal node builder.
Definition: astContext.cpp:373
TRITON_EXPORT SharedAbstractNode bvfalse(void)
AST C++ API - bvfalse node builder.
Definition: astContext.cpp:86
TRITON_EXPORT SharedAbstractNode bvsle(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsle node builder.
Definition: astContext.cpp:230
SharedAbstractNode getVariableNode(const std::string &name)
Gets a variable node from its name.
Definition: astContext.cpp:575
TRITON_EXPORT SharedAbstractNode lor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - lor node builder.
Definition: astContext.cpp:473