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

Public Member Functions

def __init__
 
def dstflow
 
def dstflow2label
 
def breakflow
 
def is_subcall
 
def getdstflow
 
def splitflow
 
def get_symbol_size
 
def fixDstOffset
 
def get_args_expr
 
def get_asm_offset
 
def gen_args
 
def __str__
 
def resolve_args_with_symbols
 
def get_info
 

Static Public Member Functions

def arg2str
 

Public Attributes

 name
 
 mode
 
 args
 
 additional_info
 

Static Public Attributes

int delayslot = 0
 

Detailed Description

Definition at line 280 of file arch.py.

Constructor & Destructor Documentation

def miasm2.arch.arm.arch.instruction_arm.__init__ (   self,
  args,
  kargs 
)

Definition at line 283 of file arch.py.

284  def __init__(self, *args, **kargs):
285  super(instruction_arm, self).__init__(*args, **kargs)

Member Function Documentation

def miasm2.core.cpu.instruction.__str__ (   self)
inherited

Definition at line 924 of file cpu.py.

925  def __str__(self):
926  o = "%-10s " % self.name
927  args = []
928  for i, arg in enumerate(self.args):
929  if not isinstance(arg, m2_expr.Expr):
930  raise ValueError('zarb arg type')
931  x = self.arg2str(arg, pos = i)
932  args.append(x)
933  o += self.gen_args(args)
934  return o

+ Here is the call graph for this function:

def miasm2.arch.arm.arch.instruction_arm.arg2str (   e,
  pos = None 
)
static

Definition at line 287 of file arch.py.

288  def arg2str(e, pos = None):
289  wb = False
290  if isinstance(e, ExprId) or isinstance(e, ExprInt):
291  return str(e)
292  if isinstance(e, ExprOp) and e.op in expr2shift_dct:
293  if len(e.args) == 1:
294  return '%s %s' % (e.args[0], expr2shift_dct[e.op])
295  elif len(e.args) == 2:
296  return '%s %s %s' % (e.args[0], expr2shift_dct[e.op], e.args[1])
297  else:
298  raise NotImplementedError('zarb arg2str')
299 
300 
301  sb = False
302  if isinstance(e, ExprOp) and e.op == "sbit":
303  sb = True
304  e = e.args[0]
305  if isinstance(e, ExprOp) and e.op == "reglist":
306  o = [gpregs.expr.index(x) for x in e.args]
307  out = reglist2str(o)
308  if sb:
309  out += "^"
310  return out
311 
312 
313  if isinstance(e, ExprOp) and e.op == 'wback':
314  wb = True
315  e = e.args[0]
316  if isinstance(e, ExprId):
317  out = str(e)
318  if wb:
319  out += "!"
320  return out
321 
322  if not isinstance(e, ExprMem):
323  return str(e)
324 
325  e = e.arg
326  if isinstance(e, ExprOp) and e.op == 'wback':
327  wb = True
328  e = e.args[0]
329 
330 
331  if isinstance(e, ExprId):
332  r, s = e, None
333  elif len(e.args) == 1 and isinstance(e.args[0], ExprId):
334  r, s = e.args[0], None
335  elif isinstance(e.args[0], ExprId):
336  r, s = e.args[0], e.args[1]
337  else:
338  r, s = e.args[0].args
339  if isinstance(s, ExprOp) and s.op in expr2shift_dct:
340  s = ' '.join([str(x)
341  for x in s.args[0], expr2shift_dct[s.op], s.args[1]])
342 
343  if isinstance(e, ExprOp) and e.op == 'postinc':
344  o = '[%s]' % r
345  if s and not (isinstance(s, ExprInt) and s.arg == 0):
346  o += ', %s' % s
347  else:
348  if s and not (isinstance(s, ExprInt) and s.arg == 0):
349  o = '[%s, %s]' % (r, s)
350  else:
351  o = '[%s]' % (r)
352 
353 
354  if wb:
355  o += "!"
356  return o
357 

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.arch.arm.arch.instruction_arm.breakflow (   self)

Definition at line 373 of file arch.py.

374  def breakflow(self):
375  if self.name in conditional_branch + unconditional_branch:
376  return True
377  if self.name.startswith("LDM") and PC in self.args[1].args:
378  return True
379  if self.args and PC in self.args[0].get_r():
380  return True
381  return False

+ Here is the caller graph for this function:

def miasm2.arch.arm.arch.instruction_arm.dstflow (   self)

Definition at line 358 of file arch.py.

359  def dstflow(self):
360  return self.name in conditional_branch + unconditional_branch
def miasm2.arch.arm.arch.instruction_arm.dstflow2label (   self,
  symbol_pool 
)

Definition at line 361 of file arch.py.

362  def dstflow2label(self, symbol_pool):
363  e = self.args[0]
364  if not isinstance(e, ExprInt):
365  return
366  if self.name == 'BLX':
367  ad = e.arg + self.offset
368  else:
369  ad = e.arg + self.offset
370  l = symbol_pool.getby_offset_create(ad)
371  s = ExprId(l, e.size)
372  self.args[0] = s
def miasm2.arch.arm.arch.instruction_arm.fixDstOffset (   self)

Definition at line 402 of file arch.py.

403  def fixDstOffset(self):
404  e = self.args[0]
405  if self.offset is None:
406  raise ValueError('symbol not resolved %s' % l)
407  if not isinstance(e, ExprInt):
408  log.debug('dyn dst %r', e)
409  return
410  off = e.arg - self.offset
411  if int(off % 4):
412  raise ValueError('strange offset! %r' % off)
413  self.args[0] = ExprInt32(off)

+ Here is the call graph for this function:

def miasm2.core.cpu.instruction.gen_args (   self,
  args 
)
inherited

Definition at line 920 of file cpu.py.

921  def gen_args(self, args):
922  out = ', '.join([str(x) for x in args])
923  return out

+ Here is the caller graph for this function:

def miasm2.arch.arm.arch.instruction_arm.get_args_expr (   self)

Definition at line 414 of file arch.py.

415  def get_args_expr(self):
416  args = [a for a in self.args]
417  return args
def miasm2.arch.arm.arch.instruction_arm.get_asm_offset (   self,
  expr 
)

Definition at line 418 of file arch.py.

419  def get_asm_offset(self, expr):
420  # LDR XXX, [PC, offset] => PC is self.offset+8
421  return ExprInt_from(expr, self.offset+8)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.core.cpu.instruction.get_info (   self,
  c 
)
inherited

Definition at line 975 of file cpu.py.

976  def get_info(self, c):
977  return
978 
def miasm2.arch.arm.arch.instruction_arm.get_symbol_size (   self,
  symbol,
  symbol_pool 
)

Definition at line 399 of file arch.py.

400  def get_symbol_size(self, symbol, symbol_pool):
401  return 32

+ Here is the caller graph for this function:

def miasm2.arch.arm.arch.instruction_arm.getdstflow (   self,
  symbol_pool 
)

Definition at line 387 of file arch.py.

388  def getdstflow(self, symbol_pool):
389  return [self.args[0]]

+ Here is the caller graph for this function:

def miasm2.arch.arm.arch.instruction_arm.is_subcall (   self)

Definition at line 382 of file arch.py.

383  def is_subcall(self):
384  if self.name == 'BLX':
385  return True
386  return self.additional_info.lnk
def miasm2.core.cpu.instruction.resolve_args_with_symbols (   self,
  symbols = None 
)
inherited

Definition at line 938 of file cpu.py.

939  def resolve_args_with_symbols(self, symbols=None):
940  if symbols is None:
941  symbols = {}
942  args_out = []
943  for a in self.args:
944  e = a
945  # try to resolve symbols using symbols (0 for default value)
946  ids = m2_expr.get_expr_ids(e)
947  fixed_ids = {}
948  for x in ids:
949  if isinstance(x.name, asmbloc.asm_label):
950  name = x.name.name
951  # special symbol $
952  if name == '$':
953  fixed_ids[x] = self.get_asm_offset(x)
954  continue
955  if not name in symbols:
956  raise ValueError('unresolved symbol! %r' % x)
957  else:
958  name = x.name
959  if not name in symbols:
960  continue
961  if symbols[name].offset is None:
962  raise ValueError('The offset of label "%s" cannot be '
963  'determined' % name)
964  else:
965  size = x.size
966  if size is None:
967  default_size = self.get_symbol_size(x, symbols)
968  size = default_size
969  value = m2_expr.ExprInt(symbols[name].offset, size)
970  fixed_ids[x] = value
971  e = e.replace_expr(fixed_ids)
972  e = expr_simp(e)
973  args_out.append(e)
974  return args_out

+ Here is the call graph for this function:

def miasm2.arch.arm.arch.instruction_arm.splitflow (   self)

Definition at line 390 of file arch.py.

391  def splitflow(self):
392  if self.additional_info.lnk:
393  return True
394  if self.name == 'BLX':
395  return True
396  if self.name == 'BX':
397  return False
398  return self.breakflow() and self.additional_info.cond != 14

+ Here is the call graph for this function:

Member Data Documentation

miasm2.core.cpu.instruction.additional_info
inherited

Definition at line 918 of file cpu.py.

miasm2.core.cpu.instruction.args
inherited

Definition at line 917 of file cpu.py.

int miasm2.arch.arm.arch.instruction_arm.delayslot = 0
static

Definition at line 281 of file arch.py.

miasm2.core.cpu.instruction.mode
inherited

Definition at line 916 of file cpu.py.

miasm2.arch.arm.arch.instruction_arm.name

Definition at line 365 of file arch.py.


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