1 //! \file
2 /*
3 **  Copyright (C) - Triton
4 **
5 **  This program is under the terms of the Apache License 2.0.
6 */
7 
8 #include <triton/exceptions.hpp>
9 #include <triton/pathConstraint.hpp>
10 
11 
12 
13 namespace triton {
14   namespace engines {
15     namespace symbolic {
16 
PathConstraint()17       PathConstraint::PathConstraint() {
18       }
19 
20 
PathConstraint(const PathConstraint & other)21       PathConstraint::PathConstraint(const PathConstraint &other) {
22         this->branches = other.branches;
23       }
24 
25 
~PathConstraint()26       PathConstraint::~PathConstraint() {
27         /* See #828: Release ownership before calling container destructor */
28         this->branches.clear();
29       }
30 
31 
operator =(const PathConstraint & other)32       PathConstraint& PathConstraint::operator=(const PathConstraint &other) {
33         this->branches = other.branches;
34         return *this;
35       }
36 
37 
addBranchConstraint(bool taken,triton::uint64 srcAddr,triton::uint64 dstAddr,const triton::ast::SharedAbstractNode & pc)38       void PathConstraint::addBranchConstraint(bool taken, triton::uint64 srcAddr, triton::uint64 dstAddr, const triton::ast::SharedAbstractNode& pc) {
39         if (pc == nullptr)
40           throw triton::exceptions::PathConstraint("PathConstraint::addBranchConstraint(): The PC node cannot be null.");
41         this->branches.push_back(std::make_tuple(taken, srcAddr, dstAddr, pc));
42       }
43 
44 
getBranchConstraints(void) const45       const std::vector<std::tuple<bool, triton::uint64, triton::uint64, triton::ast::SharedAbstractNode>>& PathConstraint::getBranchConstraints(void) const {
46         return this->branches;
47       }
48 
49 
getTakenAddress(void) const50       triton::uint64 PathConstraint::getTakenAddress(void) const {
51         for (auto it = this->branches.begin(); it != this->branches.end(); it++) {
52           if (std::get<0>(*it) == true)
53             return std::get<2>(*it);
54         }
55         throw triton::exceptions::PathConstraint("PathConstraint::getTakenAddress(): Something wrong, no branch taken.");
56       }
57 
58 
getTakenPredicate(void) const59       triton::ast::SharedAbstractNode PathConstraint::getTakenPredicate(void) const {
60         for (auto it = this->branches.begin(); it != this->branches.end(); it++) {
61           if (std::get<0>(*it) == true)
62             return std::get<3>(*it);
63         }
64         throw triton::exceptions::PathConstraint("PathConstraint::getTakenPredicate(): Something wrong, no branch taken.");
65       }
66 
67 
isMultipleBranches(void) const68       bool PathConstraint::isMultipleBranches(void) const {
69         if (this->branches.size() == 0)
70           throw triton::exceptions::PathConstraint("PathConstraint::isMultipleBranches(): Path Constraint is empty.");
71         else if (this->branches.size() == 1)
72           return false;
73         return true;
74       }
75 
76     }; /* symbolic namespace */
77   }; /* engines namespace */
78 }; /*triton namespace */
79