| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import print_function |
| 6 |
from capstone import * |
| 7 |
from capstone.systemz import * |
| 8 |
|
| 9 |
|
| 10 |
SYSZ_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\xec\x18\x00\x00\xc1\x7f" |
| 11 |
mask64 = lambda v: v & 0xFFFFFFFFFFFFFFFF |
| 12 |
all_tests = ( |
| 13 |
(CS_ARCH_SYSZ, 0, SYSZ_CODE, "SystemZ"), |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
def print_insn_detail(insn): |
| 18 |
|
| 19 |
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str)) |
| 20 |
|
| 21 |
|
| 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 == SYSZ_OP_REG: |
| 30 |
print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg))) |
| 31 |
if i.type == SYSZ_OP_ACREG: |
| 32 |
print("\t\toperands[%u].type: ACREG = %u" % (c, i.reg)) |
| 33 |
if i.type == SYSZ_OP_IMM: |
| 34 |
print("\t\toperands[%u].type: IMM = 0x%x" % (c, mask64(i.imm))) |
| 35 |
if i.type == SYSZ_OP_MEM: |
| 36 |
print("\t\toperands[%u].type: MEM" % c) |
| 37 |
if i.mem.base != 0: |
| 38 |
print("\t\t\toperands[%u].mem.base: REG = %s" \ |
| 39 |
% (c, insn.reg_name(i.mem.base))) |
| 40 |
if i.mem.index != 0: |
| 41 |
print("\t\t\toperands[%u].mem.index: REG = %s" \ |
| 42 |
% (c, insn.reg_name(i.mem.index))) |
| 43 |
if i.mem.length != 0: |
| 44 |
print("\t\t\toperands[%u].mem.length: 0x%x" \ |
| 45 |
% (c, mask64(i.mem.length))) |
| 46 |
if i.mem.disp != 0: |
| 47 |
print("\t\t\toperands[%u].mem.disp: 0x%x" \ |
| 48 |
% (c, mask64(i.mem.disp))) |
| 49 |
c += 1 |
| 50 |
|
| 51 |
if insn.cc: |
| 52 |
print("\tConditional code: %u" % insn.cc) |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
def test_class(): |
| 57 |
|
| 58 |
for (arch, mode, code, comment) in all_tests: |
| 59 |
print("*" * 16) |
| 60 |
print("Platform: %s" %comment) |
| 61 |
print("Code: %s" % code.hex(' ')) |
| 62 |
print("Disasm:") |
| 63 |
|
| 64 |
try: |
| 65 |
md = Cs(arch, mode) |
| 66 |
md.detail = True |
| 67 |
for insn in md.disasm(code, 0x1000): |
| 68 |
print_insn_detail(insn) |
| 69 |
print () |
| 70 |
print("0x%x:\n" % (insn.address + insn.size)) |
| 71 |
except CsError as e: |
| 72 |
print("ERROR: %s" %e) |
| 73 |
|
| 74 |
|
| 75 |
if __name__ == '__main__': |
| 76 |
test_class() |