capstone/bindings/python/tests/test_customized_mnem.py
peace-maker 89aee40003
Add arm64 and sysz compatibility layer to Python bindings (#2559)
* Add arm64.py and sysz_const.py compatibility layer to the Python bindings

When importing `capstone.arm64` before doing other capstone imports the ARM64 constants get monkey patched into the exports.
Same with `capstone.sysz_const` for the SYSZ constants.

* Add SPDX-License comments

* Access an instruction detail in compatibility test

* Fail python tests on error instead of just ERROR output

Include the test_iter.py in the test_all.py too.

* Improve python compatibility docs

Co-authored-by: Rot127 <45763064+Rot127@users.noreply.github.com>

* Test for ARM_CC_* constants presence

---------

Co-authored-by: Rot127 <45763064+Rot127@users.noreply.github.com>
2024-12-05 19:35:18 +08:00

44 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
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" % (insn.mnemonic, insn.op_str))
def test():
errors = []
try:
md = Cs(CS_ARCH_X86, CS_MODE_32)
print("Disassemble X86 code with default instruction mnemonic")
print_insn(md, X86_CODE32)
print("\nNow customize engine to change mnemonic from 'JNE' to 'JNZ'")
md.mnemonic_setup(X86_INS_JNE, "jnz")
print_insn(md, X86_CODE32)
print("\nReset 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)
errors.append(str(e))
return errors
if __name__ == '__main__':
if test():
print("Some errors happened. Please check the output")
exit(1)