| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import print_function |
| 6 |
import sys |
| 7 |
from capstone import * |
| 8 |
|
| 9 |
CODE32 = b"\x48\x01\x05\x15" |
| 10 |
CODE32 += b"\x4B\xff\xff\xfd" |
| 11 |
CODE32 += b"\x48\x00\x00\x0c" |
| 12 |
CODE32 += b"\x41\x80\xff\xd8" |
| 13 |
CODE32 += b"\x40\x80\xff\xec" |
| 14 |
CODE32 += b"\x41\x84\x01\x6c" |
| 15 |
CODE32 += b"\x41\x82\x00\x10" |
| 16 |
CODE32 += b"\x40\x82\x00\x08" |
| 17 |
CODE32 += b"\x40\x95\x00\x94" |
| 18 |
CODE32 += b"\x40\x9f\x10\x30" |
| 19 |
CODE32 += b"\x42\x00\xff\xd8" |
| 20 |
CODE32 += b"\x4d\x82\x00\x20" |
| 21 |
CODE32 += b"\x4e\x80\x00\x20" |
| 22 |
CODE32 += b"\x4a\x00\x00\x02" |
| 23 |
CODE32 += b"\x41\x80\xff\xda" |
| 24 |
CODE32 += b"\x41\x4f\xff\x17" |
| 25 |
CODE32 += b"\x43\x20\x0c\x07" |
| 26 |
CODE32 += b"\x4c\x00\x04\x20" |
| 27 |
|
| 28 |
_python3 = sys.version_info.major == 3 |
| 29 |
|
| 30 |
all_tests = ( |
| 31 |
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, CODE32, "PPC branch instruction decoding", 0), |
| 32 |
) |
| 33 |
|
| 34 |
|
| 35 |
def to_hex(s): |
| 36 |
if _python3: |
| 37 |
return " ".join("0x{0:02x}".format(c) for c in s) |
| 38 |
else: |
| 39 |
return " ".join("0x{0:02x}".format(ord(c)) for c in s) |
| 40 |
|
| 41 |
|
| 42 |
def test_cs_disasm_quick(): |
| 43 |
for (arch, mode, code, comment, syntax) in all_tests: |
| 44 |
print("Platform: %s" % comment) |
| 45 |
print("Code: %s" %(to_hex(code))), |
| 46 |
print("Disasm:") |
| 47 |
for (addr, size, mnemonic, op_str) in cs_disasm_lite(arch, mode, code, 0x1000): |
| 48 |
print("0x%x:\t%s\t%s" % (addr, mnemonic, op_str)) |
| 49 |
print() |
| 50 |
|
| 51 |
|
| 52 |
if __name__ == '__main__': |
| 53 |
test_cs_disasm_quick() |