libTriton  version 0.7 build 1409
astContext.cpp
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 #include <memory>
9 
10 #include <triton/ast.hpp>
11 #include <triton/astContext.hpp>
12 #include <triton/exceptions.hpp>
15 
16 
17 
18 namespace triton {
19  namespace ast {
20 
22  : modes(modes) {
23  }
24 
25 
27  : std::enable_shared_from_this<AstContext>(other),
28  modes(other.modes),
29  astRepresentation(other.astRepresentation),
30  valueMapping(other.valueMapping) {
31  }
32 
33 
35  this->valueMapping.clear();
36  }
37 
38 
40  std::enable_shared_from_this<AstContext>::operator=(other);
41  this->astRepresentation = other.astRepresentation;
42  this->modes = other.modes;
43  this->valueMapping = other.valueMapping;
44  return *this;
45  }
46 
47 
49  SharedAbstractNode node = std::make_shared<AssertNode>(expr);
50  if (node == nullptr)
51  throw triton::exceptions::Ast("Node builders - Not enough memory");
52  node->init();
53  return node;
54  }
55 
56 
58  SharedAbstractNode node = std::make_shared<BvNode>(value, size, this->shared_from_this());
59  if (node == nullptr)
60  throw triton::exceptions::Ast("Node builders - Not enough memory");
61  node->init();
62  return node;
63  }
64 
65 
67  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
68  /* Optimization: 0 + A = A */
69  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
70  return expr2;
71 
72  /* Optimization: A + 0 = A */
73  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
74  return expr1;
75  }
76 
77  SharedAbstractNode node = std::make_shared<BvaddNode>(expr1, expr2);
78  if (node == nullptr)
79  throw triton::exceptions::Ast("Node builders - Not enough memory");
80  node->init();
81 
82  return node;
83  }
84 
85 
87  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
88  /* Optimization: 0 & A = 0 */
89  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
90  return this->bv(0, expr1->getBitvectorSize());
91 
92  /* Optimization: A & 0 = 0 */
93  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
94  return this->bv(0, expr1->getBitvectorSize());
95 
96  /* Optimization: A & -1 = A */
97  if (!expr2->isSymbolized() && expr2->evaluate() == expr2->getBitvectorMask())
98  return expr1;
99 
100  /* Optimization: -1 & A = A */
101  if (!expr1->isSymbolized() && expr1->evaluate() == expr1->getBitvectorMask())
102  return expr2;
103 
104  /* Optimization: A & A = A */
105  if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
106  return expr1;
107  }
108 
109  SharedAbstractNode node = std::make_shared<BvandNode>(expr1, expr2);
110  if (node == nullptr)
111  throw triton::exceptions::Ast("Node builders - Not enough memory");
112  node->init();
113 
114  return node;
115  }
116 
117 
119  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
120  /* Optimization: 0 >> A = 0 */
121  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
122  return this->bv(0, expr1->getBitvectorSize());
123 
124  /* Optimization: A >> 0 = A */
125  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
126  return expr1;
127  }
128 
129  SharedAbstractNode node = std::make_shared<BvashrNode>(expr1, expr2);
130  if (node == nullptr)
131  throw triton::exceptions::Ast("Node builders - Not enough memory");
132  node->init();
133 
134  return node;
135  }
136 
137 
139  SharedAbstractNode node = std::make_shared<BvNode>(0, 1, this->shared_from_this());
140  if (node == nullptr)
141  throw triton::exceptions::Ast("Node builders - Not enough memory");
142  node->init();
143  return node;
144  }
145 
146 
148  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
149  /* Optimization: 0 >> A = 0 */
150  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
151  return this->bv(0, expr1->getBitvectorSize());
152 
153  /* Optimization: A >> 0 = A */
154  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
155  return expr1;
156 
157  /* Optimization: A >> B>=size(A) = 0 */
158  if (!expr2->isSymbolized() && expr2->evaluate() >= expr1->getBitvectorSize())
159  return this->bv(0, expr1->getBitvectorSize());
160  }
161 
162  SharedAbstractNode node = std::make_shared<BvlshrNode>(expr1, expr2);
163  if (node == nullptr)
164  throw triton::exceptions::Ast("Node builders - Not enough memory");
165  node->init();
166 
167  return node;
168  }
169 
170 
172  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
173  /* Optimization: 0 * A = 0 */
174  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
175  return this->bv(0, expr1->getBitvectorSize());
176 
177  /* Optimization: A * 0 = 0 */
178  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
179  return this->bv(0, expr1->getBitvectorSize());
180  }
181 
182  SharedAbstractNode node = std::make_shared<BvmulNode>(expr1, expr2);
183  if (node == nullptr)
184  throw triton::exceptions::Ast("Node builders - Not enough memory");
185  node->init();
186 
187  return node;
188  }
189 
190 
192  SharedAbstractNode node = std::make_shared<BvnandNode>(expr1, expr2);
193  if (node == nullptr)
194  throw triton::exceptions::Ast("Node builders - Not enough memory");
195  node->init();
196  return node;
197  }
198 
199 
201  SharedAbstractNode node = std::make_shared<BvnegNode>(expr);
202  if (node == nullptr)
203  throw triton::exceptions::Ast("Node builders - Not enough memory");
204  node->init();
205  return node;
206  }
207 
208 
210  SharedAbstractNode node = std::make_shared<BvnorNode>(expr1, expr2);
211  if (node == nullptr)
212  throw triton::exceptions::Ast("Node builders - Not enough memory");
213  node->init();
214  return node;
215  }
216 
217 
219  SharedAbstractNode node = std::make_shared<BvnotNode>(expr);
220  if (node == nullptr)
221  throw triton::exceptions::Ast("Node builders - Not enough memory");
222  node->init();
223  return node;
224  }
225 
226 
228  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
229  /* Optimization: 0 | A = A */
230  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
231  return expr2;
232 
233  /* Optimization: A | 0 = A */
234  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
235  return expr1;
236 
237  /* Optimization: -1 | A = -1 */
238  if (!expr1->isSymbolized() && expr1->evaluate() == expr1->getBitvectorMask())
239  return this->bv(expr1->getBitvectorMask(), expr1->getBitvectorSize());
240 
241  /* Optimization: A | -1 = -1 */
242  if (!expr2->isSymbolized() && expr2->evaluate() == expr2->getBitvectorMask())
243  return this->bv(expr2->getBitvectorMask(), expr2->getBitvectorSize());
244 
245  /* Optimization: A | A = A */
246  if (expr1->equalTo(expr2))
247  return expr1;
248  }
249 
250  SharedAbstractNode node = std::make_shared<BvorNode>(expr1, expr2);
251  if (node == nullptr)
252  throw triton::exceptions::Ast("Node builders - Not enough memory");
253  node->init();
254 
255  return node;
256  }
257 
258 
260  SharedAbstractNode node = std::make_shared<BvrolNode>(expr, rot);
261  if (node == nullptr)
262  throw triton::exceptions::Ast("Node builders - Not enough memory");
263  node->init();
264  return node;
265  }
266 
267 
269  /*
270  * If the mode SYMBOLIZE_INDEX_ROTATION we apply a AST transformation
271  * in order to make index rotation symbolic. Note that this mode increases the
272  * complexity of solving.
273  *
274  * bvrol(rot, expr) = ((expr << (rot % size)) | (expr >> (size - (rot % size))))
275  **/
276  if (this->modes->isModeEnabled(triton::modes::SYMBOLIZE_INDEX_ROTATION)) {
277  auto size = expr->getBitvectorSize();
278  auto bvsize = this->bv(size, size);
279  auto node = this->bvor(
280  this->bvshl(expr, this->bvsmod(rot, bvsize)),
281  this->bvlshr(expr, this->bvsub(bvsize, this->bvsmod(rot, bvsize)))
282  );
283  return node;
284  }
285 
286  /* Otherwise, we concretize the index rotation */
287  SharedAbstractNode node = std::make_shared<BvrolNode>(expr, this->integer(rot->evaluate()));
288  if (node == nullptr)
289  throw triton::exceptions::Ast("Node builders - Not enough memory");
290  node->init();
291 
292  return node;
293  }
294 
295 
297  SharedAbstractNode node = std::make_shared<BvrorNode>(expr, rot);
298  if (node == nullptr)
299  throw triton::exceptions::Ast("Node builders - Not enough memory");
300  node->init();
301  return node;
302  }
303 
304 
306  /*
307  * If the mode SYMBOLIZE_INDEX_ROTATION we apply a AST transformation
308  * in order to make index rotation symbolic. Note that this mode increases the
309  * complexity of solving.
310  *
311  * bvror(rot, expr) = ((value >> (rot % size)) | (value << (size - (rot % size))))
312  **/
313  if (this->modes->isModeEnabled(triton::modes::SYMBOLIZE_INDEX_ROTATION)) {
314  auto size = expr->getBitvectorSize();
315  auto bvsize = this->bv(size, size);
316  auto node = this->bvor(
317  this->bvlshr(expr, this->bvsmod(rot, bvsize)),
318  this->bvshl(expr, this->bvsub(bvsize, this->bvsmod(rot, bvsize)))
319  );
320  return node;
321  }
322 
323  /* Otherwise, we concretize the index rotation */
324  SharedAbstractNode node = std::make_shared<BvrorNode>(expr, this->integer(rot->evaluate()));
325  if (node == nullptr)
326  throw triton::exceptions::Ast("Node builders - Not enough memory");
327  node->init();
328 
329  return node;
330  }
331 
332 
334  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
335  /* Optimization: A / 1 = A */
336  if (!expr2->isSymbolized() && expr2->evaluate() == 1)
337  return expr1;
338  }
339 
340  SharedAbstractNode node = std::make_shared<BvsdivNode>(expr1, expr2);
341  if (node == nullptr)
342  throw triton::exceptions::Ast("Node builders - Not enough memory");
343  node->init();
344 
345  return node;
346  }
347 
348 
350  SharedAbstractNode node = std::make_shared<BvsgeNode>(expr1, expr2);
351  if (node == nullptr)
352  throw triton::exceptions::Ast("Node builders - Not enough memory");
353  node->init();
354  return node;
355  }
356 
357 
359  SharedAbstractNode node = std::make_shared<BvsgtNode>(expr1, expr2);
360  if (node == nullptr)
361  throw triton::exceptions::Ast("Node builders - Not enough memory");
362  node->init();
363  return node;
364  }
365 
366 
368  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
369  /* Optimization: 0 << A = 0 */
370  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
371  return this->bv(0, expr1->getBitvectorSize());
372 
373  /* Optimization: A << 0 = A */
374  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
375  return expr1;
376 
377  /* Optimization: A << B>=size(A) = 0 */
378  if (!expr2->isSymbolized() && expr2->evaluate() >= expr1->getBitvectorSize())
379  return this->bv(0, expr1->getBitvectorSize());
380  }
381 
382  SharedAbstractNode node = std::make_shared<BvshlNode>(expr1, expr2);
383  if (node == nullptr)
384  throw triton::exceptions::Ast("Node builders - Not enough memory");
385  node->init();
386 
387  return node;
388  }
389 
390 
392  SharedAbstractNode node = std::make_shared<BvsleNode>(expr1, expr2);
393  if (node == nullptr)
394  throw triton::exceptions::Ast("Node builders - Not enough memory");
395  node->init();
396  return node;
397  }
398 
399 
401  SharedAbstractNode node = std::make_shared<BvsltNode>(expr1, expr2);
402  if (node == nullptr)
403  throw triton::exceptions::Ast("Node builders - Not enough memory");
404  node->init();
405  return node;
406  }
407 
408 
410  SharedAbstractNode node = std::make_shared<BvsmodNode>(expr1, expr2);
411  if (node == nullptr)
412  throw triton::exceptions::Ast("Node builders - Not enough memory");
413  node->init();
414  return node;
415  }
416 
417 
419  SharedAbstractNode node = std::make_shared<BvsremNode>(expr1, expr2);
420  if (node == nullptr)
421  throw triton::exceptions::Ast("Node builders - Not enough memory");
422  node->init();
423  return node;
424  }
425 
426 
428  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
429  /* Optimization: A - 0 = A */
430  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
431  return expr1;
432 
433  /* Optimization: 0 - A = -A */
434  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
435  return this->bvneg(expr2);
436 
437  /* Optimization: A - A = 0 */
438  if (expr1->equalTo(expr2))
439  return this->bv(0, expr1->getBitvectorSize());
440  }
441 
442  SharedAbstractNode node = std::make_shared<BvsubNode>(expr1, expr2);
443  if (node == nullptr)
444  throw triton::exceptions::Ast("Node builders - Not enough memory");
445  node->init();
446 
447  return node;
448  }
449 
450 
452  SharedAbstractNode node = std::make_shared<BvNode>(1, 1, this->shared_from_this());
453  if (node == nullptr)
454  throw triton::exceptions::Ast("Node builders - Not enough memory");
455  node->init();
456  return node;
457  }
458 
459 
461  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
462  /* Optimization: A / 1 = A */
463  if (!expr2->isSymbolized() && expr2->evaluate() == 1)
464  return expr1;
465  }
466 
467  SharedAbstractNode node = std::make_shared<BvudivNode>(expr1, expr2);
468  if (node == nullptr)
469  throw triton::exceptions::Ast("Node builders - Not enough memory");
470  node->init();
471 
472  return node;
473  }
474 
475 
477  SharedAbstractNode node = std::make_shared<BvugeNode>(expr1, expr2);
478  if (node == nullptr)
479  throw triton::exceptions::Ast("Node builders - Not enough memory");
480  node->init();
481  return node;
482  }
483 
484 
486  SharedAbstractNode node = std::make_shared<BvugtNode>(expr1, expr2);
487  if (node == nullptr)
488  throw triton::exceptions::Ast("Node builders - Not enough memory");
489  node->init();
490  return node;
491  }
492 
493 
495  SharedAbstractNode node = std::make_shared<BvuleNode>(expr1, expr2);
496  if (node == nullptr)
497  throw triton::exceptions::Ast("Node builders - Not enough memory");
498  node->init();
499  return node;
500  }
501 
502 
504  SharedAbstractNode node = std::make_shared<BvultNode>(expr1, expr2);
505  if (node == nullptr)
506  throw triton::exceptions::Ast("Node builders - Not enough memory");
507  node->init();
508  return node;
509  }
510 
511 
513  SharedAbstractNode node = std::make_shared<BvuremNode>(expr1, expr2);
514  if (node == nullptr)
515  throw triton::exceptions::Ast("Node builders - Not enough memory");
516  node->init();
517  return node;
518  }
519 
520 
522  SharedAbstractNode node = std::make_shared<BvxnorNode>(expr1, expr2);
523  if (node == nullptr)
524  throw triton::exceptions::Ast("Node builders - Not enough memory");
525  node->init();
526  return node;
527  }
528 
529 
531  if (this->modes->isModeEnabled(triton::modes::AST_OPTIMIZATIONS)) {
532  /* Optimization: A ^ 0 = A */
533  if (!expr2->isSymbolized() && expr2->evaluate() == 0)
534  return expr1;
535 
536  /* Optimization: 0 ^ A = A */
537  if (!expr1->isSymbolized() && expr1->evaluate() == 0)
538  return expr2;
539 
540  /* Optimization: A ^ A = 0 */
541  if (expr1->equalTo(expr2))
542  return this->bv(0, expr1->getBitvectorSize());
543  }
544 
545  SharedAbstractNode node = std::make_shared<BvxorNode>(expr1, expr2);
546  if (node == nullptr)
547  throw triton::exceptions::Ast("Node builders - Not enough memory");
548  node->init();
549 
550  return node;
551  }
552 
553 
554  template TRITON_EXPORT SharedAbstractNode AstContext::compound(const std::vector<SharedAbstractNode>& exprs);
555  template TRITON_EXPORT SharedAbstractNode AstContext::compound(const std::list<SharedAbstractNode>& exprs);
556 
557 
559  SharedAbstractNode node = std::make_shared<ConcatNode>(expr1, expr2);
560  if (node == nullptr)
561  throw triton::exceptions::Ast("Node builders - Not enough memory");
562  node->init();
563  return node;
564  }
565 
566 
567  template TRITON_EXPORT SharedAbstractNode AstContext::concat(const std::vector<SharedAbstractNode>& exprs);
568  template TRITON_EXPORT SharedAbstractNode AstContext::concat(const std::list<SharedAbstractNode>& exprs);
569 
570 
572  SharedAbstractNode node = std::make_shared<DeclareNode>(var);
573  if (node == nullptr)
574  throw triton::exceptions::Ast("Node builders - Not enough memory");
575  node->init();
576  return node;
577  }
578 
579 
581  SharedAbstractNode node = std::make_shared<DistinctNode>(expr1, expr2);
582  if (node == nullptr)
583  throw triton::exceptions::Ast("Node builders - Not enough memory");
584  node->init();
585  return node;
586  }
587 
588 
590  SharedAbstractNode node = std::make_shared<EqualNode>(expr1, expr2);
591  if (node == nullptr)
592  throw triton::exceptions::Ast("Node builders - Not enough memory");
593  node->init();
594  return node;
595  }
596 
597 
599  /* Optimization: If we extract the full size of expr, just return expr */
600  if (low == 0 && (high + 1) == expr->getBitvectorSize())
601  return expr;
602 
603  SharedAbstractNode node = std::make_shared<ExtractNode>(high, low, expr);
604 
605  if (node == nullptr)
606  throw triton::exceptions::Ast("Node builders - Not enough memory");
607 
608  node->init();
609  return node;
610  }
611 
612 
614  SharedAbstractNode node = std::make_shared<IffNode>(expr1, expr2);
615  if (node == nullptr)
616  throw triton::exceptions::Ast("Node builders - Not enough memory");
617  node->init();
618  return node;
619  }
620 
621 
623  SharedAbstractNode node = std::make_shared<IntegerNode>(value, this->shared_from_this());
624  if (node == nullptr)
625  throw triton::exceptions::Ast("Node builders - Not enough memory");
626  node->init();
627  return node;
628  }
629 
630 
632  SharedAbstractNode node = std::make_shared<IteNode>(ifExpr, thenExpr, elseExpr);
633  if (node == nullptr)
634  throw triton::exceptions::Ast("Node builders - Not enough memory");
635  node->init();
636  return node;
637  }
638 
639 
641  SharedAbstractNode node = std::make_shared<LandNode>(expr1, expr2);
642  if (node == nullptr)
643  throw triton::exceptions::Ast("Node builders - Not enough memory");
644  node->init();
645  return node;
646  }
647 
648 
649  template TRITON_EXPORT SharedAbstractNode AstContext::land(const std::vector<SharedAbstractNode>& exprs);
650  template TRITON_EXPORT SharedAbstractNode AstContext::land(const std::list<SharedAbstractNode>& exprs);
651 
652 
653  SharedAbstractNode AstContext::let(std::string alias, const SharedAbstractNode& expr2, const SharedAbstractNode& expr3) {
654  SharedAbstractNode node = std::make_shared<LetNode>(alias, expr2, expr3);
655  if (node == nullptr)
656  throw triton::exceptions::Ast("Node builders - Not enough memory");
657  node->init();
658  return node;
659  }
660 
661 
663  SharedAbstractNode node = std::make_shared<LnotNode>(expr);
664  if (node == nullptr)
665  throw triton::exceptions::Ast("Node builders - Not enough memory");
666  node->init();
667  return node;
668  }
669 
670 
672  SharedAbstractNode node = std::make_shared<LorNode>(expr1, expr2);
673  if (node == nullptr)
674  throw triton::exceptions::Ast("Node builders - Not enough memory");
675  node->init();
676  return node;
677  }
678 
679 
680  template TRITON_EXPORT SharedAbstractNode AstContext::lor(const std::vector<SharedAbstractNode>& exprs);
681  template TRITON_EXPORT SharedAbstractNode AstContext::lor(const std::list<SharedAbstractNode>& exprs);
682 
683 
685  SharedAbstractNode node = std::make_shared<ReferenceNode>(expr);
686  if (node == nullptr)
687  throw triton::exceptions::Ast("Node builders - Not enough memory");
688  node->init();
689  return node;
690  }
691 
692 
694  SharedAbstractNode node = std::make_shared<StringNode>(value, this->shared_from_this());
695  if (node == nullptr)
696  throw triton::exceptions::Ast("Node builders - Not enough memory");
697  node->init();
698  return node;
699  }
700 
701 
703  /* Optimization: Just return expr if the extend is zero */
704  if (sizeExt == 0)
705  return expr;
706 
707  SharedAbstractNode node = std::make_shared<SxNode>(sizeExt, expr);
708 
709  if (node == nullptr)
710  throw triton::exceptions::Ast("Node builders - Not enough memory");
711 
712  node->init();
713  return node;
714  }
715 
716 
718  // try to get node from variable pool
719  auto it = this->valueMapping.find(symVar->getName());
720  if (it != this->valueMapping.end()) {
721  auto& node = it->second.first;
722 
723  if (node->getBitvectorSize() != symVar->getSize())
724  throw triton::exceptions::Ast("Node builders - Missmatching variable size.");
725 
726  // This node already exist, just return it
727  node->init();
728  return node;
729  }
730  else {
731  // if not found, create a new variable node
732  SharedAbstractNode node = std::make_shared<VariableNode>(symVar, this->shared_from_this());
733  this->initVariable(symVar->getName(), 0, node);
734  if (node == nullptr)
735  throw triton::exceptions::Ast("Node builders - Not enough memory");
736  node->init();
737  return node;
738  }
739  }
740 
741 
743  /* Optimization: Just return expr if the extend is zero */
744  if (sizeExt == 0)
745  return expr;
746 
747  SharedAbstractNode node = std::make_shared<ZxNode>(sizeExt, expr);
748 
749  if (node == nullptr)
750  throw triton::exceptions::Ast("Node builders - Not enough memory");
751 
752  node->init();
753  return node;
754  }
755 
756 
757  void AstContext::initVariable(const std::string& name, const triton::uint512& value, const SharedAbstractNode& node) {
758  auto it = this->valueMapping.find(name);
759  if (it == this->valueMapping.end())
760  this->valueMapping.insert(std::make_pair(name, std::make_pair(node, value)));
761  else
762  throw triton::exceptions::Ast("Ast variable already initialized");
763  }
764 
765 
766  void AstContext::updateVariable(const std::string& name, const triton::uint512& value) {
767  auto& kv = this->valueMapping.at(name);
768  kv.second = value;
769  kv.first->init();
770  }
771 
772 
774  auto it = this->valueMapping.find(name);
775  if (it == this->valueMapping.end())
776  return nullptr;
777  else
778  return it->second.first;
779  }
780 
781 
782  const triton::uint512& AstContext::getVariableValue(const std::string& varName) const {
783  try {
784  return this->valueMapping.at(varName).second;
785  } catch (const std::out_of_range&) {
786  throw triton::exceptions::Ast("AstContext::getVariableValue(): Variable doesn't exists");
787  }
788  }
789 
790 
792  this->astRepresentation.setMode(mode);
793  }
794 
795 
797  return this->astRepresentation.getMode();
798  }
799 
800 
801  std::ostream& AstContext::print(std::ostream& stream, AbstractNode* node) {
802  return this->astRepresentation.print(stream, node);
803  }
804 
805  }; /* ast namespace */
806 }; /* triton namespace */
TRITON_EXPORT SharedAbstractNode assert_(const SharedAbstractNode &expr)
AST C++ API - assert node builder.
Definition: astContext.cpp:48
TRITON_EXPORT SharedAbstractNode iff(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - iff node builder.
Definition: astContext.cpp:613
TRITON_EXPORT SharedAbstractNode bvnor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvnor node builder.
Definition: astContext.cpp:209
TRITON_EXPORT void setRepresentationMode(triton::uint32 mode)
Sets the representation mode for this astContext.
Definition: astContext.cpp:791
TRITON_EXPORT SharedAbstractNode string(std::string value)
AST C++ API - string node builder.
Definition: astContext.cpp:693
TRITON_EXPORT SharedAbstractNode distinct(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - distinct node builder.
Definition: astContext.cpp:580
TRITON_EXPORT const triton::uint512 & getVariableValue(const std::string &varName) const
Gets a variable value from its name.
Definition: astContext.cpp:782
TRITON_EXPORT SharedAbstractNode land(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - land node builder.
Definition: astContext.cpp:640
Abstract node.
Definition: ast.hpp:67
TRITON_EXPORT SharedAbstractNode ite(const SharedAbstractNode &ifExpr, const SharedAbstractNode &thenExpr, const SharedAbstractNode &elseExpr)
AST C++ API - ite node builder.
Definition: astContext.cpp:631
TRITON_EXPORT SharedAbstractNode let(std::string alias, const SharedAbstractNode &expr2, const SharedAbstractNode &expr3)
AST C++ API - let node builder.
Definition: astContext.cpp:653
AST Context - Used as AST builder.
Definition: astContext.hpp:51
TRITON_EXPORT SharedAbstractNode bvrol(const SharedAbstractNode &expr, triton::uint32 rot)
AST C++ API - bvrol node builder.
Definition: astContext.cpp:259
TRITON_EXPORT SharedAbstractNode declare(const SharedAbstractNode &var)
AST C++ API - declare node builder.
Definition: astContext.cpp:571
TRITON_EXPORT SharedAbstractNode bvsdiv(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsdiv node builder.
Definition: astContext.cpp:333
SharedAbstractNode compound(const T &exprs)
AST C++ API - compound node builder.
Definition: astContext.hpp:181
The Triton namespace.
Definition: api.cpp:226
TRITON_EXPORT SharedAbstractNode lnot(const SharedAbstractNode &expr)
AST C++ API - lnot node builder.
Definition: astContext.cpp:662
TRITON_EXPORT SharedAbstractNode integer(triton::uint512 value)
AST C++ API - integer node builder.
Definition: astContext.cpp:622
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:400
TRITON_EXPORT SharedAbstractNode bvand(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvand node builder.
Definition: astContext.cpp:86
TRITON_EXPORT SharedAbstractNode bvsrem(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsrem node builder.
Definition: astContext.cpp:418
TRITON_EXPORT SharedAbstractNode reference(const triton::engines::symbolic::SharedSymbolicExpression &expr)
AST C++ API - reference node builder.
Definition: astContext.cpp:684
TRITON_EXPORT SharedAbstractNode bvurem(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvurem node builder.
Definition: astContext.cpp:512
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
Definition: ast.hpp:58
TRITON_EXPORT SharedAbstractNode bvuge(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvuge node builder.
Definition: astContext.cpp:476
TRITON_EXPORT SharedAbstractNode bvnot(const SharedAbstractNode &expr)
AST C++ API - bvnot node builder.
Definition: astContext.cpp:218
TRITON_EXPORT SharedAbstractNode extract(triton::uint32 high, triton::uint32 low, const SharedAbstractNode &expr)
AST C++ API - extract node builder.
Definition: astContext.cpp:598
TRITON_EXPORT SharedAbstractNode bvxnor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvxnor node builder.
Definition: astContext.cpp:521
TRITON_EXPORT SharedAbstractNode sx(triton::uint32 sizeExt, const SharedAbstractNode &expr)
AST C++ API - sx node builder.
Definition: astContext.cpp:702
TRITON_EXPORT ~AstContext()
Destructor.
Definition: astContext.cpp:34
TRITON_EXPORT SharedAbstractNode bvor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvor node builder.
Definition: astContext.cpp:227
TRITON_EXPORT SharedAbstractNode bvadd(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvadd node builder.
Definition: astContext.cpp:66
[AST] Classical arithmetic optimisations to reduce the depth of the trees.
Definition: modesEnums.hpp:31
std::shared_ptr< triton::modes::Modes > SharedModes
Shared Modes.
Definition: modes.hpp:63
TRITON_EXPORT SharedAbstractNode bvror(const SharedAbstractNode &expr, triton::uint32 rot)
AST C++ API - bvror node builder.
Definition: astContext.cpp:296
TRITON_EXPORT SharedAbstractNode bvashr(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvashr node builder.
Definition: astContext.cpp:118
TRITON_EXPORT void updateVariable(const std::string &name, const triton::uint512 &value)
Updates a variable value in this context.
Definition: astContext.cpp:766
TRITON_EXPORT SharedAbstractNode bv(triton::uint512 value, triton::uint32 size)
AST C++ API - bv node builder.
Definition: astContext.cpp:57
TRITON_EXPORT void initVariable(const std::string &name, const triton::uint512 &value, const SharedAbstractNode &node)
Initializes a variable in the context.
Definition: astContext.cpp:757
TRITON_EXPORT SharedAbstractNode bvmul(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvmul node builder.
Definition: astContext.cpp:171
TRITON_EXPORT SharedAbstractNode bvsmod(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsmod node builder.
Definition: astContext.cpp:409
TRITON_EXPORT SharedAbstractNode bvneg(const SharedAbstractNode &expr)
AST C++ API - bvneg node builder.
Definition: astContext.cpp:200
TRITON_EXPORT SharedAbstractNode concat(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - concat node builder.
Definition: astContext.cpp:558
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition: ast.hpp:39
TRITON_EXPORT SharedAbstractNode zx(triton::uint32 sizeExt, const SharedAbstractNode &expr)
AST C++ API - zx node builder.
Definition: astContext.cpp:742
TRITON_EXPORT SharedAbstractNode bvxor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvxor node builder.
Definition: astContext.cpp:530
std::uint32_t uint32
unisgned 32-bits
Definition: tritonTypes.hpp:31
TRITON_EXPORT SharedAbstractNode bvlshr(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvlshr node builder.
Definition: astContext.cpp:147
TRITON_EXPORT SharedAbstractNode bvnand(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvnand node builder.
Definition: astContext.cpp:191
TRITON_EXPORT SharedAbstractNode equal(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - equal node builder.
Definition: astContext.cpp:589
TRITON_EXPORT void setMode(triton::uint32 mode)
Sets the representation mode.
[symbolic] Symbolize index rotation for bvrol and bvror (see #751). This mode increases the complexit...
Definition: modesEnums.hpp:36
TRITON_EXPORT SharedAbstractNode bvsge(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsge node builder.
Definition: astContext.cpp:349
TRITON_EXPORT std::ostream & print(std::ostream &stream, AbstractNode *node)
Displays the node according to the representation mode.
TRITON_EXPORT AstContext(const triton::modes::SharedModes &modes)
Constructor.
Definition: astContext.cpp:21
TRITON_EXPORT triton::uint32 getRepresentationMode(void) const
Gets the representations mode of this astContext.
Definition: astContext.cpp:796
TRITON_EXPORT SharedAbstractNode bvtrue(void)
AST C++ API - bvtrue node builder.
Definition: astContext.cpp:451
std::shared_ptr< triton::engines::symbolic::SymbolicVariable > SharedSymbolicVariable
Shared Symbolic variable.
Definition: ast.hpp:42
TRITON_EXPORT SharedAbstractNode bvudiv(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvudiv node builder.
Definition: astContext.cpp:460
TRITON_EXPORT SharedAbstractNode bvult(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvult node builder.
Definition: astContext.cpp:503
TRITON_EXPORT SharedAbstractNode bvshl(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvshl node builder.
Definition: astContext.cpp:367
TRITON_EXPORT SharedAbstractNode bvule(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvule node builder.
Definition: astContext.cpp:494
TRITON_EXPORT SharedAbstractNode variable(const triton::engines::symbolic::SharedSymbolicVariable &symVar)
AST C++ API - variable node builder.
Definition: astContext.cpp:717
TRITON_EXPORT SharedAbstractNode bvugt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvugt node builder.
Definition: astContext.cpp:485
TRITON_EXPORT AstContext & operator=(const AstContext &other)
Operator.
Definition: astContext.cpp:39
TRITON_EXPORT SharedAbstractNode bvsgt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsgt node builder.
Definition: astContext.cpp:358
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:801
TRITON_EXPORT SharedAbstractNode bvsub(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsub node builder.
Definition: astContext.cpp:427
TRITON_EXPORT SharedAbstractNode bvfalse(void)
AST C++ API - bvfalse node builder.
Definition: astContext.cpp:138
TRITON_EXPORT SharedAbstractNode bvsle(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsle node builder.
Definition: astContext.cpp:391
SharedAbstractNode getVariableNode(const std::string &name)
Gets a variable node from its name.
Definition: astContext.cpp:773
TRITON_EXPORT triton::uint32 getMode(void) const
Returns the representation mode.
TRITON_EXPORT SharedAbstractNode lor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - lor node builder.
Definition: astContext.cpp:671