Rizin
unix-like reverse engineering framework and cli tools
test_customized_mnem.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
4 
5 from __future__ import print_function
6 from capstone import *
7 from capstone.x86 import *
8 from xprint import to_hex
9 
10 
11 X86_CODE32 = b"\x75\x01"
12 
13 
14 def 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 
21 def 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 
39 if __name__ == '__main__':
40  test()
-lz4-versions
def to_hex(s, prefix_0x=True)
Definition: xprint.py:9