Skip to content

Commit

Permalink
python: Fix capstone syntax values
Browse files Browse the repository at this point in the history
The option values for capstone syntax bindings are currently out-of-sync
with capstone.h on the v5. This causes Python code using the syntax
options to not work correctly. For example, consider:

	import capstone as c
	md = c.Cs(c.CS_ARCH_X86, c.CS_MODE_32)
	md.syntax = c.CS_OPT_SYNTAX_ATT

This code will presently error on the latest 5.0.1 release, it works
on both the next branch and the 4.X releases. The error message is:

	capstone.CsError: Invalid option (CS_ERR_OPTION)

This is because commit 53eaeac broke
the option values on the v5 branch as it caused capstone.h and
bindings/python/capstone/__init__.py to define these values differently.
  • Loading branch information
nmeum committed Jan 9, 2024
1 parent 6ac231f commit 15e19bd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions bindings/python/capstone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@
CS_AC_WRITE = (1 << 1) # Operand that is written to.

# Capstone syntax value
CS_OPT_SYNTAX_DEFAULT = 1 << 1 # Default assembly syntax of all platforms (CS_OPT_SYNTAX)
CS_OPT_SYNTAX_INTEL = 1 << 2 # Intel X86 asm syntax - default syntax on X86 (CS_OPT_SYNTAX, CS_ARCH_X86)
CS_OPT_SYNTAX_ATT = 1 << 3 # ATT asm syntax (CS_OPT_SYNTAX, CS_ARCH_X86)
CS_OPT_SYNTAX_NOREGNAME = 1 << 4 # Asm syntax prints register name with only number - (CS_OPT_SYNTAX, CS_ARCH_PPC, CS_ARCH_ARM)
CS_OPT_SYNTAX_MASM = 1 << 5 # MASM syntax (CS_OPT_SYNTAX, CS_ARCH_X86)
CS_OPT_SYNTAX_MOTOROLA = 1 << 6 # MOS65XX use $ as hex prefix
CS_OPT_SYNTAX_CS_REG_ALIAS = 1 << 7 # Prints common register alias which are not defined in LLVM (ARM: r9 = sb etc.)
CS_OPT_SYNTAX_DEFAULT = 0 # Default assembly syntax of all platforms (CS_OPT_SYNTAX)
CS_OPT_SYNTAX_INTEL = 1 # Intel X86 asm syntax - default syntax on X86 (CS_OPT_SYNTAX, CS_ARCH_X86)
CS_OPT_SYNTAX_ATT = 2 # ATT asm syntax (CS_OPT_SYNTAX, CS_ARCH_X86)
CS_OPT_SYNTAX_NOREGNAME = 3 # Asm syntax prints register name with only number - (CS_OPT_SYNTAX, CS_ARCH_PPC, CS_ARCH_ARM)
CS_OPT_SYNTAX_MASM = 4 # MASM syntax (CS_OPT_SYNTAX, CS_ARCH_X86)
CS_OPT_SYNTAX_MOTOROLA = 5 # MOS65XX use $ as hex prefix
CS_OPT_SYNTAX_CS_REG_ALIAS = 6 # Prints common register alias which are not defined in LLVM (ARM: r9 = sb etc.)

# Capstone error type
CS_ERR_OK = 0 # No error: everything was fine
Expand Down

0 comments on commit 15e19bd

Please sign in to comment.