12 #include "exception.hpp"
89 std::string op_to_str(
Op op);
91 bool op_is_symetric(
Op op);
92 bool op_is_associative(
Op op);
93 bool op_is_left_associative(
Op op);
94 bool op_is_distributive_over(
Op op1,
Op op2);
95 bool op_is_multiplication(
Op op);
126 static const uint64_t
vs_max = 0xffffffffffffffff;
146 bool contains(
ucst_t val);
178 typedef std::shared_ptr<ExprObject>
Expr;
192 bool _value_set_computed;
230 virtual void get_associative_args(
Op op, std::vector<Expr>& vec){};
231 virtual void get_left_associative_args(
Op op, std::vector<Expr>& vec,
Expr& leftmost){};
291 bool already_simplified_by(
int simplifier_id);
299 bool inf(
Expr other);
303 virtual const std::string& name(){
throw runtime_exception(
"No implementation");};
304 virtual Op op(){
throw runtime_exception(
"No implementation");};
305 virtual cst_t mode(){
throw runtime_exception(
"No implementation");};
306 virtual unsigned int access_count(){
throw runtime_exception(
"No implementation");};
307 virtual Expr cond_left(){
throw runtime_exception(
"No implementation");};
308 virtual Expr cond_right(){
throw runtime_exception(
"No implementation");};
309 virtual Expr if_true(){
throw runtime_exception(
"No implementation");};
310 virtual Expr if_false(){
throw runtime_exception(
"No implementation");};
311 virtual ITECond cond_op(){
throw runtime_exception(
"No implementation");};
312 virtual Expr base_expr(){
throw runtime_exception(
"No implementation");};
315 virtual void print(std::ostream& out){out <<
"???";};
335 virtual void print(std::ostream& out);
346 const std::string _name;
347 static const int max_name_length = 1024;
359 virtual void print(std::ostream& out);
370 unsigned int _access_count;
375 bool _unfolded_with_forced_align;
385 virtual void print(std::ostream& out);
388 unsigned int access_count();
409 virtual void print(std::ostream& out);
431 virtual void get_associative_args(
Op op, std::vector<Expr>& vec);
432 virtual void get_left_associative_args(
Op op, std::vector<Expr>& vec,
Expr& leftmost);
433 virtual void print(std::ostream& out);
450 virtual void print(std::ostream& out);
467 virtual void print(std::ostream& out);
492 virtual void print(std::ostream& out);
593 cst_t cst_mask(
size_t size);
594 cst_t cst_sign_extend(
size_t size,
cst_t val);
606 static unsigned int _id_cnt;
610 std::map<std::string, maat::Number> varmap;
623 const maat::Number& get_as_number(
const std::string& var)
const;
624 std::vector<uint8_t> get_as_buffer(std::string var,
unsigned int elem_size=1)
const;
625 std::string get_as_string(std::string var)
const;
628 std::string new_name_from(
const std::string& hint)
const;
637 const std::string& name,
640 bool null_terminated=
false
651 const std::string& name,
652 const std::vector<cst_t>& concrete_buffer,
655 bool null_terminated=
false
673 std::string ite_cond_to_string(
ITECond c);
682 if (new_expr->size >= old_expr->size)
684 else if(higher_bit == new_expr->size-1)
686 return concat(
extract(old_expr, old_expr->size-1, higher_bit+1), new_expr);
688 else if(higher_bit == old_expr->size-1)
690 return concat(new_expr,
extract(old_expr, higher_bit-new_expr->size, 0));
694 return concat(
extract(old_expr, old_expr->size-1, higher_bit+1),
695 concat(new_expr,
extract(old_expr, higher_bit-new_expr->size, 0)));
Expr extract(Expr arg, unsigned long higher, unsigned long lower)
Create new ExprExtract instance.
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
Expr smulh(Expr left, Expr right)
Signed multiply two expressions (higher bits of result)
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
ucst_t max
Upper bound.
Definition: expression.hpp:133
cst_t as_int(const VarContext &ctx)
Return the concrete value of the expression evaluated in the context 'ctx' as a signed value....
Expr operator&(Expr left, Expr right)
Logical and between two expressions.
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
Expr operator^(Expr left, Expr right)
Logical xor between two expressions.
void set(const std::string &var, cst_t value)
Give a concrete value to a symbolic variable.
ExprCst(size_t size, cst_t cst)
Constructor for constants on 64 bits or less.
int _simplifier_id
ID of the simplifier that has simplified the expression.
Definition: expression.hpp:199
ITECond cond_op()
Condition comparison operator (==, !=, <, <=, ...)
void make_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Make the bits specified by 'taint_mask' tainted in the expression.
Definition: exception.hpp:64
virtual const Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
Concatenation of two expressions.
Definition: expression.hpp:457
void set_cst(ucst_t val)
Set value set as just one constant value.
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
ucst_t range()
Return the difference between max and min.
Binary operation.
Definition: expression.hpp:417
bool contains_vars(std::set< std::string > &var_names)
Return true if the expression contains at least one of the given symbolic variable names.
int size
Definition: expression.hpp:131
int64_t cst_t
Signed constant integer value.
Definition: types.hpp:14
fcst_t as_float()
Return the concrete value of the expression as a floating point value. If the expression is concolic,...
ucst_t _taint_mask
The bits that are tainted in the expression (if _taint == TAINTED)
Definition: expression.hpp:203
Expr operator+(Expr left, Expr right)
Add two expressions.
Definition: expression.hpp:366
ExprObject(ExprType type, size_t size, bool _is_simp=false, Taint _t=Taint::NOT_COMPUTED, ucst_t _taint_mask=maat::default_expr_taint_mask)
Constructor.
ExprUnop(Op op, Expr arg)
Constructor.
ExprConcat(Expr upper, Expr lower)
Constructor.
int _taint_ctx_id
The ID of the VarContext that was used to compute the taint.
Definition: expression.hpp:202
ucst_t min
Lower bound.
Definition: expression.hpp:132
Expr mulh(Expr left, Expr right)
Unsigned multiply two expressions (higher bits of result)
double fcst_t
Float constant value (double precision / 64 bits)
Definition: types.hpp:16
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
uint64_t ucst_t
Unsigned constant integer value.
Definition: types.hpp:15
Expr concat(Expr upper, Expr lower)
Create new ExprConcat instance.
std::shared_ptr< ExprObject > Expr
Definition: expression.hpp:178
ExprStatus
Definition: expression.hpp:99
VarContext(unsigned int id=0)
Constructor.
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
bool eq(Expr other)
Checks equality between two expressions. The method returns true if the expressions are syntactically...
Dedicated memory engine handling the 'symbolic' memory state resulting from symbolic pointer writes.
Definition: memory.hpp:310
Expr cond_left()
Left member of condition.
const std::string & name()
Get the variable name.
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
Expr cond_right()
Right member of condition.
const maat::Number & as_number(const VarContext &ctx)
Return the concrete value of the expression as a *maat::Number instance. If the expression is concoli...
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
const ExprType type
Expression type.
Definition: expression.hpp:222
Definition: simplification.hpp:29
virtual const Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
Definition: expression.hpp:246
If-Then-Else expression.
Definition: expression.hpp:474
Expr exprmem(size_t size, Expr addr, unsigned int access_count=0xffffffff, Expr base=nullptr)
Create new ExprMem instance.
ucst_t as_uint(const VarContext &ctx)
Return the concrete value of the expression evaluated in the context 'ctx' as an unsigned value....
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
Definition: expression.hpp:279
bool contains(const std::string &var) const
Return true if a concrete value is associated to the symbolic variable.
std::vector< Expr > args
Expression arguments (sub-expressions)
Definition: expression.hpp:227
Expr exprcst(size_t size, cst_t cst)
Create new ExprCst instance.
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
Expr sdiv(Expr left, Expr right)
Signed divide two expressions.
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
Unary operation.
Definition: expression.hpp:395
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
bool neq(Expr other)
Opposite of the eq() method.
Expr operator>>(Expr val, Expr shift)
Shift an expression to the right.
Expr sar(Expr arg, Expr shift)
Arithmetic shift an expression to the right.
void print(std::ostream &os) const
Print the context to a stream.
void set_all()
Make value set as big as possible (min = vs_min, max = vs_max)
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
Expr operator*(Expr left, Expr right)
Unsigned multiply two expressions (lower bits of result)
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
Expr operator%(Expr val, Expr mod)
Unsigned modulo of two expressions.
Expr __attribute__((always_inline)) overwrite_expr_bits(Expr old_expr
Returns the expression resulting from overwriting the bits higher_bit to higher_bit-new_expr....
bool is_concrete(const VarContext &ctx)
Return true if expression is concrete.
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
Expr operator/(Expr left, Expr right)
Unsigned divide two expressions.
Op op()
Return the operation of the expression.
Expr smod(Expr val, Expr mod)
Signed modulo between two expressions.
ucst_t taint_mask()
Return the bit mask of tainted bits in the expression.
ucst_t stride
Stride.
Definition: expression.hpp:134
Expr ITE(Expr cond_left, ITECond cond_op, Expr cond_right, Expr if_true, Expr if_false)
Create new ExprITE instance.
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
virtual const Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
cst_t get(const std::string &var) const
Get the concrete value given to a symbolic variable.
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
@ CONCRETE
Concrete expression (no symbolic variables)
@ NOT_TAINTED
No bit is tainted.
void update_from(VarContext &other)
Copy the mapping between concrete values and symbolic variables from 'other'.
ExprITE(Expr cond1, ITECond cond_op, Expr cond2, Expr if_true, Expr if_false)
Constructor.
virtual const Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
Expr exprvar(size_t size, std::string name, Taint tainted=Taint::NOT_TAINTED)
Create new ExprVar instance.
Definition: expression.hpp:604
cst_t as_int()
Return the concrete value of the expression as an signed value. If the expression is concolic,...
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
std::ostream & operator<<(std::ostream &os, const Constraint &constr)
Print a constraint to an out stream.
bool is_cst()
Return true if the value set represents a constant (min==max)
int _concrete_ctx_id
The ID of the VarContext that was used to concretize the expression.
Definition: expression.hpp:206
Expr _simplified_expr
Pointer to the simplified version of this expression if it has already been simplified.
Definition: expression.hpp:197
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
Expr if_false()
Value of the expression if the condition is false.
void remove(const std::string &var)
Remove concrete value for symbolic variable.
Abstract variable.
Definition: expression.hpp:344
Definition: expression.hpp:123
ExprCst(size_t size, const std::string &value, int base=16)
Constructor for constants on more than 64 bits.
Expr if_true()
Value of the expression if the condition is true.
ExprType
Different types of abstract expressions.
Definition: expression.hpp:37
void get_vars(std::set< std::string > &var_names)
Fill 'var_names' with the names of symbolic variables contained in the expression.
bool _is_simplified
True if this expression is the result of a simplification.
Definition: expression.hpp:198
void set(const std::string &var, const Number &number)
Give a concrete value to a symbolic variable as a maat::Number instance.
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
Main namespace for Maat's API.
Definition: arch.hpp:11
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
Definition: expression.hpp:282
Op
Definition: expression.hpp:68
const size_t size
Expression size in bits.
Definition: expression.hpp:226
Op op()
Return the operation of the expression.
static const uint64_t default_expr_taint_mask
Definition: expression.hpp:117
static const uint64_t vs_min
Minimal lower bound.
Definition: expression.hpp:125
virtual ValueSet & value_set()
Return the value set of the expression, which is the set of possible numerical values it can take exp...
virtual hash_t hash()
Return the expression hash. Every expression has a unique hash.
Definition: expression.hpp:239
virtual ExprStatus status(const VarContext &ctx)
Return the expression symbolic status.
Constant expression.
Definition: expression.hpp:321
ITECond
Definition: expression.hpp:54
Taint
Definition: expression.hpp:110
unsigned int id
Unique identifier for the VarContext instance.
Definition: expression.hpp:619
virtual const Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
virtual bool is_tainted(ucst_t taint_mask=maat::default_expr_taint_mask)
Return true if at least one bit set in 'taint_mask' is tainted in the epression.
fcst_t as_float(const VarContext &ctx)
Return the concrete value of the expression evaluated in the context 'ctx' as a floating point value.
bool is_type(ExprType t, Op op=Op::NONE)
Return true if the expression is of type 't'. If type is UNOP or BINOP, also check if the operation i...
Represents a constant value on an arbitrary number of bits.
Definition: number.hpp:23
virtual bool is_symbolic(const VarContext &ctx)
Return true if expression is symbolic.
Expr smull(Expr left, Expr right)
Signed multiply two expressions (lower bits of result)
ExprCst(const Number &value)
Constructor for constants directly from number.
ExprBinop(Op op, Expr left, Expr right)
Constructor.
std::vector< Expr > new_concolic_buffer(const std::string &name, const std::vector< cst_t > &concrete_buffer, int nb_elems, int elem_size=1, bool null_terminated=false)
Create a new buffer of concolic variables. Returns a pair <buffer_name, buffer>.
static const uint64_t vs_max
Maximal upper bound.
Definition: expression.hpp:126
maat::Number _concrete
The concrete value of the expression.
Definition: expression.hpp:205
std::vector< Expr > new_symbolic_buffer(const std::string &name, int nb_elems, int elem_size=1, bool null_terminated=false)
Create a new buffer of symbolic variables. Returns a pair <buffer_name, buffer>.
virtual const maat::Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
Definition: expression.hpp:222
virtual const Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
Constraint operator<(Expr left, Expr right)
Create a signed less-than constraint.
const maat::Number & as_number()
Return the concrete value of the expression as a maat::Number instance.
uint32_t hash_t
Unique hash identifying an abstract expression object.
Definition: types.hpp:13
virtual bool is_concolic(const VarContext &ctx)
Return true if expression is concolic.
int _status_ctx_id
The ID of the VarContext that was used to compute the epression status.
Definition: expression.hpp:209
ucst_t as_uint()
Return the concrete value of the expression as an unsigned value. If the expression is concolic,...
virtual const Number & concretize(const VarContext *ctx=nullptr)
Return the concrete value of the expression evaluated in the context 'ctx'.
Expr operator-(Expr left, Expr right)
Subtract two expressions.
Expr operator~(Expr arg)
Negate an expression.
Definition: expression.hpp:186
ExprVar(size_t size, std::string name, Taint tainted=Taint::NOT_TAINTED)
Constructor.