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_armt Class Reference
+ Inheritance diagram for miasm2.arch.arm.arch.instruction_armt:
+ Collaboration diagram for miasm2.arch.arm.arch.instruction_armt:

Public Member Functions

def __init__
 
def dstflow
 
def dstflow2label
 
def breakflow
 
def getdstflow
 
def splitflow
 
def is_subcall
 
def fixDstOffset
 
def get_asm_offset
 
def get_symbol_size
 
def get_args_expr
 
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 422 of file arch.py.

Constructor & Destructor Documentation

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

Definition at line 424 of file arch.py.

425  def __init__(self, *args, **kargs):
426  super(instruction_armt, 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 
)
staticinherited

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_armt.breakflow (   self)

Definition at line 450 of file arch.py.

451  def breakflow(self):
452  if self.name in conditional_branch + unconditional_branch +["CBZ", "CBNZ"]:
453  return True
454  if self.name.startswith("LDM") and PC in self.args[1].args:
455  return True
456  if self.args and PC in self.args[0].get_r():
457  return True
458  return False
def miasm2.arch.arm.arch.instruction_armt.dstflow (   self)

Definition at line 427 of file arch.py.

428  def dstflow(self):
429  if self.name in ["CBZ", "CBNZ"]:
430  return True
431  return self.name in conditional_branch + unconditional_branch
def miasm2.arch.arm.arch.instruction_armt.dstflow2label (   self,
  symbol_pool 
)

Definition at line 432 of file arch.py.

433  def dstflow2label(self, symbol_pool):
434  if self.name in ["CBZ", "CBNZ"]:
435  e = self.args[1]
436  else:
437  e = self.args[0]
438  if not isinstance(e, ExprInt):
439  return
440  if self.name == 'BLX':
441  ad = e.arg + (self.offset & 0xfffffffc)
442  else:
443  ad = e.arg + self.offset
444  l = symbol_pool.getby_offset_create(ad)
445  s = ExprId(l, e.size)
446  if self.name in ["CBZ", "CBNZ"]:
447  self.args[1] = s
448  else:
449  self.args[0] = s
def miasm2.arch.arm.arch.instruction_armt.fixDstOffset (   self)

Definition at line 472 of file arch.py.

473  def fixDstOffset(self):
474  e = self.args[0]
475  if self.offset is None:
476  raise ValueError('symbol not resolved %s' % l)
477  if not isinstance(e, ExprInt):
478  log.debug('dyn dst %r', e)
479  return
480  # The first +2 is to compensate instruction len, but strangely, 32 bits
481  # thumb2 instructions len is 2... For the second +2, didn't find it in
482  # the doc.
483  off = e.arg - self.offset
484  if int(off % 2):
485  raise ValueError('strange offset! %r' % off)
486  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)
inherited

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_armt.get_asm_offset (   self,
  expr 
)

Definition at line 487 of file arch.py.

488  def get_asm_offset(self, expr):
489  # ADR XXX, PC, imm => PC is 4 aligned + imm
490  new_offset = ((self.offset+self.l)/4)*4
491  return ExprInt_from(expr, new_offset)
492 

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

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_armt.getdstflow (   self,
  symbol_pool 
)

Definition at line 459 of file arch.py.

460  def getdstflow(self, symbol_pool):
461  if self.name in ['CBZ', 'CBNZ']:
462  return [self.args[1]]
463  return [self.args[0]]

+ Here is the caller graph for this function:

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

Definition at line 469 of file arch.py.

470  def is_subcall(self):
471  return self.name in ['BL', 'BLX']
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_armt.splitflow (   self)

Definition at line 464 of file arch.py.

465  def splitflow(self):
466  if self.name in conditional_branch + ['BL', 'BLX', 'CBZ', 'CBNZ']:
467  return True
468  return False

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
staticinherited

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_armt.name

Definition at line 439 of file arch.py.


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