Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Public Attributes | Static Public Attributes | Properties | Static Private Attributes | List of all members
miasm2.expression.expression.Expr Class Reference
+ Inheritance diagram for miasm2.expression.expression.Expr:
+ Collaboration diagram for miasm2.expression.expression.Expr:

Public Member Functions

def set_size
 
def __init__
 
def __str__
 
def __getitem__
 
def get_size
 
def get_r
 
def get_w
 
def is_function_call
 
def __repr__
 
def __hash__
 
def pre_eq
 
def __eq__
 
def __ne__
 
def __add__
 
def __sub__
 
def __div__
 
def __mod__
 
def __mul__
 
def __lshift__
 
def __rshift__
 
def __xor__
 
def __or__
 
def __and__
 
def __neg__
 
def __invert__
 
def copy
 
def replace_expr
 
def canonize
 
def msb
 
def zeroExtend
 
def signExtend
 
def graph_recursive
 
def graph
 
def set_mask
 

Public Attributes

 arg
 

Static Public Attributes

 is_term = False
 
 is_simp = False
 
 is_canon = False
 
 is_eval = False
 

Properties

 size = property(lambda self: self._size)
 
 mask = property(lambda self: ExprInt(-1, self.size))
 

Static Private Attributes

 _hash = None
 
 _repr = None
 

Detailed Description

Definition at line 113 of file expression.py.

Constructor & Destructor Documentation

def miasm2.expression.expression.Expr.__init__ (   self,
  arg 
)

Definition at line 128 of file expression.py.

129  def __init__(self, arg):
130  self.arg = arg

Member Function Documentation

def miasm2.expression.expression.Expr.__add__ (   self,
  a 
)

Definition at line 192 of file expression.py.

193  def __add__(self, a):
194  return ExprOp('+', self, a)

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.__and__ (   self,
  a 
)

Definition at line 219 of file expression.py.

220  def __and__(self, a):
221  return ExprOp('&', self, a)

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.__div__ (   self,
  a 
)

Definition at line 198 of file expression.py.

199  def __div__(self, a):
200  return ExprOp('/', self, a)
def miasm2.expression.expression.Expr.__eq__ (   self,
  other 
)

Definition at line 183 of file expression.py.

184  def __eq__(self, other):
185  res = self.pre_eq(other)
186  if res is not None:
187  return res
188  return repr(self) == repr(other)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.__getitem__ (   self,
  i 
)

Definition at line 138 of file expression.py.

139  def __getitem__(self, i):
140  if not isinstance(i, slice):
141  raise TypeError("Expression: Bad slice: %s" % i)
142  start, stop, step = i.indices(self.size)
143  if step != 1:
144  raise ValueError("Expression: Bad slice: %s" % i)
145  return ExprSlice(self, start, stop)
def miasm2.expression.expression.Expr.__hash__ (   self)

Definition at line 165 of file expression.py.

166  def __hash__(self):
167  if self._hash is None:
168  self._hash = self._exprhash()
169  return self._hash

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.__invert__ (   self)

Definition at line 225 of file expression.py.

226  def __invert__(self):
227  s = self.size
228  return ExprOp('^', self, ExprInt(mod_size2uint[s](size2mask(s))))

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.__lshift__ (   self,
  a 
)

Definition at line 207 of file expression.py.

208  def __lshift__(self, a):
209  return ExprOp('<<', self, a)
def miasm2.expression.expression.Expr.__mod__ (   self,
  a 
)

Definition at line 201 of file expression.py.

202  def __mod__(self, a):
203  return ExprOp('%', self, a)
def miasm2.expression.expression.Expr.__mul__ (   self,
  a 
)

Definition at line 204 of file expression.py.

205  def __mul__(self, a):
206  return ExprOp('*', self, a)

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.__ne__ (   self,
  a 
)

Definition at line 189 of file expression.py.

190  def __ne__(self, a):
191  return not self.__eq__(a)

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.__neg__ (   self)

Definition at line 222 of file expression.py.

223  def __neg__(self):
224  return ExprOp('-', self)
def miasm2.expression.expression.Expr.__or__ (   self,
  a 
)

Definition at line 216 of file expression.py.

217  def __or__(self, a):
218  return ExprOp('|', self, a)

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.__repr__ (   self)

Definition at line 160 of file expression.py.

161  def __repr__(self):
162  if self._repr is None:
163  self._repr = self._exprrepr()
164  return self._repr

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.__rshift__ (   self,
  a 
)

Definition at line 210 of file expression.py.

211  def __rshift__(self, a):
212  return ExprOp('>>', self, a)
def miasm2.expression.expression.Expr.__str__ (   self)

Definition at line 135 of file expression.py.

136  def __str__(self):
137  return str(self.arg)
def miasm2.expression.expression.Expr.__sub__ (   self,
  a 
)

Definition at line 195 of file expression.py.

196  def __sub__(self, a):
197  return ExprOp('+', self, ExprOp('-', a))
def miasm2.expression.expression.Expr.__xor__ (   self,
  a 
)

Definition at line 213 of file expression.py.

214  def __xor__(self, a):
215  return ExprOp('^', self, a)

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.canonize (   self)

Definition at line 247 of file expression.py.

248  def canonize(self):
249  "Canonize the Expression"
250 
251  def must_canon(e):
252  return not e.is_canon
253 
254  def canonize_visitor(e):
255  if e.is_canon:
256  return e
257  if isinstance(e, ExprOp):
258  if e.is_associative():
259  # ((a+b) + c) => (a + b + c)
260  args = []
261  for arg in e.args:
262  if isinstance(arg, ExprOp) and e.op == arg.op:
263  args += arg.args
264  else:
265  args.append(arg)
266  args = canonize_expr_list(args)
267  new_e = ExprOp(e.op, *args)
268  else:
269  new_e = e
270  elif isinstance(e, ExprCompose):
271  new_e = ExprCompose(canonize_expr_list_compose(e.args))
272  else:
273  new_e = e
274  new_e.is_canon = True
275  return new_e
276 
277  return self.visit(canonize_visitor, must_canon)

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.copy (   self)

Definition at line 229 of file expression.py.

230  def copy(self):
231  "Deep copy of the expression"
232  return self.visit(lambda x: x)

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.get_r (   self,
  mem_read = False,
  cst_read = False 
)

Definition at line 149 of file expression.py.

150  def get_r(self, mem_read=False, cst_read=False):
151  return self.arg.get_r(mem_read, cst_read)
def miasm2.expression.expression.Expr.get_size (   self)

Definition at line 146 of file expression.py.

147  def get_size(self):
148  raise DeprecationWarning("use X.size instead of X.get_size()")
def miasm2.expression.expression.Expr.get_w (   self)

Definition at line 152 of file expression.py.

153  def get_w(self):
154  return self.arg.get_w()
def miasm2.expression.expression.Expr.graph (   self)
Return a DiGraph instance standing for Expr tree
Instance's display functions have been override for better visibility
Wrapper on graph_recursive

Definition at line 319 of file expression.py.

320  def graph(self):
321  """Return a DiGraph instance standing for Expr tree
322  Instance's display functions have been override for better visibility
323  Wrapper on graph_recursive"""
324 
325  # Create recursively the graph
326  graph = DiGraphExpr()
327  self.graph_recursive(graph)
328 
329  return graph

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.graph_recursive (   self,
  graph 
)
Recursive method used by graph
@graph: miasm2.core.graph.DiGraph instance
Update @graph instance to include sons
This is an Abstract method

Definition at line 311 of file expression.py.

312  def graph_recursive(self, graph):
313  """Recursive method used by graph
314  @graph: miasm2.core.graph.DiGraph instance
315  Update @graph instance to include sons
316  This is an Abstract method"""
317 
318  raise ValueError("Abstract method")

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.is_function_call (   self)
Returns true if the considered Expr is a function call

Definition at line 155 of file expression.py.

156  def is_function_call(self):
157  """Returns true if the considered Expr is a function call
158  """
159  return False
def miasm2.expression.expression.Expr.msb (   self)

Definition at line 278 of file expression.py.

279  def msb(self):
280  "Return the Most Significant Bit"
281  s = self.size
282  return self[s - 1:s]

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.pre_eq (   self,
  other 
)
Return True if ids are equal;
False if instances are obviously not equal
None if we cannot simply decide

Definition at line 170 of file expression.py.

171  def pre_eq(self, other):
172  """Return True if ids are equal;
173  False if instances are obviously not equal
174  None if we cannot simply decide"""
175 
176  if id(self) == id(other):
177  return True
178  if self.__class__ is not other.__class__:
179  return False
180  if hash(self) != hash(other):
181  return False
182  return None

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.replace_expr (   self,
  dct = None 
)
Find and replace sub expression using dct
@dct: dictionnary of Expr -> *

Definition at line 233 of file expression.py.

234  def replace_expr(self, dct=None):
235  """Find and replace sub expression using dct
236  @dct: dictionnary of Expr -> *
237  """
238  if dct is None:
239  dct = {}
240 
241  def my_replace(e, dct):
242  if e in dct:
243  return dct[e]
244  return e
245 
246  return self.visit(lambda e: my_replace(e, dct))

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.set_mask (   self,
  value 
)

Definition at line 330 of file expression.py.

331  def set_mask(self, value):
332  raise ValueError('mask is not mutable')
def miasm2.expression.expression.Expr.set_size (   self,
  value 
)

Definition at line 125 of file expression.py.

126  def set_size(self, value):
127  raise ValueError('size is not mutable')
def miasm2.expression.expression.Expr.signExtend (   self,
  size 
)
Sign extend to size
@size: int

Definition at line 295 of file expression.py.

296  def signExtend(self, size):
297  """Sign extend to size
298  @size: int
299  """
300  assert(self.size <= size)
301  if self.size == size:
302  return self
303  ad_size = size - self.size
304  c = ExprCompose([(self, 0, self.size),
305  (ExprCond(self.msb(),
306  ExprInt(size2mask(ad_size), ad_size),
307  ExprInt(0, ad_size)),
308  self.size, size)
309  ])
310  return c

+ Here is the call graph for this function:

def miasm2.expression.expression.Expr.zeroExtend (   self,
  size 
)
Zero extend to size
@size: int

Definition at line 283 of file expression.py.

284  def zeroExtend(self, size):
285  """Zero extend to size
286  @size: int
287  """
288  assert(self.size <= size)
289  if self.size == size:
290  return self
291  ad_size = size - self.size
292  n = ExprInt(0, ad_size)
293  return ExprCompose([(self, 0, self.size),
294  (n, self.size, size)])

Member Data Documentation

miasm2.expression.expression.Expr._hash = None
staticprivate

Definition at line 122 of file expression.py.

miasm2.expression.expression.Expr._repr = None
staticprivate

Definition at line 123 of file expression.py.

miasm2.expression.expression.Expr.arg

Definition at line 129 of file expression.py.

miasm2.expression.expression.Expr.is_canon = False
static

Definition at line 119 of file expression.py.

miasm2.expression.expression.Expr.is_eval = False
static

Definition at line 120 of file expression.py.

miasm2.expression.expression.Expr.is_simp = False
static

Definition at line 118 of file expression.py.

miasm2.expression.expression.Expr.is_term = False
static

Definition at line 117 of file expression.py.

Property Documentation

miasm2.expression.expression.Expr.mask = property(lambda self: ExprInt(-1, self.size))
static

Definition at line 333 of file expression.py.

miasm2.expression.expression.Expr.size = property(lambda self: self._size)
static

Definition at line 131 of file expression.py.


The documentation for this class was generated from the following file: