Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arm64 and sysz compatibility layer to Python bindings #2559

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

peace-maker
Copy link
Contributor

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

To allow Python scripts to work with ARM64 and SYSZ constants on capstone v5 as well as v6, provide a compatibility layer similar to the compatibility headers in the C API. Script authors can choose to keep the old constant names around to avoid forcing the update to capstone v6 right away.

The idea is to introduce something in a similar fashion to the C API CAPSTONE_AARCH64_COMPAT_HEADER defines, which defines the old ARM64_* constants. Instead of a #define before including capstone, Python scripts should explicitly import the architecture by their old name before their usual capstone imports:

# First import legacy compatibility module using old `arm64` name instead of `aarch64`.
import capstone.arm64
# Then import anything else from capstone
import capstone # from capstone import *

# capstone.CS_ARCH_ARM64
# capstone.arm64.ARM64_INS_FDIV

SystemZ follows a similar pattern:

# First import legacy compatibility module using old `sysz_const` name instead of `systemz_const`.
import capstone.sysz_const
# Then import anything else from capstone.
import capstone # from capstone import *

# capstone.CS_ARCH_SYSZ
# capstone.systemz.SYSZ_REG_V3

This is achieved by monkey-patching the modules to define all exports expected by scripts supporting older versions of capstone using setattr(capstone, name, value).

This compatibility layer only handles constant values. The ctypes structures aren't reexposed with old names and the _cs_arch doesn't contain the arm64 arch, so code using insn.detail.arm64.cc or similar still fails. I don't know how to rename those in a transparent manner.

Test plan

Added test script which uses the old constants.

Closing issues

closes #2536

…ings

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backward compatibility for ARM64.
1 participant