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

Public Member Functions

def str_to_imm_rot_form
 
def decode
 
def encode
 
def fromstring
 

Public Attributes

 expr
 
 value
 

Static Public Attributes

 parser = shift_off
 

Detailed Description

Definition at line 896 of file arch.py.

Member Function Documentation

def miasm2.arch.arm.arch.arm_op2.decode (   self,
  v 
)

Definition at line 908 of file arch.py.

909  def decode(self, v):
910  val = v & self.lmask
911  if self.parent.immop.value:
912  rot = val >> 8
913  imm = val & 0xff
914  imm = myror32(imm, rot * 2)
915  self.expr = ExprInt32(imm)
916  return True
917  rm = val & 0xf
918  shift = val >> 4
919  shift_kind = shift & 1
920  shift_type = (shift >> 1) & 3
921  shift >>= 3
922  # print self.parent.immop.value, hex(shift), hex(shift_kind),
923  # hex(shift_type)
924  if shift_kind:
925  # shift kind is reg
926  if shift & 1:
927  # log.debug('error in shift1')
928  return False
929  rs = shift >> 1
930  if rs == 0xf:
931  # log.debug('error in shift2')
932  return False
933  shift_op = regs_expr[rs]
934  else:
935  # shift kind is imm
936  amount = shift
937  shift_op = ExprInt32(amount)
938  a = regs_expr[rm]
939  if shift_op == ExprInt32(0):
940  if shift_type == 3:
941  self.expr = ExprOp(allshifts[4], a)
942  else:
943  self.expr = a
944  else:
945  self.expr = ExprOp(allshifts[shift_type], a, shift_op)
946  return True
def myror32
Definition: cpu.py:345

+ Here is the call graph for this function:

def miasm2.arch.arm.arch.arm_op2.encode (   self)

Definition at line 947 of file arch.py.

948  def encode(self):
949  e = self.expr
950  # pure imm
951  if isinstance(e, ExprInt):
952  val = self.str_to_imm_rot_form(int(e.arg))
953  if val is None:
954  return False
955  self.parent.immop.value = 1
956  self.value = val
957  return True
958 
959  self.parent.immop.value = 0
960  # pure reg
961  if isinstance(e, ExprId):
962  rm = gpregs.expr.index(e)
963  shift_kind = 0
964  shift_type = 0
965  amount = 0
966  self.value = (
967  ((((amount << 2) | shift_type) << 1) | shift_kind) << 4) | rm
968  return True
969  # rot reg
970  if not isinstance(e, ExprOp):
971  log.debug('bad reg rot1 %r', e)
972  return False
973  rm = gpregs.expr.index(e.args[0])
974  shift_type = allshifts.index(e.op)
975  if e.op == 'rrx':
976  shift_kind = 0
977  amount = 0
978  shift_type = 3
979  elif isinstance(e.args[1], ExprInt):
980  shift_kind = 0
981  amount = int(e.args[1].arg)
982  # LSR/ASR of 32 => 0
983  if amount == 32 and e.op in ['>>', 'a>>']:
984  amount = 0
985  else:
986  shift_kind = 1
987  amount = gpregs.expr.index(e.args[1]) << 1
988  self.value = (
989  ((((amount << 2) | shift_type) << 1) | shift_kind) << 4) | rm
990  return True
991 
992 # op2imm + rn
993 

+ Here is the call graph for this function:

def miasm2.core.cpu.m_arg.fromstring (   self,
  s,
  parser_result = None 
)
inherited

Definition at line 604 of file cpu.py.

605  def fromstring(self, s, parser_result=None):
606  if parser_result:
607  e, start, stop = parser_result[self.parser]
608  self.expr = e
609  return start, stop
610  try:
611  v, start, stop = self.parser.scanString(s).next()
612  except StopIteration:
613  return None, None
614  self.expr = v[0]
615  return start, stop
616 

+ Here is the call graph for this function:

def miasm2.arch.arm.arch.arm_op2.str_to_imm_rot_form (   self,
  s,
  neg = False 
)

Definition at line 899 of file arch.py.

900  def str_to_imm_rot_form(self, s, neg=False):
901  if neg:
902  s = -s & 0xffffffff
903  for i in xrange(0, 32, 2):
904  v = myrol32(s, i)
905  if 0 <= v < 0x100:
906  return ((i / 2) << 8) | v
907  return None
def myrol32
Definition: cpu.py:349

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

miasm2.arch.arm.arch.arm_op2.expr

Definition at line 914 of file arch.py.

miasm2.arch.arm.arch.arm_op2.parser = shift_off
static

Definition at line 897 of file arch.py.

miasm2.arch.arm.arch.arm_op2.value

Definition at line 955 of file arch.py.


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