Debian Codegraph @

bindings/python/tests/test_customized_mnem.py

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