Rizin
unix-like reverse engineering framework and cli tools
test_arm Namespace Reference

Functions

def print_insn_detail (insn)
 
def test_class ()
 

Variables

string ARM_CODE = b"\x86\x48\x60\xf4\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3\x00\x02\x01\xf1\x05\x40\xd0\xe8\xf4\x80\x00\x00"
 
string ARM_CODE2 = b"\xd1\xe8\x00\xf0\xf0\x24\x04\x07\x1f\x3c\xf2\xc0\x00\x00\x4f\xf0\x00\x01\x46\x6c"
 
string THUMB_CODE = b"\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0"
 
string THUMB_CODE2 = b"\x4f\xf0\x00\x01\xbd\xe8\x00\x88\xd1\xe8\x00\xf0\x18\xbf\xad\xbf\xf3\xff\x0b\x0c\x86\xf3\x00\x89\x80\xf3\x00\x8c\x4f\xfa\x99\xf6\xd0\xff\xa2\x01"
 
string THUMB_MCLASS = b"\xef\xf3\x02\x80"
 
string ARMV8 = b"\xe0\x3b\xb2\xee\x42\x00\x01\xe1\x51\xf0\x7f\xf5"
 
tuple all_tests
 

Function Documentation

◆ print_insn_detail()

def test_arm.print_insn_detail (   insn)

Definition at line 28 of file test_arm.py.

28 def print_insn_detail(insn):
29  # print address, mnemonic and operands
30  print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
31 
32  # "data" instruction generated by SKIPDATA option has no detail
33  if insn.id == 0:
34  return
35 
36  if len(insn.operands) > 0:
37  print("\top_count: %u" % len(insn.operands))
38  c = 0
39  for i in insn.operands:
40  if i.type == ARM_OP_REG:
41  print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg)))
42  if i.type == ARM_OP_IMM:
43  print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x_32(i.imm)))
44  if i.type == ARM_OP_PIMM:
45  print("\t\toperands[%u].type: P-IMM = %u" % (c, i.imm))
46  if i.type == ARM_OP_CIMM:
47  print("\t\toperands[%u].type: C-IMM = %u" % (c, i.imm))
48  if i.type == ARM_OP_FP:
49  print("\t\toperands[%u].type: FP = %f" % (c, i.fp))
50  if i.type == ARM_OP_SYSREG:
51  print("\t\toperands[%u].type: SYSREG = %u" % (c, i.reg))
52  if i.type == ARM_OP_SETEND:
53  if i.setend == ARM_SETEND_BE:
54  print("\t\toperands[%u].type: SETEND = be" % c)
55  else:
56  print("\t\toperands[%u].type: SETEND = le" % c)
57  if i.type == ARM_OP_MEM:
58  print("\t\toperands[%u].type: MEM" % c)
59  if i.mem.base != 0:
60  print("\t\t\toperands[%u].mem.base: REG = %s" \
61  % (c, insn.reg_name(i.mem.base)))
62  if i.mem.index != 0:
63  print("\t\t\toperands[%u].mem.index: REG = %s" \
64  % (c, insn.reg_name(i.mem.index)))
65  if i.mem.scale != 1:
66  print("\t\t\toperands[%u].mem.scale: %u" \
67  % (c, i.mem.scale))
68  if i.mem.disp != 0:
69  print("\t\t\toperands[%u].mem.disp: 0x%s" \
70  % (c, to_x_32(i.mem.disp)))
71  if i.mem.lshift != 0:
72  print("\t\t\toperands[%u].mem.lshift: 0x%s" \
73  % (c, to_x_32(i.mem.lshift)))
74 
75  if i.neon_lane != -1:
76  print("\t\toperands[%u].neon_lane = %u" % (c, i.neon_lane))
77 
78  if i.access == CS_AC_READ:
79  print("\t\toperands[%u].access: READ\n" % (c))
80  elif i.access == CS_AC_WRITE:
81  print("\t\toperands[%u].access: WRITE\n" % (c))
82  elif i.access == CS_AC_READ | CS_AC_WRITE:
83  print("\t\toperands[%u].access: READ | WRITE\n" % (c))
84 
85  if i.shift.type != ARM_SFT_INVALID and i.shift.value:
86  print("\t\t\tShift: %u = %u" \
87  % (i.shift.type, i.shift.value))
88  if i.vector_index != -1:
89  print("\t\t\toperands[%u].vector_index = %u" %(c, i.vector_index))
90  if i.subtracted:
91  print("\t\t\toperands[%u].subtracted = True" %c)
92 
93  c += 1
94 
95  if insn.update_flags:
96  print("\tUpdate-flags: True")
97  if insn.writeback:
98  print("\tWrite-back: True")
99  if not insn.cc in [ARM_CC_AL, ARM_CC_INVALID]:
100  print("\tCode condition: %u" % insn.cc)
101  if insn.cps_mode:
102  print("\tCPSI-mode: %u" %(insn.cps_mode))
103  if insn.cps_flag:
104  print("\tCPSI-flag: %u" %(insn.cps_flag))
105  if insn.vector_data:
106  print("\tVector-data: %u" %(insn.vector_data))
107  if insn.vector_size:
108  print("\tVector-size: %u" %(insn.vector_size))
109  if insn.usermode:
110  print("\tUser-mode: True")
111  if insn.mem_barrier:
112  print("\tMemory-barrier: %u" %(insn.mem_barrier))
113 
114  (regs_read, regs_write) = insn.regs_access()
115 
116  if len(regs_read) > 0:
117  print("\tRegisters read:", end="")
118  for r in regs_read:
119  print(" %s" %(insn.reg_name(r)), end="")
120  print("")
121 
122  if len(regs_write) > 0:
123  print("\tRegisters modified:", end="")
124  for r in regs_write:
125  print(" %s" %(insn.reg_name(r)), end="")
126  print("")
127 
128 
129 # ## Test class Cs
size_t len
Definition: 6502dis.c:15
def print_insn_detail(insn)
Definition: test_arm.py:28
def to_x_32(s)
Definition: xprint.py:36

References len, and xprint.to_x_32().

Referenced by test_class().

◆ test_class()

def test_arm.test_class ( )

Definition at line 130 of file test_arm.py.

130 def test_class():
131 
132  for (arch, mode, code, comment, syntax) in all_tests:
133  print("*" * 16)
134  print("Platform: %s" % comment)
135  print("Code: %s" % to_hex(code))
136  print("Disasm:")
137 
138  try:
139  md = Cs(arch, mode)
140  if syntax is not None:
141  md.syntax = syntax
142  md.detail = True
143  for insn in md.disasm(code, 0x80001000):
144  print_insn_detail(insn)
145  print ()
146  except CsError as e:
147  print("ERROR: %s" % e)
148 
149 
def test_class()
Definition: test_arm.py:130
def to_hex(s, prefix_0x=True)
Definition: xprint.py:9

References print_insn_detail(), and xprint.to_hex().

Variable Documentation

◆ all_tests

tuple test_arm.all_tests
Initial value:
1 = (
2  (CS_ARCH_ARM, CS_MODE_ARM, ARM_CODE, "ARM", None),
3  (CS_ARCH_ARM, CS_MODE_THUMB, THUMB_CODE, "Thumb", None),
4  (CS_ARCH_ARM, CS_MODE_THUMB, ARM_CODE2, "Thumb-mixed", None),
5  (CS_ARCH_ARM, CS_MODE_THUMB, THUMB_CODE2, "Thumb-2 & register named with numbers", CS_OPT_SYNTAX_NOREGNAME),
6  (CS_ARCH_ARM, CS_MODE_THUMB + CS_MODE_MCLASS, THUMB_MCLASS, "Thumb-MClass", None),
7  (CS_ARCH_ARM, CS_MODE_ARM + CS_MODE_V8, ARMV8, "Arm-V8", None),
8  )

Definition at line 18 of file test_arm.py.

Referenced by TestArm.main(), TestArm64.main(), TestM680x.main(), TestMips.main(), TestPpc.main(), TestSparc.main(), TestSystemz.main(), TestX86.main(), and TestXcore.main().

◆ ARM_CODE

string test_arm.ARM_CODE = b"\x86\x48\x60\xf4\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3\x00\x02\x01\xf1\x05\x40\xd0\xe8\xf4\x80\x00\x00"

Definition at line 11 of file test_arm.py.

◆ ARM_CODE2

string test_arm.ARM_CODE2 = b"\xd1\xe8\x00\xf0\xf0\x24\x04\x07\x1f\x3c\xf2\xc0\x00\x00\x4f\xf0\x00\x01\x46\x6c"

Definition at line 12 of file test_arm.py.

◆ ARMV8

string test_arm.ARMV8 = b"\xe0\x3b\xb2\xee\x42\x00\x01\xe1\x51\xf0\x7f\xf5"

Definition at line 16 of file test_arm.py.

◆ THUMB_CODE

string test_arm.THUMB_CODE = b"\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0"

Definition at line 13 of file test_arm.py.

◆ THUMB_CODE2

string test_arm.THUMB_CODE2 = b"\x4f\xf0\x00\x01\xbd\xe8\x00\x88\xd1\xe8\x00\xf0\x18\xbf\xad\xbf\xf3\xff\x0b\x0c\x86\xf3\x00\x89\x80\xf3\x00\x8c\x4f\xfa\x99\xf6\xd0\xff\xa2\x01"

Definition at line 14 of file test_arm.py.

◆ THUMB_MCLASS

string test_arm.THUMB_MCLASS = b"\xef\xf3\x02\x80"

Definition at line 15 of file test_arm.py.