1#!/usr/bin/env python 2 3# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com> 4 5from __future__ import print_function 6from capstone import * 7from capstone.x86 import * 8from xprint import to_hex 9 10 11X86_CODE32 = b"\x75\x01" 12 13 14def print_insn(md, code): 15 print("%s\t" % to_hex(code, False), end="") 16 17 for insn in md.disasm(code, 0x1000): 18 print("\t%s\t%s\n" % (insn.mnemonic, insn.op_str)) 19 20 21def test(): 22 try: 23 md = Cs(CS_ARCH_X86, CS_MODE_32) 24 25 print("Disassemble X86 code with default instruction mnemonic") 26 print_insn(md, X86_CODE32) 27 28 print("Now customize engine to change mnemonic from 'JNE' to 'JNZ'") 29 md.mnemonic_setup(X86_INS_JNE, "jnz") 30 print_insn(md, X86_CODE32) 31 32 print("Reset engine to use the default mnemonic") 33 md.mnemonic_setup(X86_INS_JNE, None) 34 print_insn(md, X86_CODE32) 35 except CsError as e: 36 print("ERROR: %s" % e) 37 38 39if __name__ == '__main__': 40 test() 41