Debian Codegraph @

bindings/python/tests/test_tricore.py

raw symbols SCIP
1 #!/usr/bin/env python
2
3 # Capstone Python bindings, by Nguyen Anh Quynnh <[email protected]>
4
5 from __future__ import print_function
6 from capstone import *
7 from capstone.tricore import *
8
9 TRICORE_CODE = b"\x16\x01\x20\x01\x1d\x00\x02\x00\x8f\x70\x00\x11\x40\xae\x89\xee\x04\x09\x42\xf2\xe2\xf2\xc2\x11\x19" \
10 b"\xff\xc0\x70\x19\xff\x20\x10"
11
12 all_tests = (
13 (CS_ARCH_TRICORE, CS_MODE_TRICORE_162, TRICORE_CODE, "TriCore"),
14 )
15 mask64 = lambda v: v & 0xFFFFFFFFFFFFFFFF
16
17 def print_insn_detail(insn):
18 # print address, mnemonic and operands
19 print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
20
21 # "data" instruction generated by SKIPDATA option has no detail
22 if insn.id == 0:
23 return
24
25 if len(insn.operands) > 0:
26 print("\top_count: %u" % len(insn.operands))
27 c = 0
28 for i in insn.operands:
29 if i.type == TRICORE_OP_REG:
30 print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg)))
31 if i.type == TRICORE_OP_IMM:
32 print("\t\toperands[%u].type: IMM = 0x%x" % (c, mask64(i.imm)))
33 if i.type == TRICORE_OP_MEM:
34 print("\t\toperands[%u].type: MEM" % c)
35 if i.mem.base != 0:
36 print("\t\t\toperands[%u].mem.base: REG = %s" \
37 % (c, insn.reg_name(i.mem.base)))
38 if i.mem.disp != 0:
39 print("\t\t\toperands[%u].mem.disp: 0x%x" \
40 % (c, mask64(i.mem.disp)))
41 c += 1
42
43
44 # ## Test class Cs
45 def test_class():
46 for (arch, mode, code, comment) in all_tests:
47 print("*" * 16)
48 print("Platform: %s" % comment)
49 print("Code: %s" % code.hex(' '))
50 print("Disasm:")
51
52 try:
53 md = Cs(arch, mode)
54 md.detail = True
55 for insn in md.disasm(code, 0x1000):
56 print_insn_detail(insn)
57 print()
58 print("0x%x:\n" % (insn.address + insn.size))
59 except CsError as e:
60 print("ERROR: %s" % e)
61
62
63 if __name__ == '__main__':
64 test_class()