libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
ast.hpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
8#ifndef TRITON_AST_H
9#define TRITON_AST_H
10
11#include <deque>
12#include <memory>
13#include <ostream>
14#include <stdexcept>
15#include <string>
16#include <unordered_map>
17#include <unordered_set>
18#include <vector>
19
20#include <triton/astEnums.hpp>
21#include <triton/coreUtils.hpp>
22#include <triton/cpuSize.hpp>
23#include <triton/dllexport.hpp>
24#include <triton/exceptions.hpp>
26
27
28
30namespace triton {
36 /* Forward declarations */
37 namespace engines {
38 namespace symbolic {
39 class SymbolicExpression;
40 using SharedSymbolicExpression = std::shared_ptr<triton::engines::symbolic::SymbolicExpression>;
41
42 class SymbolicVariable;
43 using SharedSymbolicVariable = std::shared_ptr<triton::engines::symbolic::SymbolicVariable>;
44 };
45 };
46
48 namespace ast {
55 class AstContext;
56 class AbstractNode;
57
59 using SharedAbstractNode = std::shared_ptr<triton::ast::AbstractNode>;
60
62 using WeakAbstractNode = std::weak_ptr<triton::ast::AbstractNode>;
63
65 using SharedAstContext = std::shared_ptr<triton::ast::AstContext>;
66
68 class AbstractNode : public std::enable_shared_from_this<AbstractNode> {
69 private:
71 virtual void initHash(void) = 0;
72
73 protected:
76
79
81 std::vector<SharedAbstractNode> children;
82
83 // This structure counter the number of use of a given parent as a node may have
84 // multiple time the same parent: eg. xor rax rax
85 std::unordered_map<AbstractNode*, std::pair<triton::uint32, WeakAbstractNode>> parents;
86
89
92
95
98
101
103 bool array;
104
107
108 public:
111
113 TRITON_EXPORT virtual ~AbstractNode();
114
116 TRITON_EXPORT SharedAstContext getContext(void) const;
117
119 TRITON_EXPORT triton::ast::ast_e getType(void) const;
120
122 TRITON_EXPORT triton::uint32 getBitvectorSize(void) const;
123
125 TRITON_EXPORT triton::uint512 getBitvectorMask(void) const;
126
128 TRITON_EXPORT bool isArray(void) const;
129
131 TRITON_EXPORT bool isSigned(void) const;
132
134 TRITON_EXPORT bool isSymbolized(void) const;
135
137 TRITON_EXPORT bool isLogical(void) const;
138
140 TRITON_EXPORT bool hasSameConcreteValueAndTypeAs(const SharedAbstractNode& other) const;
141
143 TRITON_EXPORT bool canReplaceNodeWithoutUpdate(const SharedAbstractNode& other) const;
144
146 TRITON_EXPORT bool equalTo(const SharedAbstractNode& other) const;
147
149 TRITON_EXPORT triton::uint32 getLevel(void) const;
150
152 TRITON_EXPORT triton::uint512 getHash(void) const;
153
155 TRITON_EXPORT triton::uint512 evaluate(void) const;
156
158 void initParents(void);
159
161 TRITON_EXPORT std::vector<SharedAbstractNode>& getChildren(void);
162
164 TRITON_EXPORT std::vector<SharedAbstractNode> getParents(void);
165
167 TRITON_EXPORT void removeParent(AbstractNode* p);
168
170 TRITON_EXPORT void setParent(AbstractNode* p);
171
173 TRITON_EXPORT void setParent(std::unordered_set<AbstractNode*>& p);
174
176 TRITON_EXPORT void setBitvectorSize(triton::uint32 size);
177
179 TRITON_EXPORT void addChild(const SharedAbstractNode& child);
180
182 TRITON_EXPORT void setChild(triton::uint32 index, const SharedAbstractNode& child);
183
185 TRITON_EXPORT std::string str(void) const;
186
188 TRITON_EXPORT virtual void init(bool withParents=false) = 0;
189 };
190
191
193 class ArrayNode : public AbstractNode {
194 private:
196 //
197 // (1) Synchronize the concrete and the symbolic
198 // (2) Evaluate nodes
199 std::unordered_map<triton::uint64, triton::uint8> memory;
200
202 triton::uint32 indexSize;
203
204 TRITON_EXPORT void initHash(void);
205
206 public:
207 TRITON_EXPORT ArrayNode(triton::uint32 indexSize, const SharedAstContext& ctxt);
208 TRITON_EXPORT void init(bool withParents=false);
209
211 TRITON_EXPORT void store(triton::uint64 addr, triton::uint8 value);
212
214 TRITON_EXPORT triton::uint8 select(triton::uint64 addr) const;
215
217 TRITON_EXPORT triton::uint8 select(const triton::uint512& addr) const;
218
220 TRITON_EXPORT triton::uint8 select(const SharedAbstractNode& node) const;
221
223 TRITON_EXPORT std::unordered_map<triton::uint64, triton::uint8>& getMemory(void);
224
226 TRITON_EXPORT triton::uint32 getIndexSize(void) const;
227 };
228
229
231 class AssertNode : public AbstractNode {
232 private:
233 TRITON_EXPORT void initHash(void);
234
235 public:
236 TRITON_EXPORT AssertNode(const SharedAbstractNode& expr);
237 TRITON_EXPORT void init(bool withParents=false);
238 };
239
240
242 class BswapNode : public AbstractNode {
243 private:
244 TRITON_EXPORT void initHash(void);
245
246 public:
247 TRITON_EXPORT BswapNode(const SharedAbstractNode& expr);
248 TRITON_EXPORT void init(bool withParents=false);
249 };
250
251
253 class BvaddNode : public AbstractNode {
254 private:
255 TRITON_EXPORT void initHash(void);
256
257 public:
258 TRITON_EXPORT BvaddNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
259 TRITON_EXPORT void init(bool withParents=false);
260 };
261
262
264 class BvandNode : public AbstractNode {
265 private:
266 TRITON_EXPORT void initHash(void);
267
268 public:
269 TRITON_EXPORT BvandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
270 TRITON_EXPORT void init(bool withParents=false);
271 };
272
273
275 class BvashrNode : public AbstractNode {
276 private:
277 TRITON_EXPORT void initHash(void);
278
279 public:
280 TRITON_EXPORT BvashrNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
281 TRITON_EXPORT void init(bool withParents=false);
282 };
283
284
286 class BvlshrNode : public AbstractNode {
287 private:
288 TRITON_EXPORT void initHash(void);
289
290 public:
291 TRITON_EXPORT BvlshrNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
292 TRITON_EXPORT void init(bool withParents=false);
293 };
294
295
297 class BvmulNode : public AbstractNode {
298 private:
299 TRITON_EXPORT void initHash(void);
300
301 public:
302 TRITON_EXPORT BvmulNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
303 TRITON_EXPORT void init(bool withParents=false);
304 };
305
306
308 class BvnandNode : public AbstractNode {
309 private:
310 TRITON_EXPORT void initHash(void);
311
312 public:
313 TRITON_EXPORT BvnandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
314 TRITON_EXPORT void init(bool withParents=false);
315 };
316
317
319 class BvnegNode : public AbstractNode {
320 private:
321 TRITON_EXPORT void initHash(void);
322
323 public:
324 TRITON_EXPORT BvnegNode(const SharedAbstractNode& expr);
325 TRITON_EXPORT void init(bool withParents=false);
326 };
327
328
330 class BvnorNode : public AbstractNode {
331 private:
332 TRITON_EXPORT void initHash(void);
333
334 public:
335 TRITON_EXPORT BvnorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
336 TRITON_EXPORT void init(bool withParents=false);
337 };
338
339
341 class BvnotNode : public AbstractNode {
342 private:
343 TRITON_EXPORT void initHash(void);
344
345 public:
346 TRITON_EXPORT BvnotNode(const SharedAbstractNode& expr1);
347 TRITON_EXPORT void init(bool withParents=false);
348 };
349
350
352 class BvorNode : public AbstractNode {
353 private:
354 TRITON_EXPORT void initHash(void);
355
356 public:
357 TRITON_EXPORT BvorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
358 TRITON_EXPORT void init(bool withParents=false);
359 };
360
361
363 class BvrolNode : public AbstractNode {
364 private:
365 TRITON_EXPORT void initHash(void);
366
367 public:
368 TRITON_EXPORT BvrolNode(const SharedAbstractNode& expr, triton::uint32 rot);
369 TRITON_EXPORT BvrolNode(const SharedAbstractNode& expr, const SharedAbstractNode& rot);
370 TRITON_EXPORT void init(bool withParents=false);
371 };
372
373
375 class BvrorNode : public AbstractNode {
376 private:
377 TRITON_EXPORT void initHash(void);
378
379 public:
380 TRITON_EXPORT BvrorNode(const SharedAbstractNode& expr, triton::uint32 rot);
381 TRITON_EXPORT BvrorNode(const SharedAbstractNode& expr, const SharedAbstractNode& rot);
382 TRITON_EXPORT void init(bool withParents=false);
383 };
384
385
387 class BvsdivNode : public AbstractNode {
388 private:
389 TRITON_EXPORT void initHash(void);
390
391 public:
392 TRITON_EXPORT BvsdivNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
393 TRITON_EXPORT void init(bool withParents=false);
394 };
395
396
398 class BvsgeNode : public AbstractNode {
399 private:
400 TRITON_EXPORT void initHash(void);
401
402 public:
403 TRITON_EXPORT BvsgeNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
404 TRITON_EXPORT void init(bool withParents=false);
405 };
406
407
409 class BvsgtNode : public AbstractNode {
410 private:
411 TRITON_EXPORT void initHash(void);
412
413 public:
414 TRITON_EXPORT BvsgtNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
415 TRITON_EXPORT void init(bool withParents=false);
416 };
417
418
420 class BvshlNode : public AbstractNode {
421 private:
422 TRITON_EXPORT void initHash(void);
423
424 public:
425 TRITON_EXPORT BvshlNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
426 TRITON_EXPORT void init(bool withParents=false);
427 };
428
429
431 class BvsleNode : public AbstractNode {
432 private:
433 TRITON_EXPORT void initHash(void);
434
435 public:
436 TRITON_EXPORT BvsleNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
437 TRITON_EXPORT void init(bool withParents=false);
438 };
439
440
442 class BvsltNode : public AbstractNode {
443 private:
444 TRITON_EXPORT void initHash(void);
445
446 public:
447 TRITON_EXPORT BvsltNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
448 TRITON_EXPORT void init(bool withParents=false);
449 };
450
451
453 class BvsmodNode : public AbstractNode {
454 private:
455 TRITON_EXPORT void initHash(void);
456
457 public:
458 TRITON_EXPORT BvsmodNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
459 TRITON_EXPORT void init(bool withParents=false);
460 };
461
462
464 class BvsremNode : public AbstractNode {
465 private:
466 TRITON_EXPORT void initHash(void);
467
468 public:
469 TRITON_EXPORT BvsremNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
470 TRITON_EXPORT void init(bool withParents=false);
471 };
472
473
475 class BvsubNode : public AbstractNode {
476 private:
477 TRITON_EXPORT void initHash(void);
478
479 public:
480 TRITON_EXPORT BvsubNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
481 TRITON_EXPORT void init(bool withParents=false);
482 };
483
484
486 class BvudivNode : public AbstractNode {
487 private:
488 TRITON_EXPORT void initHash(void);
489
490 public:
491 TRITON_EXPORT BvudivNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
492 TRITON_EXPORT void init(bool withParents=false);
493 };
494
495
497 class BvugeNode : public AbstractNode {
498 private:
499 TRITON_EXPORT void initHash(void);
500
501 public:
502 TRITON_EXPORT BvugeNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
503 TRITON_EXPORT void init(bool withParents=false);
504 };
505
506
508 class BvugtNode : public AbstractNode {
509 private:
510 TRITON_EXPORT void initHash(void);
511
512 public:
513 TRITON_EXPORT BvugtNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
514 TRITON_EXPORT void init(bool withParents=false);
515 };
516
517
519 class BvuleNode : public AbstractNode {
520 private:
521 TRITON_EXPORT void initHash(void);
522
523 public:
524 TRITON_EXPORT BvuleNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
525 TRITON_EXPORT void init(bool withParents=false);
526 };
527
528
530 class BvultNode : public AbstractNode {
531 private:
532 TRITON_EXPORT void initHash(void);
533
534 public:
535 TRITON_EXPORT BvultNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
536 TRITON_EXPORT void init(bool withParents=false);
537 };
538
539
541 class BvuremNode : public AbstractNode {
542 private:
543 TRITON_EXPORT void initHash(void);
544
545 public:
546 TRITON_EXPORT BvuremNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
547 TRITON_EXPORT void init(bool withParents=false);
548 };
549
550
552 class BvxnorNode : public AbstractNode {
553 private:
554 TRITON_EXPORT void initHash(void);
555
556 public:
557 TRITON_EXPORT BvxnorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
558 TRITON_EXPORT void init(bool withParents=false);
559 };
560
561
563 class BvxorNode : public AbstractNode {
564 private:
565 TRITON_EXPORT void initHash(void);
566
567 public:
568 TRITON_EXPORT BvxorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
569 TRITON_EXPORT void init(bool withParents=false);
570 };
571
572
574 class BvNode : public AbstractNode {
575 private:
576 TRITON_EXPORT void initHash(void);
577
578 public:
579 TRITON_EXPORT BvNode(const triton::uint512& value, triton::uint32 size, const SharedAstContext& ctxt);
580 TRITON_EXPORT void init(bool withParents=false);
581 };
582
583
585 class CompoundNode : public AbstractNode {
586 private:
587 TRITON_EXPORT void initHash(void);
588
589 public:
590 template <typename T> CompoundNode(const T& exprs, const SharedAstContext& ctxt)
592 for (auto expr : exprs)
593 this->addChild(expr);
594 }
595
596 TRITON_EXPORT void init(bool withParents=false);
597 };
598
599
601 class ConcatNode : public AbstractNode {
602 private:
603 TRITON_EXPORT void initHash(void);
604
605 public:
606 template <typename T> ConcatNode(const T& exprs, const SharedAstContext& ctxt)
608 for (auto expr : exprs)
609 this->addChild(expr);
610 }
611
612 TRITON_EXPORT ConcatNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
613 TRITON_EXPORT void init(bool withParents=false);
614 };
615
616
618 class DeclareNode : public AbstractNode {
619 private:
620 TRITON_EXPORT void initHash(void);
621
622 public:
623 TRITON_EXPORT DeclareNode(const SharedAbstractNode& var);
624 TRITON_EXPORT void init(bool withParents=false);
625 };
626
627
629 class DistinctNode : public AbstractNode {
630 private:
631 TRITON_EXPORT void initHash(void);
632
633 public:
634 TRITON_EXPORT DistinctNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
635 TRITON_EXPORT void init(bool withParents=false);
636 };
637
638
640 class EqualNode : public AbstractNode {
641 private:
642 TRITON_EXPORT void initHash(void);
643
644 public:
645 TRITON_EXPORT EqualNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
646 TRITON_EXPORT void init(bool withParents=false);
647 };
648
649
651 class ExtractNode : public AbstractNode {
652 private:
653 TRITON_EXPORT void initHash(void);
654
655 public:
656 TRITON_EXPORT ExtractNode(triton::uint32 high, triton::uint32 low, const SharedAbstractNode& expr);
657 TRITON_EXPORT void init(bool withParents=false);
658 };
659
660
662 class ForallNode : public AbstractNode {
663 private:
664 TRITON_EXPORT void initHash(void);
665
666 public:
667 template <typename T> ForallNode(const T& vars, const SharedAbstractNode& body)
668 : AbstractNode(FORALL_NODE, body->getContext()) {
669 for (auto var : vars)
670 this->addChild(var);
671 this->addChild(body);
672 }
673
674 TRITON_EXPORT void init(bool withParents=false);
675 };
676
677
679 class IffNode : public AbstractNode {
680 private:
681 TRITON_EXPORT void initHash(void);
682
683 public:
684 TRITON_EXPORT IffNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
685 TRITON_EXPORT void init(bool withParents=false);
686 };
687
688
690 class IntegerNode : public AbstractNode {
691 private:
692 TRITON_EXPORT void initHash(void);
693
694 protected:
695 triton::uint512 value;
696
697 public:
698 TRITON_EXPORT IntegerNode(const triton::uint512& value, const SharedAstContext& ctxt);
699 TRITON_EXPORT void init(bool withParents=false);
700 TRITON_EXPORT triton::uint512 getInteger(void);
701 };
702
703
705 class IteNode : public AbstractNode {
706 private:
707 TRITON_EXPORT void initHash(void);
708
709 public:
710 TRITON_EXPORT IteNode(const SharedAbstractNode& ifExpr, const SharedAbstractNode& thenExpr, const SharedAbstractNode& elseExpr);
711 TRITON_EXPORT void init(bool withParents=false);
712 };
713
714
716 class LandNode : public AbstractNode {
717 private:
718 TRITON_EXPORT void initHash(void);
719
720 public:
721 template <typename T> LandNode(const T& exprs, const SharedAstContext& ctxt)
723 for (auto expr : exprs)
724 this->addChild(expr);
725 }
726
727 TRITON_EXPORT LandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
728 TRITON_EXPORT void init(bool withParents=false);
729 };
730
731
733 class LetNode : public AbstractNode {
734 private:
735 TRITON_EXPORT void initHash(void);
736
737 public:
738 TRITON_EXPORT LetNode(std::string alias, const SharedAbstractNode& expr2, const SharedAbstractNode& expr3);
739 TRITON_EXPORT void init(bool withParents=false);
740 };
741
742
744 class LnotNode : public AbstractNode {
745 private:
746 TRITON_EXPORT void initHash(void);
747
748 public:
749 TRITON_EXPORT LnotNode(const SharedAbstractNode& expr);
750 TRITON_EXPORT void init(bool withParents=false);
751 };
752
753
755 class LorNode : public AbstractNode {
756 private:
757 TRITON_EXPORT void initHash(void);
758
759 public:
760 template <typename T> LorNode(const T& exprs, const SharedAstContext& ctxt)
762 for (auto expr : exprs)
763 this->addChild(expr);
764 }
765
766 TRITON_EXPORT LorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
767 TRITON_EXPORT void init(bool withParents=false);
768 };
769
770
772 class LxorNode : public AbstractNode {
773 private:
774 TRITON_EXPORT void initHash(void);
775
776 public:
777 template <typename T> LxorNode(const T& exprs, const SharedAstContext& ctxt)
779 for (auto expr : exprs)
780 this->addChild(expr);
781 }
782
783 TRITON_EXPORT LxorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2);
784 TRITON_EXPORT void init(bool withParents=false);
785 };
786
787
790 private:
791 TRITON_EXPORT void initHash(void);
792
793 protected:
795
796 public:
798 TRITON_EXPORT void init(bool withParents=false);
799 TRITON_EXPORT const triton::engines::symbolic::SharedSymbolicExpression& getSymbolicExpression(void) const;
800 };
801
802
804 class SelectNode : public AbstractNode {
805 private:
806 TRITON_EXPORT void initHash(void);
807
808 public:
809 TRITON_EXPORT SelectNode(const SharedAbstractNode& array, triton::usize index);
810 TRITON_EXPORT SelectNode(const SharedAbstractNode& array, const SharedAbstractNode& index);
811 TRITON_EXPORT void init(bool withParents=false);
812 };
813
814
816 class StoreNode : public AbstractNode {
817 private:
819 //
820 // (1) Synchronize the concrete and the symbolic
821 // (2) Evaluate nodes
822 std::unordered_map<triton::uint64, triton::uint8> memory;
823
825 triton::uint32 indexSize;
826
827 TRITON_EXPORT void initHash(void);
828
829 public:
830 TRITON_EXPORT StoreNode(const SharedAbstractNode& array, triton::usize index, const SharedAbstractNode& expr);
831 TRITON_EXPORT StoreNode(const SharedAbstractNode& array, const SharedAbstractNode& index, const SharedAbstractNode& expr);
832 TRITON_EXPORT void init(bool withParents=false);
833
835 TRITON_EXPORT triton::uint8 select(triton::uint64 addr) const;
836
838 TRITON_EXPORT triton::uint8 select(const triton::uint512& addr) const;
839
841 TRITON_EXPORT triton::uint8 select(const SharedAbstractNode& node) const;
842
844 TRITON_EXPORT std::unordered_map<triton::uint64, triton::uint8>& getMemory(void);
845
847 TRITON_EXPORT triton::uint32 getIndexSize(void) const;
848 };
849
850
852 class StringNode : public AbstractNode {
853 private:
854 TRITON_EXPORT void initHash(void);
855
856 protected:
857 std::string value;
858
859 public:
860 TRITON_EXPORT StringNode(std::string value, const SharedAstContext& ctxt);
861 TRITON_EXPORT void init(bool withParents=false);
862 TRITON_EXPORT std::string getString(void);
863 };
864
865
867 class SxNode : public AbstractNode {
868 private:
869 TRITON_EXPORT void initHash(void);
870
871 public:
872 TRITON_EXPORT SxNode(triton::uint32 sizeExt, const SharedAbstractNode& expr);
873 TRITON_EXPORT void init(bool withParents=false);
874 };
875
876
878 class VariableNode : public AbstractNode {
879 private:
880 TRITON_EXPORT void initHash(void);
881
882 protected:
884
885 public:
887 TRITON_EXPORT void init(bool withParents=false);
888 TRITON_EXPORT const triton::engines::symbolic::SharedSymbolicVariable& getSymbolicVariable(void);
889 };
890
891
893 class ZxNode : public AbstractNode {
894 private:
895 TRITON_EXPORT void initHash(void);
896
897 public:
899 TRITON_EXPORT ZxNode(triton::uint32 sizeExt, const SharedAbstractNode& expr);
900 TRITON_EXPORT void init(bool withParents=false);
901 };
902
905
908
911
913 TRITON_EXPORT std::ostream& operator<<(std::ostream& stream, AbstractNode* node);
914
916 TRITON_EXPORT SharedAbstractNode newInstance(AbstractNode* node, bool unroll=false);
917
919 TRITON_EXPORT SharedAbstractNode unroll(const SharedAbstractNode& node);
920
922 TRITON_EXPORT std::vector<SharedAbstractNode> childrenExtraction(const SharedAbstractNode& node, bool unroll, bool revert);
923
925 TRITON_EXPORT std::vector<SharedAbstractNode> parentsExtraction(const SharedAbstractNode& node, bool revert);
926
928 TRITON_EXPORT std::deque<SharedAbstractNode> search(const SharedAbstractNode& node, triton::ast::ast_e match=ANY_NODE);
929
931 TRITON_EXPORT SharedAbstractNode dereference(const SharedAbstractNode& node);
932
935
937 template <typename T> T inline getInteger(const SharedAbstractNode& node) {
938 if (node->getType() == INTEGER_NODE) {
939 return static_cast<T>(reinterpret_cast<IntegerNode*>(node.get())->getInteger());
940 }
941 throw triton::exceptions::Ast("triton::ast::getInteger(): You must provide an INTEGER_NODE.");
942 }
943
945 template <> std::string inline getInteger(const SharedAbstractNode& node) {
946 if (node->getType() == INTEGER_NODE) {
947 return triton::utils::toString(reinterpret_cast<triton::ast::IntegerNode*>(node.get())->getInteger());
948 }
949 throw triton::exceptions::Ast("triton::ast::getInteger(): You must provide an INTEGER_NODE.");
950 }
951
953 };
955};
956
957#endif /* TRITON_AST_H */
Abstract node.
Definition ast.hpp:68
TRITON_EXPORT bool canReplaceNodeWithoutUpdate(const SharedAbstractNode &other) const
Returns true if the node's value, value type and properties match those of the second one.
Definition ast.cpp:145
TRITON_EXPORT triton::uint32 getLevel(void) const
Returns the deep level of the tree.
Definition ast.cpp:169
bool symbolized
True if the tree contains a symbolic variable.
Definition ast.hpp:97
TRITON_EXPORT bool hasSameConcreteValueAndTypeAs(const SharedAbstractNode &other) const
Returns true if the node's concrete value and value type match those of the second one.
Definition ast.cpp:138
TRITON_EXPORT SharedAstContext getContext(void) const
Access to its context.
Definition ast.cpp:50
TRITON_EXPORT AbstractNode(triton::ast::ast_e type, const SharedAstContext &ctxt)
Constructor.
Definition ast.cpp:31
triton::ast::ast_e type
The type of the node.
Definition ast.hpp:78
TRITON_EXPORT void setParent(AbstractNode *p)
Sets a parent node.
Definition ast.cpp:205
TRITON_EXPORT bool equalTo(const SharedAbstractNode &other) const
Returns true if the current tree is equal to the second one.
Definition ast.cpp:151
TRITON_EXPORT void setChild(triton::uint32 index, const SharedAbstractNode &child)
Sets a child at an index.
Definition ast.cpp:250
TRITON_EXPORT bool isSigned(void) const
According to the size of the expression, returns true if the MSB is 1.
Definition ast.cpp:72
TRITON_EXPORT std::vector< SharedAbstractNode > getParents(void)
Returns the parents of node or an empty set if there is still no parent defined.
Definition ast.cpp:187
TRITON_EXPORT triton::uint512 getHash(void) const
Returns the hash of the tree.
Definition ast.cpp:164
bool array
True if it's an array node.
Definition ast.hpp:103
SharedAstContext ctxt
Contect use to create this node.
Definition ast.hpp:106
TRITON_EXPORT triton::uint512 getBitvectorMask(void) const
Returns the vector mask according the size of the node.
Definition ast.cpp:65
TRITON_EXPORT bool isArray(void) const
Returns true if it's an array node.
Definition ast.cpp:116
virtual TRITON_EXPORT ~AbstractNode()
Destructor.
Definition ast.cpp:44
triton::uint32 size
The size of the node.
Definition ast.hpp:88
TRITON_EXPORT bool isSymbolized(void) const
Returns true if the tree contains a symbolic variable.
Definition ast.cpp:79
std::vector< SharedAbstractNode > children
The children of the node.
Definition ast.hpp:81
TRITON_EXPORT triton::uint32 getBitvectorSize(void) const
Returns the size of the node.
Definition ast.cpp:60
virtual TRITON_EXPORT void init(bool withParents=false)=0
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT bool isLogical(void) const
Returns true if it's a logical node.
Definition ast.cpp:84
TRITON_EXPORT std::vector< SharedAbstractNode > & getChildren(void)
Returns the children of the node.
Definition ast.cpp:182
bool logical
True if it's a logical node.
Definition ast.hpp:100
TRITON_EXPORT void setBitvectorSize(triton::uint32 size)
Sets the size of the node.
Definition ast.cpp:273
triton::uint512 eval
The value of the tree from this root node.
Definition ast.hpp:91
triton::uint512 hash
The hash of the tree.
Definition ast.hpp:94
TRITON_EXPORT std::string str(void) const
Returns the string representation of the node.
Definition ast.cpp:278
TRITON_EXPORT void addChild(const SharedAbstractNode &child)
Adds a child.
Definition ast.cpp:245
TRITON_EXPORT void removeParent(AbstractNode *p)
Removes a parent node.
Definition ast.cpp:226
void initParents(void)
Initializes parents.
Definition ast.cpp:174
TRITON_EXPORT triton::uint512 evaluate(void) const
Evaluates the tree.
Definition ast.cpp:159
TRITON_EXPORT triton::ast::ast_e getType(void) const
Returns the type of the node.
Definition ast.cpp:55
triton::uint32 level
Deep level for computing hash.
Definition ast.hpp:75
(Array (_ BitVec indexSize) (_ BitVec 8)) node
Definition ast.hpp:193
TRITON_EXPORT void store(triton::uint64 addr, triton::uint8 value)
Stores a concrete value into the memory array.
Definition ast.cpp:332
TRITON_EXPORT triton::uint8 select(triton::uint64 addr) const
Select a concrete value into the memory array.
Definition ast.cpp:337
TRITON_EXPORT triton::uint32 getIndexSize(void) const
Gets the index size.
Definition ast.cpp:360
TRITON_EXPORT std::unordered_map< triton::uint64, triton::uint8 > & getMemory(void)
Gets the concrete memory array.
Definition ast.cpp:355
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:296
(assert <expr>) node
Definition ast.hpp:231
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:373
(bswap <expr>) node
Definition ast.hpp:242
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:423
(_ bv<value> <size>) node
Definition ast.hpp:574
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2161
(bvadd <expr1> <expr2>) node
Definition ast.hpp:253
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:483
(bvand <expr1> <expr2>) node
Definition ast.hpp:264
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:537
(bvashr <expr1> <expr2>) node
Definition ast.hpp:275
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:591
(bvlshr <expr1> <expr2>) node
Definition ast.hpp:286
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:677
(bvmul <expr1> <expr2>) node
Definition ast.hpp:297
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:731
(bvnand <expr1> <expr2>) node
Definition ast.hpp:308
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:785
(bvneg <expr>) node
Definition ast.hpp:319
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:838
(bvnor <expr1> <expr2>) node
Definition ast.hpp:330
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:889
(bvnot <expr>) node
Definition ast.hpp:341
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:942
(bvor <expr1> <expr2>) node
Definition ast.hpp:352
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:993
((_ rotate_left rot) <expr>) node
Definition ast.hpp:363
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1051
((_ rotate_right rot) <expr>) node
Definition ast.hpp:375
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1113
(bvsdiv <expr1> <expr2>) node
Definition ast.hpp:387
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1171
(bvsge <expr1> <expr2>) node
Definition ast.hpp:398
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1238
(bvsgt <expr1> <expr2>) node
Definition ast.hpp:409
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1299
(bvshl <expr1> <expr2>) node
Definition ast.hpp:420
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1360
(bvsle <expr1> <expr2>) node
Definition ast.hpp:431
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1414
(bvslt <expr1> <expr2>) node
Definition ast.hpp:442
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1475
(bvsmod <expr1> <expr2>) node
Definition ast.hpp:453
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1536
(bvsrem <expr1> <expr2>) node
Definition ast.hpp:464
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1601
(bvsub <expr1> <expr2>) node
Definition ast.hpp:475
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1666
(bvudiv <expr1> <expr2>) node
Definition ast.hpp:486
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1720
(bvuge <expr1> <expr2>) node
Definition ast.hpp:497
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1778
(bvugt <expr1> <expr2>) node
Definition ast.hpp:508
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1832
(bvule <expr1> <expr2>) node
Definition ast.hpp:519
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1886
(bvult <expr1> <expr2>) node
Definition ast.hpp:530
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1940
(bvurem <expr1> <expr2>) node
Definition ast.hpp:541
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:1994
(bvxnor <expr1> <expr2>) node
Definition ast.hpp:552
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2052
(bvxor <expr1> <expr2>) node
Definition ast.hpp:563
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2106
[<expr1> <expr2> <expr3> ...] node
Definition ast.hpp:585
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2215
(concat <expr1> <expr2> ...) node
Definition ast.hpp:601
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2263
(declare-fun <var_name> () (_ BitVec <var_size>)) node
Definition ast.hpp:618
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2322
(distinct <expr1> <expr2> ...) node
Definition ast.hpp:629
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2373
(= <expr1> <expr2> ...) node
Definition ast.hpp:640
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2427
((_ extract <high> <low>) <expr>) node
Definition ast.hpp:651
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2482
(forall ((x (_ BitVec <size>)), ...) body)
Definition ast.hpp:662
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2539
(iff <expr1> <expr2>)
Definition ast.hpp:679
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2596
Integer node.
Definition ast.hpp:690
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2652
(ite <ifExpr> <thenExpr> <elseExpr>)
Definition ast.hpp:705
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2693
(and <expr1> <expr2>)
Definition ast.hpp:716
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2760
(let ((<alias> <expr2>)) <expr3>)
Definition ast.hpp:733
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2813
(lnot <expr>)
Definition ast.hpp:744
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2863
(or <expr1> <expr2>)
Definition ast.hpp:755
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2914
(xor <expr1> <expr2>)
Definition ast.hpp:772
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:2966
Reference node.
Definition ast.hpp:789
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:3018
(select array index)
Definition ast.hpp:804
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:3062
(store array index expr)
Definition ast.hpp:816
TRITON_EXPORT triton::uint32 getIndexSize(void) const
Gets the index size.
Definition ast.cpp:3224
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:3135
TRITON_EXPORT std::unordered_map< triton::uint64, triton::uint8 > & getMemory(void)
Gets the concrete memory array.
Definition ast.cpp:3219
TRITON_EXPORT triton::uint8 select(triton::uint64 addr) const
Select a concrete value into the memory array.
Definition ast.cpp:3201
String node.
Definition ast.hpp:852
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:3237
((_ sign_extend sizeExt) <expr>) node
Definition ast.hpp:867
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:3279
Variable node.
Definition ast.hpp:878
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:3338
((_ zero_extend sizeExt) <expr>) node
Definition ast.hpp:893
TRITON_EXPORT ZxNode(triton::uint32 sizeExt, const SharedAbstractNode &expr)
Create a zero extend of expr to sizeExt bits.
Definition ast.cpp:3374
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition ast.cpp:3380
The exception class used by all AST nodes.
triton::uint32 getIndexSize(const SharedAbstractNode &node)
Gets the index size of an array.
Definition ast.cpp:3755
SharedAbstractNode unroll(const triton::ast::SharedAbstractNode &node)
AST C++ API - Unrolls the SSA form of a given AST.
Definition ast.cpp:3626
SharedAbstractNode dereference(const SharedAbstractNode &node)
Returns the first non referene node encountered.
Definition ast.cpp:3743
triton::uint512 hash2n(triton::uint512 hash, triton::uint32 n)
Custom hash2n function for hash routine.
Definition ast.cpp:3476
std::vector< SharedAbstractNode > parentsExtraction(const SharedAbstractNode &node, bool revert)
Returns node and all its parents of an AST sorted topologically. If revert is true,...
Definition ast.cpp:3705
std::vector< SharedAbstractNode > childrenExtraction(const SharedAbstractNode &node, bool unroll, bool revert)
Returns node and all its children of an AST sorted topologically. If unroll is true,...
Definition ast.cpp:3700
T getInteger(const SharedAbstractNode &node)
Gets the value of an integer node.
Definition ast.hpp:937
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
Definition ast.hpp:59
std::ostream & operator<<(std::ostream &stream, AbstractNode *node)
Displays the node in ast representation.
Definition ast.cpp:3462
std::weak_ptr< triton::ast::AbstractNode > WeakAbstractNode
Weak Abstract Node.
Definition ast.hpp:62
SharedAbstractNode newInstance(AbstractNode *node, bool unroll)
AST C++ API - Duplicates the AST.
Definition ast.cpp:3604
std::shared_ptr< triton::ast::AstContext > SharedAstContext
Shared AST context.
Definition ast.hpp:65
triton::sint512 modularSignExtend(AbstractNode *node)
Custom modular sign extend for bitwise operation.
Definition ast.cpp:3491
std::deque< SharedAbstractNode > search(const SharedAbstractNode &node, triton::ast::ast_e match)
Returns a deque of collected matched nodes via a depth-first pre order traversal.
Definition ast.cpp:3710
triton::uint512 rotl(const triton::uint512 &value, triton::uint32 shift)
Custom rotate left function for hash routine.
Definition ast.cpp:3484
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition ast.hpp:40
std::shared_ptr< triton::engines::symbolic::SymbolicVariable > SharedSymbolicVariable
Shared Symbolic variable.
Definition ast.hpp:43
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
std::uint64_t uint64
unisgned 64-bits
std::uint32_t uint32
unisgned 32-bits
std::uint8_t uint8
unisgned 8-bits
std::string toString(const T &obj)
Converts an object to a string.
Definition coreUtils.hpp:38
The Triton namespace.