aboutsummaryrefslogtreecommitdiffstats
path: root/capstone/bindings/python/test_customized_mnem.py
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /capstone/bindings/python/test_customized_mnem.py
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'capstone/bindings/python/test_customized_mnem.py')
-rwxr-xr-xcapstone/bindings/python/test_customized_mnem.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/capstone/bindings/python/test_customized_mnem.py b/capstone/bindings/python/test_customized_mnem.py
new file mode 100755
index 000000000..a09cc727f
--- /dev/null
+++ b/capstone/bindings/python/test_customized_mnem.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
+
+from __future__ import print_function
+from capstone import *
+from capstone.x86 import *
+from xprint import to_hex
+
+
+X86_CODE32 = b"\x75\x01"
+
+
+def print_insn(md, code):
+ print("%s\t" % to_hex(code, False), end="")
+
+ for insn in md.disasm(code, 0x1000):
+ print("\t%s\t%s\n" % (insn.mnemonic, insn.op_str))
+
+
+def test():
+ try:
+ md = Cs(CS_ARCH_X86, CS_MODE_32)
+
+ print("Disassemble X86 code with default instruction mnemonic")
+ print_insn(md, X86_CODE32)
+
+ print("Now customize engine to change mnemonic from 'JNE' to 'JNZ'")
+ md.mnemonic_setup(X86_INS_JNE, "jnz")
+ print_insn(md, X86_CODE32)
+
+ print("Reset engine to use the default mnemonic")
+ md.mnemonic_setup(X86_INS_JNE, None)
+ print_insn(md, X86_CODE32)
+ except CsError as e:
+ print("ERROR: %s" % e)
+
+
+if __name__ == '__main__':
+ test()