mirror of
https://github.com/siemens-mobile-hacks/capstone.git
synced 2026-11-25 22:27:31 +00:00
64 lines
2 KiB
Python
Executable file
64 lines
2 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
|
|
|
|
from __future__ import print_function
|
|
from capstone import *
|
|
from capstone.tricore import *
|
|
from xprint import to_hex, to_x
|
|
|
|
TRICORE_CODE = b"\x09\xcf\xbc\xf5\x09\xf4\x01\x00\x89\xfb\x8f\x74\x89\xfe\x48\x01\x29\x00\x19\x25\x29\x03\x09\xf4\x85\xf9\x68\x0f\x16\x01"
|
|
|
|
all_tests = (
|
|
(CS_ARCH_TRICORE, CS_MODE_TRICORE_162, TRICORE_CODE, "TriCore"),
|
|
)
|
|
|
|
|
|
def print_insn_detail(insn):
|
|
# print address, mnemonic and operands
|
|
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
|
|
|
|
# "data" instruction generated by SKIPDATA option has no detail
|
|
if insn.id == 0:
|
|
return
|
|
|
|
if len(insn.operands) > 0:
|
|
print("\top_count: %u" % len(insn.operands))
|
|
c = 0
|
|
for i in insn.operands:
|
|
if i.type == TRICORE_OP_REG:
|
|
print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg)))
|
|
if i.type == TRICORE_OP_IMM:
|
|
print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x(i.imm)))
|
|
if i.type == TRICORE_OP_MEM:
|
|
print("\t\toperands[%u].type: MEM" % c)
|
|
if i.mem.base != 0:
|
|
print("\t\t\toperands[%u].mem.base: REG = %s" \
|
|
% (c, insn.reg_name(i.mem.base)))
|
|
if i.mem.disp != 0:
|
|
print("\t\t\toperands[%u].mem.disp: 0x%s" \
|
|
% (c, to_x(i.mem.disp)))
|
|
c += 1
|
|
print()
|
|
|
|
|
|
# ## Test class Cs
|
|
def test_class():
|
|
for (arch, mode, code, comment) in all_tests:
|
|
print("*" * 16)
|
|
print("Platform: %s" % comment)
|
|
print("Code: %s" % to_hex(code))
|
|
print("Disasm:")
|
|
|
|
try:
|
|
md = Cs(arch, mode)
|
|
md.detail = True
|
|
for insn in md.disasm(code, 0x1000):
|
|
print_insn_detail(insn)
|
|
print("0x%x:" % (insn.address + insn.size))
|
|
except CsError as e:
|
|
print("ERROR: %s" % e)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test_class()
|