| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import print_function |
| 6 |
from capstone import * |
| 7 |
import binascii |
| 8 |
|
| 9 |
|
| 10 |
X86_CODE32 = b"\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00\x00\x91\x92" |
| 11 |
RANDOM_CODE = b"\xed\x00\x00\x00\x00\x1a\x5a\x0f\x1f\xff\xc2\x09\x80\x00\x00\x00\x07\xf7\xeb\x2a\xff\xff\x7f\x57\xe3\x01\xff\xff\x7f\x57\xeb\x00\xf0\x00\x00\x24\xb2\x4f\x00\x78" |
| 12 |
|
| 13 |
all_tests = ( |
| 14 |
(CS_ARCH_X86, CS_MODE_32, X86_CODE32, "X86 32 (Intel syntax)", None), |
| 15 |
(CS_ARCH_ARM, CS_MODE_ARM, RANDOM_CODE, "Arm", None), |
| 16 |
) |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
def testcb(buffer, size, offset, userdata): |
| 21 |
|
| 22 |
return 2 |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
def test_class(): |
| 27 |
for (arch, mode, code, comment, syntax) in all_tests: |
| 28 |
print('*' * 16) |
| 29 |
print("Platform: %s" %comment) |
| 30 |
print("Code: %s" % code.hex(' ')) |
| 31 |
print("Disasm:") |
| 32 |
|
| 33 |
try: |
| 34 |
md = Cs(arch, mode) |
| 35 |
|
| 36 |
if syntax is not None: |
| 37 |
md.syntax = syntax |
| 38 |
|
| 39 |
md.skipdata = True |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
md.skipdata_setup = ("db", None, None) |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
for insn in md.disasm(code, 0x1000): |
| 61 |
|
| 62 |
|
| 63 |
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str)) |
| 64 |
|
| 65 |
print("0x%x:" % (insn.address + insn.size)) |
| 66 |
print |
| 67 |
except CsError as e: |
| 68 |
print("ERROR: %s" % e) |
| 69 |
|
| 70 |
|
| 71 |
if __name__ == '__main__': |
| 72 |
test_class() |