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

Public Member Functions

def str_to_imm_rot_form
 
def decode
 
def encode
 
def fromstring
 

Public Attributes

 expr
 
 value
 

Static Public Attributes

 parser = deref
 

Detailed Description

Definition at line 994 of file arch.py.

Member Function Documentation

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

Definition at line 1004 of file arch.py.

1005  def decode(self, v):
1006  val = v & self.lmask
1007  if self.parent.immop.value == 0:
1008  imm = val
1009  if self.parent.updown.value == 0:
1010  imm = -imm
1011  if self.parent.ppi.value:
1012  e = ExprOp('preinc', self.parent.rn.expr, ExprInt32(imm))
1013  else:
1014  e = ExprOp('postinc', self.parent.rn.expr, ExprInt32(imm))
1015  if self.parent.wback.value == 1:
1016  e = ExprOp('wback', e)
1017  self.expr = ExprMem(e)
1018  return True
1019  rm = val & 0xf
1020  shift = val >> 4
1021  shift_kind = shift & 1
1022  shift_type = (shift >> 1) & 3
1023  shift >>= 3
1024  # print self.parent.immop.value, hex(shift), hex(shift_kind),
1025  # hex(shift_type)
1026  if shift_kind:
1027  # log.debug('error in disasm xx')
1028  return False
1029  else:
1030  # shift kind is imm
1031  amount = shift
1032  shift_op = ExprInt32(amount)
1033  a = regs_expr[rm]
1034  if shift_op == ExprInt32(0):
1035  pass
1036  else:
1037  a = ExprOp(allshifts[shift_type], a, shift_op)
1038  if self.parent.ppi.value:
1039  e = ExprOp('preinc', self.parent.rn.expr, a)
1040  else:
1041  e = ExprOp('postinc', self.parent.rn.expr, a)
1042  if self.parent.wback.value == 1:
1043  e = ExprOp('wback', e)
1044  self.expr = ExprMem(e)
1045  return True

+ Here is the call graph for this function:

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

Definition at line 1046 of file arch.py.

1047  def encode(self):
1048  self.parent.immop.value = 1
1049  self.parent.updown.value = 1
1050 
1051  e = self.expr
1052  assert(isinstance(e, ExprMem))
1053  e = e.arg
1054  if e.op == 'wback':
1055  self.parent.wback.value = 1
1056  e = e.args[0]
1057  else:
1058  self.parent.wback.value = 0
1059  if e.op == "postinc":
1060  self.parent.ppi.value = 0
1061  elif e.op == "preinc":
1062  self.parent.ppi.value = 1
1063  else:
1064  # XXX default
1065  self.parent.ppi.value = 1
1066 
1067  # if len(v) <1:
1068  # raise ValueError('cannot parse', s)
1069  self.parent.rn.fromstring(e.args[0])
1070  if len(e.args) == 1:
1071  self.parent.immop.value = 0
1072  self.value = 0
1073  return True
1074  # pure imm
1075  if isinstance(e.args[1], ExprInt):
1076  self.parent.immop.value = 0
1077  val = self.str_to_imm_rot_form(int(e.args[1].arg))
1078  if val is None:
1079  val = self.str_to_imm_rot_form(int(e.args[1].arg), True)
1080  if val is None:
1081  log.debug('cannot encode inm')
1082  return False
1083  self.parent.updown.value = 0
1084  self.value = val
1085  return True
1086  # pure reg
1087  if isinstance(e.args[1], ExprId):
1088  rm = gpregs.expr.index(e.args[1])
1089  shift_kind = 0
1090  shift_type = 0
1091  amount = 0
1092  self.value = (
1093  ((((amount << 2) | shift_type) << 1) | shift_kind) << 4) | rm
1094  return True
1095  # rot reg
1096  if not isinstance(e.args[1], ExprOp):
1097  log.debug('bad reg rot2 %r', e)
1098  return False
1099  e = e.args[1]
1100  rm = gpregs.expr.index(e.args[0])
1101  shift_type = allshifts.index(e.op)
1102  if isinstance(e.args[1], ExprInt):
1103  shift_kind = 0
1104  amount = int(e.args[1].arg)
1105  else:
1106  shift_kind = 1
1107  amount = gpregs.expr.index(e.args[1]) << 1
1108  self.value = (
1109  ((((amount << 2) | shift_type) << 1) | shift_kind) << 4) | rm
1110  return True
1111 
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_op2imm.str_to_imm_rot_form (   self,
  s,
  neg = False 
)

Definition at line 997 of file arch.py.

998  def str_to_imm_rot_form(self, s, neg=False):
999  if neg:
1000  s = -s & 0xffffffff
1001  if 0 <= s < (1 << 12):
1002  return s
1003  return None

Member Data Documentation

miasm2.arch.arm.arch.arm_op2imm.expr

Definition at line 1016 of file arch.py.

miasm2.arch.arm.arch.arm_op2imm.parser = deref
static

Definition at line 995 of file arch.py.

miasm2.arch.arm.arch.arm_op2imm.value

Definition at line 1071 of file arch.py.


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