miasm
Reverse engineering framework
miasm.expression.expression Namespace Reference

Classes

class  DiGraphExpr
 
class  Expr
 
class  ExprAff
 
class  ExprAssign
 
class  ExprCompose
 
class  ExprCond
 
class  ExprGetR
 
class  ExprId
 
class  ExprInt
 
class  ExprLoc
 
class  ExprMem
 
class  ExprOp
 
class  ExprSlice
 
class  ExprVisitorBase
 
class  ExprVisitorCallbackBottomToTop
 
class  ExprVisitorCallbackTopToBottom
 
class  ExprVisitorCanonize
 
class  ExprVisitorContains
 
class  ExprWalk
 
class  ExprWalkBase
 
class  LocKey
 

Functions

def should_parenthesize_child (child, parent)
 
def str_protected_child (child, parent)
 
def is_expr (expr)
 
def is_associative (expr)
 
def is_commutative (expr)
 
def canonize_to_exprloc (locdb, expr)
 
def is_function_call (expr)
 
def compare_exprs_compose (expr1, expr2)
 
def compare_expr_list_compose (l1_e, l2_e)
 
def compare_expr_list (l1_e, l2_e)
 
def compare_exprs (expr1, expr2)
 
def canonize_expr_list (expr_list)
 
def canonize_expr_list_compose (expr_list)
 
def ExprInt1 (i)
 
def ExprInt8 (i)
 
def ExprInt16 (i)
 
def ExprInt32 (i)
 
def ExprInt64 (i)
 
def ExprInt_from (expr, i)
 
def get_expr_ids_visit (expr, ids)
 
def get_expr_locs_visit (expr, locs)
 
def get_expr_ids (expr)
 
def get_expr_locs (expr)
 
def test_set (expr, pattern, tks, result)
 
def match_expr (expr, pattern, tks, result=None)
 
def MatchExpr (expr, pattern, tks, result=None)
 
def get_rw (exprs)
 
def get_list_rw (exprs, mem_read=False, cst_read=True)
 
def get_expr_ops (expr)
 
def get_expr_mem (expr)
 
def expr_is_equal (op1, op2)
 
def expr_is_not_equal (op1, op2)
 
def expr_is_unsigned_greater (op1, op2)
 
def expr_is_unsigned_greater_or_equal (op1, op2)
 
def expr_is_unsigned_lower (op1, op2)
 
def expr_is_unsigned_lower_or_equal (op1, op2)
 
def expr_is_signed_greater (op1, op2)
 
def expr_is_signed_greater_or_equal (op1, op2)
 
def expr_is_signed_lower (op1, op2)
 
def expr_is_signed_lower_or_equal (op1, op2)
 
def expr_is_NaN (expr)
 
def expr_is_infinite (expr)
 
def expr_is_IEEE754_zero (expr)
 
def expr_is_IEEE754_denormal (expr)
 
def expr_is_qNaN (expr)
 
def expr_is_sNaN (expr)
 
def expr_is_float_lower (op1, op2)
 
def expr_is_float_equal (op1, op2)
 

Variables

string TOK_INF = "<"
 
string TOK_INF_SIGNED = TOK_INF + "s"
 
string TOK_INF_UNSIGNED = TOK_INF + "u"
 
string TOK_INF_EQUAL = "<="
 
string TOK_INF_EQUAL_SIGNED = TOK_INF_EQUAL + "s"
 
string TOK_INF_EQUAL_UNSIGNED = TOK_INF_EQUAL + "u"
 
string TOK_EQUAL = "=="
 
string TOK_POS = "pos"
 
string TOK_POS_STRICT = "Spos"
 
int EXPRINT = 1
 
int EXPRID = 2
 
int EXPRLOC = 3
 
int EXPRASSIGN = 4
 
int EXPRCOND = 5
 
int EXPRMEM = 6
 
int EXPROP = 7
 
int EXPRSLICE = 8
 
int EXPRCOMPOSE = 9
 
list priorities_list
 
 priorities
 
int PRIORITY_MAX = len(priorities_list) - 1
 
 contains_visitor = ExprVisitorContains()
 
 canonize_visitor = ExprVisitorCanonize()
 
dictionary EXPR_ORDER_DICT
 
dictionary size_to_IEEE754_info
 

Function Documentation

◆ canonize_expr_list()

def miasm.expression.expression.canonize_expr_list (   expr_list)
Here is the caller graph for this function:

◆ canonize_expr_list_compose()

def miasm.expression.expression.canonize_expr_list_compose (   expr_list)

◆ canonize_to_exprloc()

def miasm.expression.expression.canonize_to_exprloc (   locdb,
  expr 
)
If expr is ExprInt, return ExprLoc with corresponding loc_key
Else, return expr

@expr: Expr instance
Here is the caller graph for this function:

◆ compare_expr_list()

def miasm.expression.expression.compare_expr_list (   l1_e,
  l2_e 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_expr_list_compose()

def miasm.expression.expression.compare_expr_list_compose (   l1_e,
  l2_e 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_exprs()

def miasm.expression.expression.compare_exprs (   expr1,
  expr2 
)
Compare 2 expressions for canonization
@expr1: Expr
@expr2: Expr
0  => ==
1  => expr1 > expr2
-1 => expr1 < expr2
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_exprs_compose()

def miasm.expression.expression.compare_exprs_compose (   expr1,
  expr2 
)
Here is the call graph for this function:

◆ expr_is_equal()

def miasm.expression.expression.expr_is_equal (   op1,
  op2 
)
if op1 == op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_float_equal()

def miasm.expression.expression.expr_is_float_equal (   op1,
  op2 
)
Return 1 on 1 bit if @op1 == @op2, 0 otherwise.
/!\ Assume @op1 and @op2 are not NaN
Comparison is the floating point one, defined in IEEE754

◆ expr_is_float_lower()

def miasm.expression.expression.expr_is_float_lower (   op1,
  op2 
)
Return 1 on 1 bit if @op1 < @op2, 0 otherwise.
/!\ Assume @op1 and @op2 are not NaN
Comparison is the floating point one, defined in IEEE754
Here is the call graph for this function:

◆ expr_is_IEEE754_denormal()

def miasm.expression.expression.expr_is_IEEE754_denormal (   expr)
Return 1 or 0 on 1 bit if expr represent a denormalized value according
to IEEE754

◆ expr_is_IEEE754_zero()

def miasm.expression.expression.expr_is_IEEE754_zero (   expr)
Return 1 or 0 on 1 bit if expr represent a zero value according to
IEEE754

◆ expr_is_infinite()

def miasm.expression.expression.expr_is_infinite (   expr)
Return 1 or 0 on 1 bit if expr represent an infinite value according to
IEEE754

◆ expr_is_NaN()

def miasm.expression.expression.expr_is_NaN (   expr)
Return 1 or 0 on 1 bit if expr represent a NaN value according to IEEE754
Here is the caller graph for this function:

◆ expr_is_not_equal()

def miasm.expression.expression.expr_is_not_equal (   op1,
  op2 
)
if op1 != op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_qNaN()

def miasm.expression.expression.expr_is_qNaN (   expr)
Return 1 or 0 on 1 bit if expr represent a qNaN (quiet) value according to
IEEE754
Here is the call graph for this function:

◆ expr_is_signed_greater()

def miasm.expression.expression.expr_is_signed_greater (   op1,
  op2 
)
Signed cmp
if op1 > op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_signed_greater_or_equal()

def miasm.expression.expression.expr_is_signed_greater_or_equal (   op1,
  op2 
)
Signed cmp
if op1 > op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_signed_lower()

def miasm.expression.expression.expr_is_signed_lower (   op1,
  op2 
)
Signed cmp
if op1 < op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_signed_lower_or_equal()

def miasm.expression.expression.expr_is_signed_lower_or_equal (   op1,
  op2 
)
Signed cmp
if op1 <= op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_sNaN()

def miasm.expression.expression.expr_is_sNaN (   expr)
Return 1 or 0 on 1 bit if expr represent a sNaN (signalling) value according
to IEEE754
Here is the call graph for this function:

◆ expr_is_unsigned_greater()

def miasm.expression.expression.expr_is_unsigned_greater (   op1,
  op2 
)
UNSIGNED cmp
if op1 > op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_unsigned_greater_or_equal()

def miasm.expression.expression.expr_is_unsigned_greater_or_equal (   op1,
  op2 
)
Unsigned cmp
if op1 >= op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ expr_is_unsigned_lower()

def miasm.expression.expression.expr_is_unsigned_lower (   op1,
  op2 
)
Unsigned cmp
if op1 < op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)
Here is the caller graph for this function:

◆ expr_is_unsigned_lower_or_equal()

def miasm.expression.expression.expr_is_unsigned_lower_or_equal (   op1,
  op2 
)
Unsigned cmp
if op1 <= op2:
   Return ExprInt(1, 1)
else:
   Return ExprInt(0, 1)

◆ ExprInt1()

def miasm.expression.expression.ExprInt1 (   i)

◆ ExprInt16()

def miasm.expression.expression.ExprInt16 (   i)

◆ ExprInt32()

def miasm.expression.expression.ExprInt32 (   i)

◆ ExprInt64()

def miasm.expression.expression.ExprInt64 (   i)

◆ ExprInt8()

def miasm.expression.expression.ExprInt8 (   i)

◆ ExprInt_from()

def miasm.expression.expression.ExprInt_from (   expr,
  i 
)
Here is the caller graph for this function:

◆ get_expr_ids()

def miasm.expression.expression.get_expr_ids (   expr)
Retrieve ExprId in @expr
@expr: Expr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_expr_ids_visit()

def miasm.expression.expression.get_expr_ids_visit (   expr,
  ids 
)
Visitor to retrieve ExprId in @expr
@expr: Expr
Here is the caller graph for this function:

◆ get_expr_locs()

def miasm.expression.expression.get_expr_locs (   expr)
Retrieve ExprLoc in @expr
@expr: Expr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_expr_locs_visit()

def miasm.expression.expression.get_expr_locs_visit (   expr,
  locs 
)
Visitor to retrieve ExprLoc in @expr
@expr: Expr
Here is the caller graph for this function:

◆ get_expr_mem()

def miasm.expression.expression.get_expr_mem (   expr)
Retrieve memory accesses of an @expr
@expr: Expr
Here is the caller graph for this function:

◆ get_expr_ops()

def miasm.expression.expression.get_expr_ops (   expr)
Retrieve operators of an @expr
@expr: Expr

◆ get_list_rw()

def miasm.expression.expression.get_list_rw (   exprs,
  mem_read = False,
  cst_read = True 
)
Return list of read/write reg/cst/mem for each @exprs
@exprs: list of expressions
@mem_read: walk though memory accesses
@cst_read: retrieve constants

◆ get_rw()

def miasm.expression.expression.get_rw (   exprs)

◆ is_associative()

def miasm.expression.expression.is_associative (   expr)
Here is the caller graph for this function:

◆ is_commutative()

def miasm.expression.expression.is_commutative (   expr)

◆ is_expr()

def miasm.expression.expression.is_expr (   expr)
Here is the caller graph for this function:

◆ is_function_call()

def miasm.expression.expression.is_function_call (   expr)
Returns true if the considered Expr is a function call
Here is the caller graph for this function:

◆ match_expr()

def miasm.expression.expression.match_expr (   expr,
  pattern,
  tks,
  result = None 
)
Try to match the @pattern expression with the pattern @expr with @tks jokers.
Result is output dictionary with matching joker values.
@expr : Expr pattern
@pattern : Targeted Expr to match
@tks : list of ExprId, available jokers
@result : dictionary of ExprId -> Expr, output matching context
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MatchExpr()

def miasm.expression.expression.MatchExpr (   expr,
  pattern,
  tks,
  result = None 
)
Here is the call graph for this function:

◆ should_parenthesize_child()

def miasm.expression.expression.should_parenthesize_child (   child,
  parent 
)
Here is the caller graph for this function:

◆ str_protected_child()

def miasm.expression.expression.str_protected_child (   child,
  parent 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_set()

def miasm.expression.expression.test_set (   expr,
  pattern,
  tks,
  result 
)
Test if v can correspond to e. If so, update the context in result.
Otherwise, return False
@expr : Expr to match
@pattern : pattern Expr
@tks : list of ExprId, available jokers
@result : dictionary of ExprId -> Expr, current context
Here is the caller graph for this function:

Variable Documentation

◆ canonize_visitor

miasm.expression.expression.canonize_visitor = ExprVisitorCanonize()

◆ contains_visitor

miasm.expression.expression.contains_visitor = ExprVisitorContains()

◆ EXPR_ORDER_DICT

dictionary miasm.expression.expression.EXPR_ORDER_DICT
Initial value:
1 = {
2  ExprId: 1,
3  ExprLoc: 2,
4  ExprCond: 3,
5  ExprMem: 4,
6  ExprOp: 5,
7  ExprSlice: 6,
8  ExprCompose: 7,
9  ExprInt: 8,
10 }

◆ EXPRASSIGN

int miasm.expression.expression.EXPRASSIGN = 4

◆ EXPRCOMPOSE

int miasm.expression.expression.EXPRCOMPOSE = 9

◆ EXPRCOND

int miasm.expression.expression.EXPRCOND = 5

◆ EXPRID

int miasm.expression.expression.EXPRID = 2

◆ EXPRINT

int miasm.expression.expression.EXPRINT = 1

◆ EXPRLOC

int miasm.expression.expression.EXPRLOC = 3

◆ EXPRMEM

int miasm.expression.expression.EXPRMEM = 6

◆ EXPROP

int miasm.expression.expression.EXPROP = 7

◆ EXPRSLICE

int miasm.expression.expression.EXPRSLICE = 8

◆ priorities

miasm.expression.expression.priorities
Initial value:
1 = dict((op, prio)
2  for prio, l in enumerate(priorities_list)
3  for op in l)

◆ priorities_list

list miasm.expression.expression.priorities_list
Initial value:
1 = [
2  [ '+' ],
3  [ '*', '/', '%' ],
4  [ '**' ],
5  [ '-' ], # Unary '-', associativity with + not handled
6 ]

◆ PRIORITY_MAX

int miasm.expression.expression.PRIORITY_MAX = len(priorities_list) - 1

◆ size_to_IEEE754_info

dictionary miasm.expression.expression.size_to_IEEE754_info
Initial value:
1 = {
2  16: {
3  "exponent": 5,
4  "significand": 10,
5  },
6  32: {
7  "exponent": 8,
8  "significand": 23,
9  },
10  64: {
11  "exponent": 11,
12  "significand": 52,
13  },
14 }

◆ TOK_EQUAL

string miasm.expression.expression.TOK_EQUAL = "=="

◆ TOK_INF

string miasm.expression.expression.TOK_INF = "<"

◆ TOK_INF_EQUAL

string miasm.expression.expression.TOK_INF_EQUAL = "<="

◆ TOK_INF_EQUAL_SIGNED

string miasm.expression.expression.TOK_INF_EQUAL_SIGNED = TOK_INF_EQUAL + "s"

◆ TOK_INF_EQUAL_UNSIGNED

string miasm.expression.expression.TOK_INF_EQUAL_UNSIGNED = TOK_INF_EQUAL + "u"

◆ TOK_INF_SIGNED

string miasm.expression.expression.TOK_INF_SIGNED = TOK_INF + "s"

◆ TOK_INF_UNSIGNED

string miasm.expression.expression.TOK_INF_UNSIGNED = TOK_INF + "u"

◆ TOK_POS

string miasm.expression.expression.TOK_POS = "pos"

◆ TOK_POS_STRICT

string miasm.expression.expression.TOK_POS_STRICT = "Spos"