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

Public Member Functions

def __init__
 
def __str__
 
def get_r
 
def get_w
 
def __contains__
 
def visit
 
def copy
 
def depth
 
def graph_recursive
 
def set_size
 
def __getitem__
 
def get_size
 
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 replace_expr
 
def canonize
 
def msb
 
def zeroExtend
 
def signExtend
 
def graph
 
def set_mask
 

Public Attributes

 arg
 

Static Public Attributes

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

Properties

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

Private Member Functions

def _exprhash
 
def _exprrepr
 

Private Attributes

 _args
 
 _size
 

Detailed Description

Compose is like a hambuger.
It's arguments are tuple of:  (Expression, start, stop)
start and stop are intergers, determining Expression position in the compose.

Burger Example:
ExprCompose([(salad, 0, 3), (cheese, 3, 10), (beacon, 10, 16)])
In the example, salad.size == 3.

Definition at line 938 of file expression.py.

Constructor & Destructor Documentation

def miasm2.expression.expression.ExprCompose.__init__ (   self,
  args 
)
Create an ExprCompose
The ExprCompose is contiguous and starts at 0
@args: tuple(Expr, int, int)

Definition at line 950 of file expression.py.

951  def __init__(self, args):
952  """Create an ExprCompose
953  The ExprCompose is contiguous and starts at 0
954  @args: tuple(Expr, int, int)
955  """
956 
957  last_stop = 0
958  args = sorted(args, key=itemgetter(1))
959  for e, start, stop in args:
960  if e.size != stop - start:
961  raise ValueError(
962  "sanitycheck: ExprCompose args must have correct size!" +
963  " %r %r %r" % (e, e.size, stop - start))
964  if last_stop != start:
965  raise ValueError(
966  "sanitycheck: ExprCompose args must be contiguous!" +
967  " %r" % (args))
968  last_stop = stop
969 
970  # Transform args to lists
971  o = []
972  for e, a, b in args:
973  assert(a >= 0 and b >= 0)
974  o.append(tuple([e, a, b]))
975  self._args = tuple(o)
977  self._size = self._args[-1][2]

Member Function Documentation

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

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 
)
inherited

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.ExprCompose.__contains__ (   self,
  e 
)

Definition at line 1000 of file expression.py.

1001  def __contains__(self, e):
1002  if self == e:
1003  return True
1004  for arg in self._args:
1005  if arg == e:
1006  return True
1007  if arg[0].__contains__(e):
1008  return True
1009  return False
def miasm2.expression.expression.Expr.__div__ (   self,
  a 
)
inherited

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 
)
inherited

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 
)
inherited

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)
inherited

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)
inherited

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 
)
inherited

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 
)
inherited

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 
)
inherited

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 
)
inherited

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)
inherited

Definition at line 222 of file expression.py.

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

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)
inherited

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 
)
inherited

Definition at line 210 of file expression.py.

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

Definition at line 980 of file expression.py.

981  def __str__(self):
982  return '{' + ', '.join(['%s,%d,%d' %
983  (str(arg[0]), arg[1], arg[2]) for arg in self._args]) + '}'
def miasm2.expression.expression.Expr.__sub__ (   self,
  a 
)
inherited

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 
)
inherited

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.ExprCompose._exprhash (   self)
private

Definition at line 992 of file expression.py.

993  def _exprhash(self):
994  h_args = [EXPRCOMPOSE] + [(hash(arg[0]), arg[1], arg[2])
995  for arg in self._args]
996  return hash(tuple(h_args))

+ Here is the caller graph for this function:

def miasm2.expression.expression.ExprCompose._exprrepr (   self)
private

Definition at line 997 of file expression.py.

998  def _exprrepr(self):
999  return "%s(%r)" % (self.__class__.__name__, self._args)

+ Here is the caller graph for this function:

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

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.ExprCompose.copy (   self)

Definition at line 1018 of file expression.py.

1019  def copy(self):
1020  args = [(arg[0].copy(), arg[1], arg[2]) for arg in self._args]
1021  return ExprCompose(args)
def miasm2.expression.expression.ExprCompose.depth (   self)

Definition at line 1022 of file expression.py.

1023  def depth(self):
1024  depth = [arg[0].depth() for arg in self._args]
1025  return max(depth) + 1
def miasm2.expression.expression.ExprCompose.get_r (   self,
  mem_read = False,
  cst_read = False 
)

Definition at line 984 of file expression.py.

985  def get_r(self, mem_read=False, cst_read=False):
986  return reduce(lambda elements, arg:
987  elements.union(arg[0].get_r(mem_read, cst_read)), self._args, set())
def miasm2.expression.expression.Expr.get_size (   self)
inherited

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.ExprCompose.get_w (   self)

Definition at line 988 of file expression.py.

989  def get_w(self):
990  return reduce(lambda elements, arg:
991  elements.union(arg[0].get_w()), self._args, set())
def miasm2.expression.expression.Expr.graph (   self)
inherited
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.ExprCompose.graph_recursive (   self,
  graph 
)

Definition at line 1026 of file expression.py.

1027  def graph_recursive(self, graph):
1028  graph.add_node(self)
1029  for arg in self.args:
1030  arg[0].graph_recursive(graph)
1031  graph.add_uniq_edge(self, arg[0])
1032 
1033 
# Expression order for comparaison
def miasm2.expression.expression.Expr.is_function_call (   self)
inherited
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)
inherited

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 
)
inherited
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 
)
inherited
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 
)
inherited

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 
)
inherited

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 
)
inherited
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.ExprCompose.visit (   self,
  cb,
  tv = None 
)

Definition at line 1011 of file expression.py.

1012  def visit(self, cb, tv=None):
1013  args = [(arg[0].visit(cb, tv), arg[1], arg[2]) for arg in self._args]
1014  modified = any([arg[0] != arg[1] for arg in zip(self._args, args)])
1015  if modified:
1016  return ExprCompose(args)
1017  return self

+ Here is the caller graph for this function:

def miasm2.expression.expression.Expr.zeroExtend (   self,
  size 
)
inherited
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.ExprCompose._args
private

Definition at line 974 of file expression.py.

miasm2.expression.expression.ExprCompose._size
private

Definition at line 976 of file expression.py.

miasm2.expression.expression.Expr.arg
inherited

Definition at line 129 of file expression.py.

miasm2.expression.expression.Expr.is_canon = False
staticinherited

Definition at line 119 of file expression.py.

miasm2.expression.expression.Expr.is_eval = False
staticinherited

Definition at line 120 of file expression.py.

miasm2.expression.expression.Expr.is_simp = False
staticinherited

Definition at line 118 of file expression.py.

miasm2.expression.expression.Expr.is_term = False
staticinherited

Definition at line 117 of file expression.py.

Property Documentation

miasm2.expression.expression.ExprCompose.args = property(lambda self: self._args)
static

Definition at line 978 of file expression.py.

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

Definition at line 333 of file expression.py.

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

Definition at line 131 of file expression.py.


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