from __future__ import print_function
import sys
from capstone import *
CODE32 = b"\x48\x01\x05\x15" CODE32 += b"\x4B\xff\xff\xfd" CODE32 += b"\x48\x00\x00\x0c" CODE32 += b"\x41\x80\xff\xd8" CODE32 += b"\x40\x80\xff\xec" CODE32 += b"\x41\x84\x01\x6c" CODE32 += b"\x41\x82\x00\x10" CODE32 += b"\x40\x82\x00\x08" CODE32 += b"\x40\x95\x00\x94" CODE32 += b"\x40\x9f\x10\x30" CODE32 += b"\x42\x00\xff\xd8" CODE32 += b"\x4d\x82\x00\x20" CODE32 += b"\x4e\x80\x00\x20" CODE32 += b"\x4a\x00\x00\x02" CODE32 += b"\x41\x80\xff\xda" CODE32 += b"\x41\x4f\xff\x17" CODE32 += b"\x43\x20\x0c\x07" CODE32 += b"\x4c\x00\x04\x20"
_python3 = sys.version_info.major == 3
all_tests = (
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, CODE32, "PPC branch instruction decoding", 0),
)
def to_hex(s):
if _python3:
return " ".join("0x{0:02x}".format(c) for c in s) else:
return " ".join("0x{0:02x}".format(ord(c)) for c in s)
def test_cs_disasm_quick():
for (arch, mode, code, comment, syntax) in all_tests:
print("Platform: %s" % comment)
print("Code: %s" %(to_hex(code))),
print("Disasm:")
for (addr, size, mnemonic, op_str) in cs_disasm_lite(arch, mode, code, 0x1000):
print("0x%x:\t%s\t%s" % (addr, mnemonic, op_str))
print()
if __name__ == '__main__':
test_cs_disasm_quick()