Merge commit '3621a6c08002c6b3e5b6f91bb0e20d8372613160' into dev

This commit is contained in:
Simone
2025-01-07 15:08:55 +00:00
1521 changed files with 323443 additions and 365407 deletions

View File

@@ -8,7 +8,19 @@
pip install bindings/python/
```
2. The tests directory contains some test code to show how to use the Capstone API.
2. Building cstest_py
To run the disassembler tests you can install `cstest_py` as alternative to the normal `cstest`.
In contrast to `cstest`, `cstest_py` also runs on Windows and Mac.
Install with:
```
pip install bindings/python/cstest_py/
```
It requires the bindings of course.
3. The tests directory contains some test code to show how to use the Capstone API.
- test_lite.py
Similarly to test_basic.py, but this code shows how to use disasm_lite(), a lighter

View File

@@ -1,5 +1,8 @@
recursive-include src *
include LICENSE.TXT
include README.txt
include BUILDING.txt
include Makefile
recursive-include prebuilt *
include BUILDING.md
graft capstone/lib
graft capstone/include
global-include *.dll
global-include *.dylib
global-include *.so.*

View File

@@ -1,47 +0,0 @@
PYTHON3 ?= python3
.PHONY: gen_const install sdist bdist clean check
gen_const:
cd .. && $(PYTHON3) const_generator.py python
install:
rm -rf src/
if test -n "${DESTDIR}"; then \
$(PYTHON3) setup.py build install --root="${DESTDIR}"; \
else \
$(PYTHON3) setup.py build install; \
fi
# build & upload PyPi package with source code of the core
sdist:
rm -rf src/ dist/
$(PYTHON3) setup.py sdist register upload
# build & upload PyPi package with prebuilt core
bdist:
rm -rf src/ dist/
$(PYTHON3) setup.py bdist_wheel register upload
clean:
rm -rf build/ src/ dist/ *.egg-info
rm -rf capstone/lib capstone/include pyx/lib pyx/include
rm -f pyx/*.c pyx/__init__.py
for f in capstone/*.py; do rm -f pyx/$$(basename $$f)x; done
rm -f MANIFEST
rm -f *.pyc capstone/*.pyc
TESTS = test_basic.py test_detail.py test_arm.py test_aarch64.py test_m68k.py test_mips.py
TESTS += test_ppc.py test_sparc.py test_systemz.py test_x86.py test_xcore.py test_tms320c64x.py
TESTS += test_m680x.py test_skipdata.py test_mos65xx.py test_bpf.py test_riscv.py
TESTS += test_evm.py test_tricore.py test_wasm.py test_sh.py test_hppa.py
TESTS += test_lite.py test_iter.py test_customized_mnem.py test_alpha.py
check:
@for t in $(TESTS); do \
echo Check $$t ... ; \
./tests/$$t > /dev/null; \
if [ $$? -eq 0 ]; then echo OK; else echo FAILED; exit 1; fi \
done

View File

@@ -1,12 +1,12 @@
To install Capstone, you should run `pip install capstone`.
If you would like to build Capstone with just the source distribution, without
pip, just run `python setup.py install` in the folder with setup.py in it.
If you would like to build and install Capstone with just the source distribution,
just run `python -m pip install .`, considering you are in the folder with setup.py in it.
In order to use this source distribution, you will need an environment that can
compile C code. On Linux, this is usually easy, but on Windows, this involves
installing Visual Studio and using the "Developer Command Prompt" to perform the
installation. See BUILDING.txt for more information.
installation. See BUILDING.md for more information.
By default, attempting to install the python bindings will trigger a build of
the capstone native core. If this is undesirable for whatever reason, for

View File

@@ -1,16 +0,0 @@
#!/bin/bash
set -e -x
cd bindings/python
if [ -f /opt/python/cp311-cp311/bin/python3 ];then
# Use manylinux Python
/opt/python/cp311-cp311/bin/python3 -m pip install wheel
/opt/python/cp311-cp311/bin/python3 setup.py bdist_wheel
else
python3 -m pip install wheel
python3 setup.py bdist_wheel
fi
cd dist
auditwheel repair *.whl
mv -f wheelhouse/*.whl .

View File

@@ -41,6 +41,7 @@ __all__ = [
'CS_ARCH_ALPHA',
'CS_ARCH_HPPA',
'CS_ARCH_LOONGARCH',
'CS_ARCH_XTENSA',
'CS_ARCH_ALL',
'CS_MODE_LITTLE_ENDIAN',
@@ -168,7 +169,7 @@ __all__ = [
'CS_OPT_SKIPDATA_SETUP',
'CS_OPT_MNEMONIC',
'CS_OPT_UNSIGNED',
'CS_OPT_NO_BRANCH_OFFSET',
'CS_OPT_ONLY_OFFSET_BRANCH',
'CS_ERR_OK',
'CS_ERR_MEM',
@@ -235,7 +236,7 @@ UINT16_MAX = 0xffff
# Capstone C interface
# API version
CS_API_MAJOR = 5
CS_API_MAJOR = 6
CS_API_MINOR = 0
# Package version
@@ -243,7 +244,7 @@ CS_VERSION_MAJOR = CS_API_MAJOR
CS_VERSION_MINOR = CS_API_MINOR
CS_VERSION_EXTRA = 0
__version__ = "%u.%u.%u" %(CS_VERSION_MAJOR, CS_VERSION_MINOR, CS_VERSION_EXTRA)
__version__ = "%u.%u.%u" % (CS_VERSION_MAJOR, CS_VERSION_MINOR, CS_VERSION_EXTRA)
# architectures
CS_ARCH_ARM = 0
@@ -267,7 +268,8 @@ CS_ARCH_TRICORE = 17
CS_ARCH_ALPHA = 18
CS_ARCH_HPPA = 19
CS_ARCH_LOONGARCH = 20
CS_ARCH_MAX = 20
CS_ARCH_XTENSA = 21
CS_ARCH_MAX = 21
CS_ARCH_ALL = 0xFFFF
# disasm mode
@@ -288,6 +290,14 @@ CS_MODE_QPX = (1 << 4) # Quad Processing eXtensions mode (PPC)
CS_MODE_SPE = (1 << 5) # Signal Processing Engine mode (PPC)
CS_MODE_BOOKE = (1 << 6) # Book-E mode (PPC)
CS_MODE_PS = (1 << 7) # Paired-singles mode (PPC)
CS_MODE_AIX_OS = (1 << 8) # PowerPC AIX-OS
CS_MODE_PWR7 = (1 << 9) # Power 7
CS_MODE_PWR8 = (1 << 10) # Power 8
CS_MODE_PWR9 = (1 << 11) # Power 9
CS_MODE_PWR10 = (1 << 12) # Power 10
CS_MODE_PPC_ISA_FUTURE = (1 << 13) # Power ISA Future
CS_MODE_MODERN_AIX_AS = (1 << 14) # PowerPC AIX-OS with modern assembly
CS_MODE_MSYNC = (1 << 15) # PowerPC Has only the msync instruction instead of sync. Implies BOOKE
CS_MODE_M68K_000 = (1 << 1) # M68K 68000 mode
CS_MODE_M68K_010 = (1 << 2) # M68K 68010 mode
CS_MODE_M68K_020 = (1 << 3) # M68K 68020 mode
@@ -340,7 +350,7 @@ CS_MODE_MOS65XX_6502 = (1 << 1) # MOS65XXX MOS 6502
CS_MODE_MOS65XX_65C02 = (1 << 2) # MOS65XXX WDC 65c02
CS_MODE_MOS65XX_W65C02 = (1 << 3) # MOS65XXX WDC W65c02
CS_MODE_MOS65XX_65816 = (1 << 4) # MOS65XXX WDC 65816, 8-bit m/x
CS_MODE_MOS65XX_65816_LONG_M = (1 << 5) # MOS65XXX WDC 65816, 16-bit m, 8-bit x
CS_MODE_MOS65XX_65816_LONG_M = (1 << 5) # MOS65XXX WDC 65816, 16-bit m, 8-bit x
CS_MODE_MOS65XX_65816_LONG_X = (1 << 6) # MOS65XXX WDC 65816, 8-bit m, 16-bit x
CS_MODE_MOS65XX_65816_LONG_MX = CS_MODE_MOS65XX_65816_LONG_M | CS_MODE_MOS65XX_65816_LONG_X
CS_MODE_SH2 = 1 << 1 # SH2
@@ -388,7 +398,7 @@ CS_OPT_SKIPDATA = 5 # Skip data when disassembling
CS_OPT_SKIPDATA_SETUP = 6 # Setup user-defined function for SKIPDATA option
CS_OPT_MNEMONIC = 7 # Customize instruction mnemonic
CS_OPT_UNSIGNED = 8 # Print immediate in unsigned form
CS_OPT_NO_BRANCH_OFFSET = 9 # ARM, prints branch immediates without offset.
CS_OPT_ONLY_OFFSET_BRANCH = 9 # ARM, prints branch immediates without offset.
# Capstone option value
CS_OPT_OFF = 0 # Turn OFF an option - default option of CS_OPT_DETAIL
@@ -413,8 +423,8 @@ CS_OP_RESERVED_14 = 14
CS_OP_RESERVED_15 = 15
CS_OP_SPECIAL = 0x10 # Special operands from archs
CS_OP_MEM = 0x80 # Memory operand. Can be ORed with another operand type.
CS_OP_MEM_REG = CS_OP_MEM | CS_OP_IMM,
CS_OP_MEM_IMM = CS_OP_MEM | CS_OP_IMM,
CS_OP_MEM_REG = CS_OP_MEM | CS_OP_REG # Memory referencing register operand.
CS_OP_MEM_IMM = CS_OP_MEM | CS_OP_IMM # Memory referencing immediate operand.
# Common instruction groups - to be consistent across all architectures.
CS_GRP_INVALID = 0 # uninitialized/invalid group.
@@ -441,7 +451,7 @@ 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_PERCENT = (1 << 8) # Prints the % in front of PPC registers.
CS_OPT_SYNTAX_NO_DOLLAR = (1 << 9) # Does not print the $ in front of Mips registers.
CS_OPT_SYNTAX_NO_DOLLAR = (1 << 9) # Does not print the $ in front of Mips, LoongArch registers.
CS_OPT_DETAIL_REAL = (1 << 1) # If enabled, always sets the real instruction detail.Even if the instruction is an alias.
# Capstone error type
@@ -498,6 +508,7 @@ else:
_found = False
def _load_lib(path):
lib_file = join(path, _lib)
if os.path.exists(lib_file):
@@ -509,6 +520,7 @@ def _load_lib(path):
return ctypes.cdll.LoadLibrary(lib_file + '.{}'.format(CS_VERSION_MAJOR))
return None
_cs = None
# Loading attempts, in order
@@ -542,11 +554,15 @@ def copy_ctypes(src):
ctypes.memmove(ctypes.byref(dst), ctypes.byref(src), ctypes.sizeof(type(src)))
return dst
def copy_ctypes_list(src):
return [copy_ctypes(n) for n in src]
# Weird import placement because these modules are needed by the below code but need the above functions
from . import arm, aarch64, m68k, mips, ppc, sparc, systemz, x86, xcore, tms320c64x, m680x, evm, mos65xx, wasm, bpf, riscv, sh, tricore, alpha, hppa, loongarch
from . import arm, aarch64, m68k, mips, ppc, sparc, systemz, x86, xcore, tms320c64x, m680x, evm, mos65xx, wasm, bpf, \
riscv, sh, tricore, alpha, hppa, loongarch, xtensa
class _cs_arch(ctypes.Union):
_fields_ = (
@@ -571,8 +587,10 @@ class _cs_arch(ctypes.Union):
('alpha', alpha.CsAlpha),
('hppa', hppa.CsHPPA),
('loongarch', loongarch.CsLoongArch),
('xtensa', xtensa.CsXtensa),
)
class _cs_detail(ctypes.Structure):
_fields_ = (
('regs_read', ctypes.c_uint16 * 20),
@@ -585,6 +603,7 @@ class _cs_detail(ctypes.Structure):
('arch', _cs_arch),
)
class _cs_insn(ctypes.Structure):
_fields_ = (
('id', ctypes.c_uint),
@@ -599,8 +618,11 @@ class _cs_insn(ctypes.Structure):
('detail', ctypes.POINTER(_cs_detail)),
)
# callback for SKIPDATA option
CS_SKIPDATA_CALLBACK = ctypes.CFUNCTYPE(ctypes.c_size_t, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t, ctypes.c_size_t, ctypes.c_void_p)
CS_SKIPDATA_CALLBACK = ctypes.CFUNCTYPE(ctypes.c_size_t, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t,
ctypes.c_size_t, ctypes.c_void_p)
class _cs_opt_skipdata(ctypes.Structure):
_fields_ = (
@@ -609,17 +631,20 @@ class _cs_opt_skipdata(ctypes.Structure):
('user_data', ctypes.c_void_p),
)
class _cs_opt_mnem(ctypes.Structure):
_fields_ = (
('id', ctypes.c_uint),
('mnemonic', ctypes.c_char_p),
)
# setup all the function prototype
def _setup_prototype(lib, fname, restype, *argtypes):
getattr(lib, fname).restype = restype
getattr(lib, fname).argtypes = argtypes
_setup_prototype(_cs, "cs_open", ctypes.c_int, ctypes.c_uint, ctypes.c_uint, ctypes.POINTER(ctypes.c_size_t))
_setup_prototype(_cs, "cs_disasm", ctypes.c_size_t, ctypes.c_size_t, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t, \
ctypes.c_uint64, ctypes.c_size_t, ctypes.POINTER(ctypes.POINTER(_cs_insn)))
@@ -709,6 +734,7 @@ def cs_disasm_quick(arch, mode, code, offset, count=0):
if status != CS_ERR_OK:
raise CsError(status)
# Another quick, but lighter function to disasm raw binary code.
# This function is faster than cs_disasm_quick() around 20% because
# cs_disasm_lite() only return tuples of (address, size, mnemonic, op_str),
@@ -750,6 +776,7 @@ def cs_disasm_lite(arch, mode, code, offset, count=0):
if status != CS_ERR_OK:
raise CsError(status)
def _ascii_name_or_default(name, default):
return default if name is None else name.decode('ascii')
@@ -762,11 +789,12 @@ class CsInsn(object):
if self._cs._detail and self._raw.id != 0:
# save detail
self._raw.detail = ctypes.pointer(all_info.detail._type_())
ctypes.memmove(ctypes.byref(self._raw.detail[0]), ctypes.byref(all_info.detail[0]), ctypes.sizeof(type(all_info.detail[0])))
ctypes.memmove(ctypes.byref(self._raw.detail[0]), ctypes.byref(all_info.detail[0]),
ctypes.sizeof(type(all_info.detail[0])))
def __repr__(self):
return '<CsInsn 0x%x [%s]: %s %s>' % (self.address, self.bytes.hex(), self.mnemonic, self.op_str)
# return instruction's ID.
@property
def id(self):
@@ -864,7 +892,7 @@ class CsInsn(object):
return self._raw.detail.contents.groups[:self._raw.detail.contents.groups_count]
raise CsError(CS_ERR_DETAIL)
# return whether instruction has writeback operands.
@property
def writeback(self):
@@ -888,7 +916,7 @@ class CsInsn(object):
arch = self._cs.arch
if arch == CS_ARCH_ARM:
(self.usermode, self.vector_size, self.vector_data, self.cps_mode, self.cps_flag, self.cc, self.vcc, self.update_flags, \
self.post_index, self.mem_barrier, self.pred_mask, self.operands) = arm.get_arch_info(self._raw.detail.contents.arch.arm)
self.post_index, self.mem_barrier, self.pred_mask, self.operands) = arm.get_arch_info(self._raw.detail.contents.arch.arm)
elif arch == CS_ARCH_AARCH64:
(self.cc, self.update_flags, self.post_index, self.operands) = \
aarch64.get_arch_info(self._raw.detail.contents.arch.aarch64)
@@ -936,7 +964,8 @@ class CsInsn(object):
(self.operands) = hppa.get_arch_info(self._raw.detail.contents.arch.hppa)
elif arch == CS_ARCH_LOONGARCH:
(self.format, self.operands) = loongarch.get_arch_info(self._raw.detail.contents.arch.loongarch)
elif arch == CS_ARCH_XTENSA:
(self.operands) = xtensa.get_arch_info(self._raw.detail.contents.arch.xtensa)
def __getattr__(self, name):
if not self._cs._detail:
@@ -985,7 +1014,6 @@ class CsInsn(object):
return _ascii_name_or_default(_cs.cs_group_name(self._cs.csh, group_id), default)
# verify if this insn belong to group with id as @group_id
def group(self, group_id):
if self._raw.id == 0:
@@ -1053,7 +1081,8 @@ class CsInsn(object):
regs_write = (ctypes.c_uint16 * 64)()
regs_write_count = ctypes.c_uint8()
status = _cs.cs_regs_access(self._cs.csh, self._raw, ctypes.byref(regs_read), ctypes.byref(regs_read_count), ctypes.byref(regs_write), ctypes.byref(regs_write_count))
status = _cs.cs_regs_access(self._cs.csh, self._raw, ctypes.byref(regs_read), ctypes.byref(regs_read_count),
ctypes.byref(regs_write), ctypes.byref(regs_write_count))
if status != CS_ERR_OK:
raise CsError(status)
@@ -1070,7 +1099,6 @@ class CsInsn(object):
return (regs_read, regs_write)
class Cs(object):
def __init__(self, arch, mode):
# verify version compatibility with the core before doing anything
@@ -1113,8 +1141,6 @@ class Cs(object):
self._skipdata_opt = _cs_opt_skipdata()
self._skipdata = False
# destructor to be called automatically when object is destroyed.
def __del__(self):
if self.csh:
@@ -1136,25 +1162,21 @@ class Cs(object):
elif opt_type == CS_OPT_UNSIGNED:
self._imm_unsigned = opt_value == CS_OPT_ON
# is this a diet engine?
@property
def diet(self):
return self._diet
# is this engine compiled with X86-reduce option?
@property
def x86_reduce(self):
return self._x86reduce
# return assembly syntax.
@property
def syntax(self):
return self._syntax
# syntax setter: modify assembly syntax.
@syntax.setter
def syntax(self, style):
@@ -1164,13 +1186,11 @@ class Cs(object):
# save syntax
self._syntax = style
# return current skipdata status
@property
def skipdata(self):
return self._skipdata
# setter: modify skipdata status
@skipdata.setter
def skipdata(self, opt):
@@ -1184,41 +1204,36 @@ class Cs(object):
# save this option
self._skipdata = opt
@property
def skipdata_setup(self):
return (self._skipdata_mnem,) + self._skipdata_cb
@skipdata_setup.setter
def skipdata_setup(self, opt):
_mnem, _cb, _ud = opt
self._skipdata_opt.mnemonic = _mnem.encode()
self._skipdata_opt.callback = CS_SKIPDATA_CALLBACK(_cb or 0)
self._skipdata_opt.user_data = ctypes.cast(_ud, ctypes.c_void_p)
status = _cs.cs_option(self.csh, CS_OPT_SKIPDATA_SETUP, ctypes.cast(ctypes.byref(self._skipdata_opt), ctypes.c_void_p))
status = _cs.cs_option(self.csh, CS_OPT_SKIPDATA_SETUP,
ctypes.cast(ctypes.byref(self._skipdata_opt), ctypes.c_void_p))
if status != CS_ERR_OK:
raise CsError(status)
self._skipdata_mnem = _mnem
self._skipdata_cb = (_cb, _ud)
@property
def skipdata_mnem(self):
return self._skipdata_mnem
@skipdata_mnem.setter
def skipdata_mnem(self, mnem):
self.skipdata_setup = (mnem,) + self._skipdata_cb
@property
def skipdata_callback(self):
return self._skipdata_cb
@skipdata_callback.setter
def skipdata_callback(self, val):
if not isinstance(val, tuple):
@@ -1226,7 +1241,6 @@ class Cs(object):
func, data = val
self.skipdata_setup = (self._skipdata_mnem, func, data)
# customize instruction mnemonic
def mnemonic_setup(self, id, mnem):
_mnem_opt = _cs_opt_mnem()
@@ -1239,19 +1253,16 @@ class Cs(object):
if status != CS_ERR_OK:
raise CsError(status)
# check to see if this engine supports a particular arch,
# or diet mode (depending on @query).
def support(self, query):
return cs_support(query)
# is detail mode enable?
@property
def detail(self):
return self._detail
# modify detail mode.
@detail.setter
def detail(self, opt): # opt is boolean type, so must be either 'True' or 'False'
@@ -1264,13 +1275,11 @@ class Cs(object):
# save detail
self._detail = opt
# is detail mode enable?
@property
def imm_unsigned(self):
return self._imm_unsigned
# modify detail mode.
@imm_unsigned.setter
def imm_unsigned(self, opt): # opt is boolean type, so must be either 'True' or 'False'
@@ -1283,13 +1292,11 @@ class Cs(object):
# save detail
self._imm_unsigned = opt
# return disassembly mode of this engine.
@property
def mode(self):
return self._mode
# modify engine's mode at run-time.
@mode.setter
def mode(self, opt): # opt is new disasm mode, of int type
@@ -1368,14 +1375,15 @@ class Cs(object):
code = ctypes.pointer(ctypes.c_char.from_buffer_copy(view))
if view.readonly:
code = (ctypes.c_char * len(view)).from_buffer_copy(view)
else:
else:
code = ctypes.pointer(ctypes.c_char.from_buffer(view))
# since we are taking a pointer to a pointer, ctypes does not do
# the typical auto conversion, so we have to cast it here.
code = ctypes.cast(code, ctypes.POINTER(ctypes.c_char))
address = ctypes.c_uint64(offset)
while _cs.cs_disasm_iter(self.csh, ctypes.byref(code), ctypes.byref(size), ctypes.byref(address), ctypes.byref(insn)):
while _cs.cs_disasm_iter(self.csh, ctypes.byref(code), ctypes.byref(size), ctypes.byref(address),
ctypes.byref(insn)):
yield (insn.address, insn.size, insn.mnemonic.decode('ascii'), insn.op_str.decode('ascii'))
# Light function to disassemble binary. This is about 20% faster than disasm() because
@@ -1432,7 +1440,7 @@ def debug():
"m680x": CS_ARCH_M680X, 'evm': CS_ARCH_EVM, 'mos65xx': CS_ARCH_MOS65XX,
'bpf': CS_ARCH_BPF, 'riscv': CS_ARCH_RISCV, 'tricore': CS_ARCH_TRICORE,
'wasm': CS_ARCH_WASM, 'sh': CS_ARCH_SH, 'alpha': CS_ARCH_ALPHA,
'hppa': CS_ARCH_HPPA, 'loongarch': CS_ARCH_LOONGARCH
'hppa': CS_ARCH_HPPA, 'loongarch': CS_ARCH_LOONGARCH, 'xtensa': CS_ARCH_XTENSA
}
all_archs = ""

View File

@@ -52,14 +52,14 @@ class AArch64SysOpSysReg(ctypes.Union):
('sysreg', ctypes.c_uint),
('tlbi', ctypes.c_uint),
('ic', ctypes.c_uint),
('raw_val', ctypes.c_uint64),
('raw_val', ctypes.c_int),
)
class AArch64SysOpSysImm(ctypes.Union):
_fields_ = (
('dbnxs', ctypes.c_uint),
('exactfpimm', ctypes.c_uint),
('raw_val', ctypes.c_uint64),
('raw_val', ctypes.c_int),
)
class AArch64SysOpSysAlias(ctypes.Union):
@@ -79,7 +79,7 @@ class AArch64SysOpSysAlias(ctypes.Union):
('bti', ctypes.c_uint),
('svepredpat', ctypes.c_uint),
('sveveclenspecifier', ctypes.c_uint),
('raw_val', ctypes.c_uint64),
('raw_val', ctypes.c_int),
)
class AArch64SysOp(ctypes.Structure):
_fields_ = (
@@ -96,7 +96,6 @@ class AArch64OpValue(ctypes.Union):
('imm_range', AArch64ImmRange),
('fp', ctypes.c_double),
('mem', AArch64OpMem),
('sysop', AArch64SysOp),
('sme', AArch64OpSme),
('pred', AArch64OpPred),
)
@@ -110,6 +109,7 @@ class AArch64Op(ctypes.Structure):
('type', ctypes.c_uint),
('is_vreg', ctypes.c_bool),
('value', AArch64OpValue),
('sysop', AArch64SysOp),
('access', ctypes.c_uint8),
('is_list_member', ctypes.c_bool),
)
@@ -136,7 +136,7 @@ class AArch64Op(ctypes.Structure):
@property
def sysop(self):
return self.value.sysop
return self.sysop
@property
def sme(self):

View File

@@ -2359,12 +2359,6 @@ AARCH64_REG_IP1 = AARCH64_REG_X17
AARCH64_REG_X29 = AARCH64_REG_FP
AARCH64_REG_X30 = AARCH64_REG_LR
AARCH64_SME_MATRIX_TILE = 0
AARCH64_SME_MATRIX_TILE_LIST = 1
AARCH64_SME_MATRIX_SLICE_REG = 2
AARCH64_SME_MATRIX_SLICE_OFF = 3
AARCH64_SME_MATRIX_SLICE_OFF_RANGE = 4
AARCH64_SME_OP_INVALID = 0
AARCH64_SME_OP_TILE = 1
AARCH64_SME_OP_TILE_VEC = 2

View File

@@ -24,6 +24,7 @@ class ArmSysopReg(ctypes.Union):
_fields_ = (
('mclasssysreg', ctypes.c_uint),
('bankedreg', ctypes.c_uint),
('raw_val', ctypes.c_int),
)
class ArmOpSysop(ctypes.Structure):

View File

@@ -0,0 +1,4 @@
# Copyright © 2024 Peace-Maker <peacemakerctf@gmail.com>
# SPDX-License-Identifier: BSD-3
# Compatibility header with pre v6 API
from .arm64_const import *

View File

@@ -0,0 +1,18 @@
# Copyright © 2024 Peace-Maker <peacemakerctf@gmail.com>
# SPDX-License-Identifier: BSD-3
# Compatibility header with pre v6 API
import capstone
import capstone.aarch64_const
setattr(capstone, "CS_ARCH_ARM64", capstone.CS_ARCH_AARCH64)
setattr(capstone, "__all__", getattr(capstone, "__all__") + ["CS_ARCH_ARM64"])
globals().update(
(name.replace("AARCH64", "ARM64"), getattr(capstone.aarch64_const, name))
for name in capstone.aarch64_const.__dict__
if name.startswith("AARCH64")
)
globals().update(
(name.replace("AArch64CC", "ARM64_CC"), getattr(capstone.aarch64_const, name))
for name in capstone.aarch64_const.__dict__
if name.startswith("AArch64CC")
)

File diff suppressed because it is too large Load Diff

View File

@@ -7,13 +7,13 @@ from .bpf_const import *
class BPFOpMem(ctypes.Structure):
_fields_ = (
('base', ctypes.c_uint8),
('base', ctypes.c_int),
('disp', ctypes.c_int32),
)
class BPFOpValue(ctypes.Union):
_fields_ = (
('reg', ctypes.c_uint8),
('reg', ctypes.c_int),
('imm', ctypes.c_uint64),
('off', ctypes.c_uint32),
('mem', BPFOpMem),
@@ -26,6 +26,8 @@ class BPFOp(ctypes.Structure):
_fields_ = (
('type', ctypes.c_uint),
('value', BPFOpValue),
('is_signed', ctypes.c_bool),
('is_pkt', ctypes.c_bool),
('access', ctypes.c_uint8),
)
@@ -57,7 +59,6 @@ class BPFOp(ctypes.Structure):
def ext(self):
return self.value.ext
class CsBPF(ctypes.Structure):
_fields_ = (
('op_count', ctypes.c_uint8),

View File

@@ -83,7 +83,7 @@ BPF_INS_STXB = 50
BPF_INS_STXDW = 51
BPF_INS_XADDW = 52
BPF_INS_XADDDW = 53
BPF_INS_JMP = 54
BPF_INS_JA = 54
BPF_INS_JEQ = 55
BPF_INS_JGT = 56
BPF_INS_JGE = 57

View File

@@ -2382,6 +2382,15 @@ LOONGARCH_INS_XVSUB_W = 2048
LOONGARCH_INS_XVXORI_B = 2049
LOONGARCH_INS_XVXOR_V = 2050
LOONGARCH_INS_ENDING = 2051
LOONGARCH_INS_ALIAS_BEGIN = 2052
LOONGARCH_INS_ALIAS_LA = 2053
LOONGARCH_INS_ALIAS_LA_GLOBAL = 2054
LOONGARCH_INS_ALIAS_LA_LOCAL = 2055
LOONGARCH_INS_ALIAS_NOP = 2056
LOONGARCH_INS_ALIAS_MOVE = 2057
LOONGARCH_INS_ALIAS_RET = 2058
LOONGARCH_INS_ALIAS_JR = 2059
LOONGARCH_INS_ALIAS_END = 2060
# Group of LOONGARCH instructions

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
import ctypes
from . import copy_ctypes_list
from .systemz_const import *
# define the API
class SystemZOpMem(ctypes.Structure):

View File

@@ -0,0 +1,17 @@
# Copyright © 2024 Peace-Maker <peacemakerctf@gmail.com>
# SPDX-License-Identifier: BSD-3
# Compatibility header with pre v6 API
import capstone
import capstone.systemz
import capstone.systemz_const
setattr(capstone, "CS_ARCH_SYSZ", capstone.CS_ARCH_SYSTEMZ)
setattr(capstone, "__all__", getattr(capstone, "__all__") + ["CS_ARCH_SYSZ"])
compatibility_constants = [
(name.replace("SYSTEMZ", "SYSZ"), getattr(capstone.systemz_const, name))
for name in capstone.systemz_const.__dict__
if name.startswith("SYSTEMZ")
]
globals().update(compatibility_constants)
for name, value in compatibility_constants:
setattr(capstone.systemz, name, value)

View File

@@ -69,395 +69,395 @@ TRICORE_REG_A14_A15 = 60
TRICORE_REG_ENDING = 61
TRICORE_INS_INVALID = 0
TRICORE_INS_XOR_T = 1
TRICORE_INS_ABSDIFS_B = 2
TRICORE_INS_ABSDIFS_H = 3
TRICORE_INS_ABSDIFS = 4
TRICORE_INS_ABSDIF_B = 5
TRICORE_INS_ABSDIF_H = 6
TRICORE_INS_ABSDIF = 7
TRICORE_INS_ABSS_B = 8
TRICORE_INS_ABSS_H = 9
TRICORE_INS_ABSS = 10
TRICORE_INS_ABS_B = 11
TRICORE_INS_ABS_H = 12
TRICORE_INS_ABS = 13
TRICORE_INS_ADDC = 14
TRICORE_INS_ADDIH_A = 15
TRICORE_INS_ADDIH = 16
TRICORE_INS_ADDI = 17
TRICORE_INS_ADDSC_AT = 18
TRICORE_INS_ADDSC_A = 19
TRICORE_INS_ADDS_BU = 20
TRICORE_INS_ADDS_B = 21
TRICORE_INS_ADDS_H = 22
TRICORE_INS_ADDS_HU = 23
TRICORE_INS_ADDS_U = 24
TRICORE_INS_ADDS = 25
TRICORE_INS_ADDX = 26
TRICORE_INS_ADD_A = 27
TRICORE_INS_ADD_B = 28
TRICORE_INS_ADD_F = 29
TRICORE_INS_ADD_H = 30
TRICORE_INS_ADD = 31
TRICORE_INS_ANDN_T = 32
TRICORE_INS_ANDN = 33
TRICORE_INS_AND_ANDN_T = 34
TRICORE_INS_AND_AND_T = 35
TRICORE_INS_AND_EQ = 36
TRICORE_INS_AND_GE_U = 37
TRICORE_INS_AND_GE = 38
TRICORE_INS_AND_LT_U = 39
TRICORE_INS_AND_LT = 40
TRICORE_INS_AND_NE = 41
TRICORE_INS_AND_NOR_T = 42
TRICORE_INS_AND_OR_T = 43
TRICORE_INS_AND_T = 44
TRICORE_INS_AND = 45
TRICORE_INS_BISR = 46
TRICORE_INS_BMERGE = 47
TRICORE_INS_BSPLIT = 48
TRICORE_INS_CACHEA_I = 49
TRICORE_INS_CACHEA_WI = 50
TRICORE_INS_CACHEA_W = 51
TRICORE_INS_CACHEI_I = 52
TRICORE_INS_CACHEI_WI = 53
TRICORE_INS_CACHEI_W = 54
TRICORE_INS_CADDN_A = 55
TRICORE_INS_CADDN = 56
TRICORE_INS_CADD_A = 57
TRICORE_INS_CADD = 58
TRICORE_INS_CALLA = 59
TRICORE_INS_CALLI = 60
TRICORE_INS_CALL = 61
TRICORE_INS_CLO_B = 62
TRICORE_INS_CLO_H = 63
TRICORE_INS_CLO = 64
TRICORE_INS_CLS_B = 65
TRICORE_INS_CLS_H = 66
TRICORE_INS_CLS = 67
TRICORE_INS_CLZ_B = 68
TRICORE_INS_CLZ_H = 69
TRICORE_INS_CLZ = 70
TRICORE_INS_CMOVN = 71
TRICORE_INS_CMOV = 72
TRICORE_INS_CMPSWAP_W = 73
TRICORE_INS_CMP_F = 74
TRICORE_INS_CRC32B_W = 75
TRICORE_INS_CRC32L_W = 76
TRICORE_INS_CRC32_B = 77
TRICORE_INS_CRCN = 78
TRICORE_INS_CSUBN_A = 79
TRICORE_INS_CSUBN = 80
TRICORE_INS_CSUB_A = 81
TRICORE_INS_CSUB = 82
TRICORE_INS_DEBUG = 83
TRICORE_INS_DEXTR = 84
TRICORE_INS_DIFSC_A = 85
TRICORE_INS_DISABLE = 86
TRICORE_INS_DIV_F = 87
TRICORE_INS_DIV_U = 88
TRICORE_INS_DIV = 89
TRICORE_INS_DSYNC = 90
TRICORE_INS_DVADJ = 91
TRICORE_INS_DVINIT_BU = 92
TRICORE_INS_DVINIT_B = 93
TRICORE_INS_DVINIT_HU = 94
TRICORE_INS_DVINIT_H = 95
TRICORE_INS_DVINIT_U = 96
TRICORE_INS_DVINIT = 97
TRICORE_INS_DVSTEP_U = 98
TRICORE_INS_DVSTEP = 99
TRICORE_INS_ENABLE = 100
TRICORE_INS_EQANY_B = 101
TRICORE_INS_EQANY_H = 102
TRICORE_INS_EQZ_A = 103
TRICORE_INS_EQ_A = 104
TRICORE_INS_EQ_B = 105
TRICORE_INS_EQ_H = 106
TRICORE_INS_EQ_W = 107
TRICORE_INS_EQ = 108
TRICORE_INS_EXTR_U = 109
TRICORE_INS_EXTR = 110
TRICORE_INS_FCALLA = 111
TRICORE_INS_FCALLI = 112
TRICORE_INS_FCALL = 113
TRICORE_INS_FRET = 114
TRICORE_INS_FTOHP = 115
TRICORE_INS_FTOIZ = 116
TRICORE_INS_FTOI = 117
TRICORE_INS_FTOQ31Z = 118
TRICORE_INS_FTOQ31 = 119
TRICORE_INS_FTOUZ = 120
TRICORE_INS_FTOU = 121
TRICORE_INS_GE_A = 122
TRICORE_INS_GE_U = 123
TRICORE_INS_GE = 124
TRICORE_INS_HPTOF = 125
TRICORE_INS_IMASK = 126
TRICORE_INS_INSERT = 127
TRICORE_INS_INSN_T = 128
TRICORE_INS_INS_T = 129
TRICORE_INS_ISYNC = 130
TRICORE_INS_ITOF = 131
TRICORE_INS_IXMAX_U = 132
TRICORE_INS_IXMAX = 133
TRICORE_INS_IXMIN_U = 134
TRICORE_INS_IXMIN = 135
TRICORE_INS_JA = 136
TRICORE_INS_JEQ_A = 137
TRICORE_INS_JEQ = 138
TRICORE_INS_JGEZ = 139
TRICORE_INS_JGE_U = 140
TRICORE_INS_JGE = 141
TRICORE_INS_JGTZ = 142
TRICORE_INS_JI = 143
TRICORE_INS_JLA = 144
TRICORE_INS_JLEZ = 145
TRICORE_INS_JLI = 146
TRICORE_INS_JLTZ = 147
TRICORE_INS_JLT_U = 148
TRICORE_INS_JLT = 149
TRICORE_INS_JL = 150
TRICORE_INS_JNED = 151
TRICORE_INS_JNEI = 152
TRICORE_INS_JNE_A = 153
TRICORE_INS_JNE = 154
TRICORE_INS_JNZ_A = 155
TRICORE_INS_JNZ_T = 156
TRICORE_INS_JNZ = 157
TRICORE_INS_JZ_A = 158
TRICORE_INS_JZ_T = 159
TRICORE_INS_JZ = 160
TRICORE_INS_J = 161
TRICORE_INS_LDLCX = 162
TRICORE_INS_LDMST = 163
TRICORE_INS_LDUCX = 164
TRICORE_INS_LD_A = 165
TRICORE_INS_LD_BU = 166
TRICORE_INS_LD_B = 167
TRICORE_INS_LD_DA = 168
TRICORE_INS_LD_D = 169
TRICORE_INS_LD_HU = 170
TRICORE_INS_LD_H = 171
TRICORE_INS_LD_Q = 172
TRICORE_INS_LD_W = 173
TRICORE_INS_LEA = 174
TRICORE_INS_LHA = 175
TRICORE_INS_LOOPU = 176
TRICORE_INS_LOOP = 177
TRICORE_INS_LT_A = 178
TRICORE_INS_LT_B = 179
TRICORE_INS_LT_BU = 180
TRICORE_INS_LT_H = 181
TRICORE_INS_LT_HU = 182
TRICORE_INS_LT_U = 183
TRICORE_INS_LT_W = 184
TRICORE_INS_LT_WU = 185
TRICORE_INS_LT = 186
TRICORE_INS_MADDMS_H = 187
TRICORE_INS_MADDMS_U = 188
TRICORE_INS_MADDMS = 189
TRICORE_INS_MADDM_H = 190
TRICORE_INS_MADDM_Q = 191
TRICORE_INS_MADDM_U = 192
TRICORE_INS_MADDM = 193
TRICORE_INS_MADDRS_H = 194
TRICORE_INS_MADDRS_Q = 195
TRICORE_INS_MADDR_H = 196
TRICORE_INS_MADDR_Q = 197
TRICORE_INS_MADDSUMS_H = 198
TRICORE_INS_MADDSUM_H = 199
TRICORE_INS_MADDSURS_H = 200
TRICORE_INS_MADDSUR_H = 201
TRICORE_INS_MADDSUS_H = 202
TRICORE_INS_MADDSU_H = 203
TRICORE_INS_MADDS_H = 204
TRICORE_INS_MADDS_Q = 205
TRICORE_INS_MADDS_U = 206
TRICORE_INS_MADDS = 207
TRICORE_INS_MADD_F = 208
TRICORE_INS_MADD_H = 209
TRICORE_INS_MADD_Q = 210
TRICORE_INS_MADD_U = 211
TRICORE_INS_MADD = 212
TRICORE_INS_MAX_B = 213
TRICORE_INS_MAX_BU = 214
TRICORE_INS_MAX_H = 215
TRICORE_INS_MAX_HU = 216
TRICORE_INS_MAX_U = 217
TRICORE_INS_MAX = 218
TRICORE_INS_MFCR = 219
TRICORE_INS_MIN_B = 220
TRICORE_INS_MIN_BU = 221
TRICORE_INS_MIN_H = 222
TRICORE_INS_MIN_HU = 223
TRICORE_INS_MIN_U = 224
TRICORE_INS_MIN = 225
TRICORE_INS_MOVH_A = 226
TRICORE_INS_MOVH = 227
TRICORE_INS_MOVZ_A = 228
TRICORE_INS_MOV_AA = 229
TRICORE_INS_MOV_A = 230
TRICORE_INS_MOV_D = 231
TRICORE_INS_MOV_U = 232
TRICORE_INS_MOV = 233
TRICORE_INS_MSUBADMS_H = 234
TRICORE_INS_MSUBADM_H = 235
TRICORE_INS_MSUBADRS_H = 236
TRICORE_INS_MSUBADR_H = 237
TRICORE_INS_MSUBADS_H = 238
TRICORE_INS_MSUBAD_H = 239
TRICORE_INS_MSUBMS_H = 240
TRICORE_INS_MSUBMS_U = 241
TRICORE_INS_MSUBMS = 242
TRICORE_INS_MSUBM_H = 243
TRICORE_INS_MSUBM_Q = 244
TRICORE_INS_MSUBM_U = 245
TRICORE_INS_MSUBM = 246
TRICORE_INS_MSUBRS_H = 247
TRICORE_INS_MSUBRS_Q = 248
TRICORE_INS_MSUBR_H = 249
TRICORE_INS_MSUBR_Q = 250
TRICORE_INS_MSUBS_H = 251
TRICORE_INS_MSUBS_Q = 252
TRICORE_INS_MSUBS_U = 253
TRICORE_INS_MSUBS = 254
TRICORE_INS_MSUB_F = 255
TRICORE_INS_MSUB_H = 256
TRICORE_INS_MSUB_Q = 257
TRICORE_INS_MSUB_U = 258
TRICORE_INS_MSUB = 259
TRICORE_INS_MTCR = 260
TRICORE_INS_MULMS_H = 261
TRICORE_INS_MULM_H = 262
TRICORE_INS_MULM_U = 263
TRICORE_INS_MULM = 264
TRICORE_INS_MULR_H = 265
TRICORE_INS_MULR_Q = 266
TRICORE_INS_MULS_U = 267
TRICORE_INS_MULS = 268
TRICORE_INS_MUL_F = 269
TRICORE_INS_MUL_H = 270
TRICORE_INS_MUL_Q = 271
TRICORE_INS_MUL_U = 272
TRICORE_INS_MUL = 273
TRICORE_INS_NAND_T = 274
TRICORE_INS_NAND = 275
TRICORE_INS_NEZ_A = 276
TRICORE_INS_NE_A = 277
TRICORE_INS_NE = 278
TRICORE_INS_NOP = 279
TRICORE_INS_NOR_T = 280
TRICORE_INS_NOR = 281
TRICORE_INS_NOT = 282
TRICORE_INS_ORN_T = 283
TRICORE_INS_ORN = 284
TRICORE_INS_OR_ANDN_T = 285
TRICORE_INS_OR_AND_T = 286
TRICORE_INS_OR_EQ = 287
TRICORE_INS_OR_GE_U = 288
TRICORE_INS_OR_GE = 289
TRICORE_INS_OR_LT_U = 290
TRICORE_INS_OR_LT = 291
TRICORE_INS_OR_NE = 292
TRICORE_INS_OR_NOR_T = 293
TRICORE_INS_OR_OR_T = 294
TRICORE_INS_OR_T = 295
TRICORE_INS_OR = 296
TRICORE_INS_PACK = 297
TRICORE_INS_PARITY = 298
TRICORE_INS_POPCNT_W = 299
TRICORE_INS_Q31TOF = 300
TRICORE_INS_QSEED_F = 301
TRICORE_INS_RESTORE = 302
TRICORE_INS_RET = 303
TRICORE_INS_RFE = 304
TRICORE_INS_RFM = 305
TRICORE_INS_RSLCX = 306
TRICORE_INS_RSTV = 307
TRICORE_INS_RSUBS_U = 308
TRICORE_INS_RSUBS = 309
TRICORE_INS_RSUB = 310
TRICORE_INS_SAT_BU = 311
TRICORE_INS_SAT_B = 312
TRICORE_INS_SAT_HU = 313
TRICORE_INS_SAT_H = 314
TRICORE_INS_SELN_A = 315
TRICORE_INS_SELN = 316
TRICORE_INS_SEL_A = 317
TRICORE_INS_SEL = 318
TRICORE_INS_SHAS = 319
TRICORE_INS_SHA_B = 320
TRICORE_INS_SHA_H = 321
TRICORE_INS_SHA = 322
TRICORE_INS_SHUFFLE = 323
TRICORE_INS_SH_ANDN_T = 324
TRICORE_INS_SH_AND_T = 325
TRICORE_INS_SH_B = 326
TRICORE_INS_SH_EQ = 327
TRICORE_INS_SH_GE_U = 328
TRICORE_INS_SH_GE = 329
TRICORE_INS_SH_H = 330
TRICORE_INS_SH_LT_U = 331
TRICORE_INS_SH_LT = 332
TRICORE_INS_SH_NAND_T = 333
TRICORE_INS_SH_NE = 334
TRICORE_INS_SH_NOR_T = 335
TRICORE_INS_SH_ORN_T = 336
TRICORE_INS_SH_OR_T = 337
TRICORE_INS_SH_XNOR_T = 338
TRICORE_INS_SH_XOR_T = 339
TRICORE_INS_SH = 340
TRICORE_INS_STLCX = 341
TRICORE_INS_STUCX = 342
TRICORE_INS_ST_A = 343
TRICORE_INS_ST_B = 344
TRICORE_INS_ST_DA = 345
TRICORE_INS_ST_D = 346
TRICORE_INS_ST_H = 347
TRICORE_INS_ST_Q = 348
TRICORE_INS_ST_T = 349
TRICORE_INS_ST_W = 350
TRICORE_INS_SUBC = 351
TRICORE_INS_SUBSC_A = 352
TRICORE_INS_SUBS_BU = 353
TRICORE_INS_SUBS_B = 354
TRICORE_INS_SUBS_HU = 355
TRICORE_INS_SUBS_H = 356
TRICORE_INS_SUBS_U = 357
TRICORE_INS_SUBS = 358
TRICORE_INS_SUBX = 359
TRICORE_INS_SUB_A = 360
TRICORE_INS_SUB_B = 361
TRICORE_INS_SUB_F = 362
TRICORE_INS_SUB_H = 363
TRICORE_INS_SUB = 364
TRICORE_INS_SVLCX = 365
TRICORE_INS_SWAPMSK_W = 366
TRICORE_INS_SWAP_A = 367
TRICORE_INS_SWAP_W = 368
TRICORE_INS_SYSCALL = 369
TRICORE_INS_TLBDEMAP = 370
TRICORE_INS_TLBFLUSH_A = 371
TRICORE_INS_TLBFLUSH_B = 372
TRICORE_INS_TLBMAP = 373
TRICORE_INS_TLBPROBE_A = 374
TRICORE_INS_TLBPROBE_I = 375
TRICORE_INS_TRAPSV = 376
TRICORE_INS_TRAPV = 377
TRICORE_INS_UNPACK = 378
TRICORE_INS_UPDFL = 379
TRICORE_INS_UTOF = 380
TRICORE_INS_WAIT = 381
TRICORE_INS_XNOR_T = 382
TRICORE_INS_XNOR = 383
TRICORE_INS_XOR_EQ = 384
TRICORE_INS_XOR_GE_U = 385
TRICORE_INS_XOR_GE = 386
TRICORE_INS_XOR_LT_U = 387
TRICORE_INS_XOR_LT = 388
TRICORE_INS_XOR_NE = 389
TRICORE_INS_ABSDIFS_B = 1
TRICORE_INS_ABSDIFS_H = 2
TRICORE_INS_ABSDIFS = 3
TRICORE_INS_ABSDIF_B = 4
TRICORE_INS_ABSDIF_H = 5
TRICORE_INS_ABSDIF = 6
TRICORE_INS_ABSS_B = 7
TRICORE_INS_ABSS_H = 8
TRICORE_INS_ABSS = 9
TRICORE_INS_ABS_B = 10
TRICORE_INS_ABS_H = 11
TRICORE_INS_ABS = 12
TRICORE_INS_ADDC = 13
TRICORE_INS_ADDIH_A = 14
TRICORE_INS_ADDIH = 15
TRICORE_INS_ADDI = 16
TRICORE_INS_ADDSC_AT = 17
TRICORE_INS_ADDSC_A = 18
TRICORE_INS_ADDS_BU = 19
TRICORE_INS_ADDS_B = 20
TRICORE_INS_ADDS_H = 21
TRICORE_INS_ADDS_HU = 22
TRICORE_INS_ADDS_U = 23
TRICORE_INS_ADDS = 24
TRICORE_INS_ADDX = 25
TRICORE_INS_ADD_A = 26
TRICORE_INS_ADD_B = 27
TRICORE_INS_ADD_F = 28
TRICORE_INS_ADD_H = 29
TRICORE_INS_ADD = 30
TRICORE_INS_ANDN_T = 31
TRICORE_INS_ANDN = 32
TRICORE_INS_AND_ANDN_T = 33
TRICORE_INS_AND_AND_T = 34
TRICORE_INS_AND_EQ = 35
TRICORE_INS_AND_GE_U = 36
TRICORE_INS_AND_GE = 37
TRICORE_INS_AND_LT_U = 38
TRICORE_INS_AND_LT = 39
TRICORE_INS_AND_NE = 40
TRICORE_INS_AND_NOR_T = 41
TRICORE_INS_AND_OR_T = 42
TRICORE_INS_AND_T = 43
TRICORE_INS_AND = 44
TRICORE_INS_BISR = 45
TRICORE_INS_BMERGE = 46
TRICORE_INS_BSPLIT = 47
TRICORE_INS_CACHEA_I = 48
TRICORE_INS_CACHEA_WI = 49
TRICORE_INS_CACHEA_W = 50
TRICORE_INS_CACHEI_I = 51
TRICORE_INS_CACHEI_WI = 52
TRICORE_INS_CACHEI_W = 53
TRICORE_INS_CADDN_A = 54
TRICORE_INS_CADDN = 55
TRICORE_INS_CADD_A = 56
TRICORE_INS_CADD = 57
TRICORE_INS_CALLA = 58
TRICORE_INS_CALLI = 59
TRICORE_INS_CALL = 60
TRICORE_INS_CLO_B = 61
TRICORE_INS_CLO_H = 62
TRICORE_INS_CLO = 63
TRICORE_INS_CLS_B = 64
TRICORE_INS_CLS_H = 65
TRICORE_INS_CLS = 66
TRICORE_INS_CLZ_B = 67
TRICORE_INS_CLZ_H = 68
TRICORE_INS_CLZ = 69
TRICORE_INS_CMOVN = 70
TRICORE_INS_CMOV = 71
TRICORE_INS_CMPSWAP_W = 72
TRICORE_INS_CMP_F = 73
TRICORE_INS_CRC32B_W = 74
TRICORE_INS_CRC32L_W = 75
TRICORE_INS_CRC32_B = 76
TRICORE_INS_CRCN = 77
TRICORE_INS_CSUBN_A = 78
TRICORE_INS_CSUBN = 79
TRICORE_INS_CSUB_A = 80
TRICORE_INS_CSUB = 81
TRICORE_INS_DEBUG = 82
TRICORE_INS_DEXTR = 83
TRICORE_INS_DIFSC_A = 84
TRICORE_INS_DISABLE = 85
TRICORE_INS_DIV_F = 86
TRICORE_INS_DIV_U = 87
TRICORE_INS_DIV = 88
TRICORE_INS_DSYNC = 89
TRICORE_INS_DVADJ = 90
TRICORE_INS_DVINIT_BU = 91
TRICORE_INS_DVINIT_B = 92
TRICORE_INS_DVINIT_HU = 93
TRICORE_INS_DVINIT_H = 94
TRICORE_INS_DVINIT_U = 95
TRICORE_INS_DVINIT = 96
TRICORE_INS_DVSTEP_U = 97
TRICORE_INS_DVSTEP = 98
TRICORE_INS_ENABLE = 99
TRICORE_INS_EQANY_B = 100
TRICORE_INS_EQANY_H = 101
TRICORE_INS_EQZ_A = 102
TRICORE_INS_EQ_A = 103
TRICORE_INS_EQ_B = 104
TRICORE_INS_EQ_H = 105
TRICORE_INS_EQ_W = 106
TRICORE_INS_EQ = 107
TRICORE_INS_EXTR_U = 108
TRICORE_INS_EXTR = 109
TRICORE_INS_FCALLA = 110
TRICORE_INS_FCALLI = 111
TRICORE_INS_FCALL = 112
TRICORE_INS_FRET = 113
TRICORE_INS_FTOHP = 114
TRICORE_INS_FTOIZ = 115
TRICORE_INS_FTOI = 116
TRICORE_INS_FTOQ31Z = 117
TRICORE_INS_FTOQ31 = 118
TRICORE_INS_FTOUZ = 119
TRICORE_INS_FTOU = 120
TRICORE_INS_GE_A = 121
TRICORE_INS_GE_U = 122
TRICORE_INS_GE = 123
TRICORE_INS_HPTOF = 124
TRICORE_INS_IMASK = 125
TRICORE_INS_INSERT = 126
TRICORE_INS_INSN_T = 127
TRICORE_INS_INS_T = 128
TRICORE_INS_ISYNC = 129
TRICORE_INS_ITOF = 130
TRICORE_INS_IXMAX_U = 131
TRICORE_INS_IXMAX = 132
TRICORE_INS_IXMIN_U = 133
TRICORE_INS_IXMIN = 134
TRICORE_INS_JA = 135
TRICORE_INS_JEQ_A = 136
TRICORE_INS_JEQ = 137
TRICORE_INS_JGEZ = 138
TRICORE_INS_JGE_U = 139
TRICORE_INS_JGE = 140
TRICORE_INS_JGTZ = 141
TRICORE_INS_JI = 142
TRICORE_INS_JLA = 143
TRICORE_INS_JLEZ = 144
TRICORE_INS_JLI = 145
TRICORE_INS_JLTZ = 146
TRICORE_INS_JLT_U = 147
TRICORE_INS_JLT = 148
TRICORE_INS_JL = 149
TRICORE_INS_JNED = 150
TRICORE_INS_JNEI = 151
TRICORE_INS_JNE_A = 152
TRICORE_INS_JNE = 153
TRICORE_INS_JNZ_A = 154
TRICORE_INS_JNZ_T = 155
TRICORE_INS_JNZ = 156
TRICORE_INS_JZ_A = 157
TRICORE_INS_JZ_T = 158
TRICORE_INS_JZ = 159
TRICORE_INS_J = 160
TRICORE_INS_LDLCX = 161
TRICORE_INS_LDMST = 162
TRICORE_INS_LDUCX = 163
TRICORE_INS_LD_A = 164
TRICORE_INS_LD_BU = 165
TRICORE_INS_LD_B = 166
TRICORE_INS_LD_DA = 167
TRICORE_INS_LD_D = 168
TRICORE_INS_LD_HU = 169
TRICORE_INS_LD_H = 170
TRICORE_INS_LD_Q = 171
TRICORE_INS_LD_W = 172
TRICORE_INS_LEA = 173
TRICORE_INS_LHA = 174
TRICORE_INS_LOOPU = 175
TRICORE_INS_LOOP = 176
TRICORE_INS_LT_A = 177
TRICORE_INS_LT_B = 178
TRICORE_INS_LT_BU = 179
TRICORE_INS_LT_H = 180
TRICORE_INS_LT_HU = 181
TRICORE_INS_LT_U = 182
TRICORE_INS_LT_W = 183
TRICORE_INS_LT_WU = 184
TRICORE_INS_LT = 185
TRICORE_INS_MADDMS_H = 186
TRICORE_INS_MADDMS_U = 187
TRICORE_INS_MADDMS = 188
TRICORE_INS_MADDM_H = 189
TRICORE_INS_MADDM_Q = 190
TRICORE_INS_MADDM_U = 191
TRICORE_INS_MADDM = 192
TRICORE_INS_MADDRS_H = 193
TRICORE_INS_MADDRS_Q = 194
TRICORE_INS_MADDR_H = 195
TRICORE_INS_MADDR_Q = 196
TRICORE_INS_MADDSUMS_H = 197
TRICORE_INS_MADDSUM_H = 198
TRICORE_INS_MADDSURS_H = 199
TRICORE_INS_MADDSUR_H = 200
TRICORE_INS_MADDSUS_H = 201
TRICORE_INS_MADDSU_H = 202
TRICORE_INS_MADDS_H = 203
TRICORE_INS_MADDS_Q = 204
TRICORE_INS_MADDS_U = 205
TRICORE_INS_MADDS = 206
TRICORE_INS_MADD_F = 207
TRICORE_INS_MADD_H = 208
TRICORE_INS_MADD_Q = 209
TRICORE_INS_MADD_U = 210
TRICORE_INS_MADD = 211
TRICORE_INS_MAX_B = 212
TRICORE_INS_MAX_BU = 213
TRICORE_INS_MAX_H = 214
TRICORE_INS_MAX_HU = 215
TRICORE_INS_MAX_U = 216
TRICORE_INS_MAX = 217
TRICORE_INS_MFCR = 218
TRICORE_INS_MIN_B = 219
TRICORE_INS_MIN_BU = 220
TRICORE_INS_MIN_H = 221
TRICORE_INS_MIN_HU = 222
TRICORE_INS_MIN_U = 223
TRICORE_INS_MIN = 224
TRICORE_INS_MOVH_A = 225
TRICORE_INS_MOVH = 226
TRICORE_INS_MOVZ_A = 227
TRICORE_INS_MOV_AA = 228
TRICORE_INS_MOV_A = 229
TRICORE_INS_MOV_D = 230
TRICORE_INS_MOV_U = 231
TRICORE_INS_MOV = 232
TRICORE_INS_MSUBADMS_H = 233
TRICORE_INS_MSUBADM_H = 234
TRICORE_INS_MSUBADRS_H = 235
TRICORE_INS_MSUBADR_H = 236
TRICORE_INS_MSUBADS_H = 237
TRICORE_INS_MSUBAD_H = 238
TRICORE_INS_MSUBMS_H = 239
TRICORE_INS_MSUBMS_U = 240
TRICORE_INS_MSUBMS = 241
TRICORE_INS_MSUBM_H = 242
TRICORE_INS_MSUBM_Q = 243
TRICORE_INS_MSUBM_U = 244
TRICORE_INS_MSUBM = 245
TRICORE_INS_MSUBRS_H = 246
TRICORE_INS_MSUBRS_Q = 247
TRICORE_INS_MSUBR_H = 248
TRICORE_INS_MSUBR_Q = 249
TRICORE_INS_MSUBS_H = 250
TRICORE_INS_MSUBS_Q = 251
TRICORE_INS_MSUBS_U = 252
TRICORE_INS_MSUBS = 253
TRICORE_INS_MSUB_F = 254
TRICORE_INS_MSUB_H = 255
TRICORE_INS_MSUB_Q = 256
TRICORE_INS_MSUB_U = 257
TRICORE_INS_MSUB = 258
TRICORE_INS_MTCR = 259
TRICORE_INS_MULMS_H = 260
TRICORE_INS_MULM_H = 261
TRICORE_INS_MULM_U = 262
TRICORE_INS_MULM = 263
TRICORE_INS_MULR_H = 264
TRICORE_INS_MULR_Q = 265
TRICORE_INS_MULS_U = 266
TRICORE_INS_MULS = 267
TRICORE_INS_MUL_F = 268
TRICORE_INS_MUL_H = 269
TRICORE_INS_MUL_Q = 270
TRICORE_INS_MUL_U = 271
TRICORE_INS_MUL = 272
TRICORE_INS_NAND_T = 273
TRICORE_INS_NAND = 274
TRICORE_INS_NEZ_A = 275
TRICORE_INS_NE_A = 276
TRICORE_INS_NE = 277
TRICORE_INS_NOP = 278
TRICORE_INS_NOR_T = 279
TRICORE_INS_NOR = 280
TRICORE_INS_NOT = 281
TRICORE_INS_ORN_T = 282
TRICORE_INS_ORN = 283
TRICORE_INS_OR_ANDN_T = 284
TRICORE_INS_OR_AND_T = 285
TRICORE_INS_OR_EQ = 286
TRICORE_INS_OR_GE_U = 287
TRICORE_INS_OR_GE = 288
TRICORE_INS_OR_LT_U = 289
TRICORE_INS_OR_LT = 290
TRICORE_INS_OR_NE = 291
TRICORE_INS_OR_NOR_T = 292
TRICORE_INS_OR_OR_T = 293
TRICORE_INS_OR_T = 294
TRICORE_INS_OR = 295
TRICORE_INS_PACK = 296
TRICORE_INS_PARITY = 297
TRICORE_INS_POPCNT_W = 298
TRICORE_INS_Q31TOF = 299
TRICORE_INS_QSEED_F = 300
TRICORE_INS_RESTORE = 301
TRICORE_INS_RET = 302
TRICORE_INS_RFE = 303
TRICORE_INS_RFM = 304
TRICORE_INS_RSLCX = 305
TRICORE_INS_RSTV = 306
TRICORE_INS_RSUBS_U = 307
TRICORE_INS_RSUBS = 308
TRICORE_INS_RSUB = 309
TRICORE_INS_SAT_BU = 310
TRICORE_INS_SAT_B = 311
TRICORE_INS_SAT_HU = 312
TRICORE_INS_SAT_H = 313
TRICORE_INS_SELN_A = 314
TRICORE_INS_SELN = 315
TRICORE_INS_SEL_A = 316
TRICORE_INS_SEL = 317
TRICORE_INS_SHAS = 318
TRICORE_INS_SHA_B = 319
TRICORE_INS_SHA_H = 320
TRICORE_INS_SHA = 321
TRICORE_INS_SHUFFLE = 322
TRICORE_INS_SH_ANDN_T = 323
TRICORE_INS_SH_AND_T = 324
TRICORE_INS_SH_B = 325
TRICORE_INS_SH_EQ = 326
TRICORE_INS_SH_GE_U = 327
TRICORE_INS_SH_GE = 328
TRICORE_INS_SH_H = 329
TRICORE_INS_SH_LT_U = 330
TRICORE_INS_SH_LT = 331
TRICORE_INS_SH_NAND_T = 332
TRICORE_INS_SH_NE = 333
TRICORE_INS_SH_NOR_T = 334
TRICORE_INS_SH_ORN_T = 335
TRICORE_INS_SH_OR_T = 336
TRICORE_INS_SH_XNOR_T = 337
TRICORE_INS_SH_XOR_T = 338
TRICORE_INS_SH = 339
TRICORE_INS_STLCX = 340
TRICORE_INS_STUCX = 341
TRICORE_INS_ST_A = 342
TRICORE_INS_ST_B = 343
TRICORE_INS_ST_DA = 344
TRICORE_INS_ST_D = 345
TRICORE_INS_ST_H = 346
TRICORE_INS_ST_Q = 347
TRICORE_INS_ST_T = 348
TRICORE_INS_ST_W = 349
TRICORE_INS_SUBC = 350
TRICORE_INS_SUBSC_A = 351
TRICORE_INS_SUBS_BU = 352
TRICORE_INS_SUBS_B = 353
TRICORE_INS_SUBS_HU = 354
TRICORE_INS_SUBS_H = 355
TRICORE_INS_SUBS_U = 356
TRICORE_INS_SUBS = 357
TRICORE_INS_SUBX = 358
TRICORE_INS_SUB_A = 359
TRICORE_INS_SUB_B = 360
TRICORE_INS_SUB_F = 361
TRICORE_INS_SUB_H = 362
TRICORE_INS_SUB = 363
TRICORE_INS_SVLCX = 364
TRICORE_INS_SWAPMSK_W = 365
TRICORE_INS_SWAP_A = 366
TRICORE_INS_SWAP_W = 367
TRICORE_INS_SYSCALL = 368
TRICORE_INS_TLBDEMAP = 369
TRICORE_INS_TLBFLUSH_A = 370
TRICORE_INS_TLBFLUSH_B = 371
TRICORE_INS_TLBMAP = 372
TRICORE_INS_TLBPROBE_A = 373
TRICORE_INS_TLBPROBE_I = 374
TRICORE_INS_TRAPSV = 375
TRICORE_INS_TRAPV = 376
TRICORE_INS_UNPACK = 377
TRICORE_INS_UPDFL = 378
TRICORE_INS_UTOF = 379
TRICORE_INS_WAIT = 380
TRICORE_INS_XNOR_T = 381
TRICORE_INS_XNOR = 382
TRICORE_INS_XOR_EQ = 383
TRICORE_INS_XOR_GE_U = 384
TRICORE_INS_XOR_GE = 385
TRICORE_INS_XOR_LT_U = 386
TRICORE_INS_XOR_LT = 387
TRICORE_INS_XOR_NE = 388
TRICORE_INS_XOR_T = 389
TRICORE_INS_XOR = 390
TRICORE_INS_ENDING = 391
@@ -467,13 +467,23 @@ TRICORE_GRP_JUMP = 2
TRICORE_GRP_ENDING = 3
TRICORE_FEATURE_INVALID = 0
TRICORE_FEATURE_HasV110 = 128
TRICORE_FEATURE_HasV120_UP = 129
TRICORE_FEATURE_HasV130_UP = 130
TRICORE_FEATURE_HasV161 = 131
TRICORE_FEATURE_HasV160_UP = 132
TRICORE_FEATURE_HasV131_UP = 133
TRICORE_FEATURE_HasV161_UP = 134
TRICORE_FEATURE_HasV162 = 135
TRICORE_FEATURE_HasV162_UP = 136
TRICORE_FEATURE_ENDING = 137
TRICORE_FEATURE_HASV110 = 128
TRICORE_FEATURE_HASV120 = 129
TRICORE_FEATURE_HASV130 = 130
TRICORE_FEATURE_HASV131 = 131
TRICORE_FEATURE_HASV160 = 132
TRICORE_FEATURE_HASV161 = 133
TRICORE_FEATURE_HASV162 = 134
TRICORE_FEATURE_HASV120_UP = 135
TRICORE_FEATURE_HASV130_UP = 136
TRICORE_FEATURE_HASV131_UP = 137
TRICORE_FEATURE_HASV160_UP = 138
TRICORE_FEATURE_HASV161_UP = 139
TRICORE_FEATURE_HASV162_UP = 140
TRICORE_FEATURE_HASV120_DN = 141
TRICORE_FEATURE_HASV130_DN = 142
TRICORE_FEATURE_HASV131_DN = 143
TRICORE_FEATURE_HASV160_DN = 144
TRICORE_FEATURE_HASV161_DN = 145
TRICORE_FEATURE_HASV162_DN = 146
TRICORE_FEATURE_ENDING = 147

View File

@@ -0,0 +1,53 @@
# Capstone Python bindings, by billow <billow.fun@gmail.com>
import ctypes
from . import copy_ctypes_list
from .xtensa_const import *
class XtensaOpMem(ctypes.Structure):
_fields_ = (
("base", ctypes.c_uint8),
("disp", ctypes.c_int32),
)
class XtensaOpValue(ctypes.Union):
_fields_ = (
("reg", ctypes.c_uint8),
("imm", ctypes.c_int32),
("mem", XtensaOpMem),
)
class XtensaOp(ctypes.Structure):
_fields_ = (
("type", ctypes.c_uint8),
("access", ctypes.c_uint8),
("value", XtensaOpValue),
)
@property
def reg(self):
return self.value.reg
@property
def imm(self):
return self.value.imm
@property
def mem(self):
return self.value.mem
# Instruction structure
class CsXtensa(ctypes.Structure):
_fields_ = (
("op_count", ctypes.c_uint8),
("operands", XtensaOp * 8),
("format", ctypes.c_uint32),
)
def get_arch_info(a):
return copy_ctypes_list(a.operands[: a.op_count])

File diff suppressed because it is too large Load Diff

View File

@@ -5,14 +5,14 @@
name = "cstest_py"
version = "0.1.0"
dependencies = [
"pyyaml >= 6.0.2",
"capstone >= 5.0.0",
"pyyaml >= 6.0.2",
"capstone >= 5.0.0",
]
requires-python = ">= 3.8"
[tool.setuptools]
packages = ["cstest_py"]
package-dir = {"" = "src"}
package-dir = { "" = "src" }
[project.scripts]
cstest_py = "cstest_py.cstest:main"

View File

@@ -11,8 +11,8 @@ configs = {
},
"CS_OPT_SKIPDATA": {"type": cs.CS_OPT_SKIPDATA, "val": cs.CS_OPT_ON},
"CS_OPT_UNSIGNED": {"type": cs.CS_OPT_UNSIGNED, "val": cs.CS_OPT_ON},
"CS_OPT_NO_BRANCH_OFFSET": {
"type": cs.CS_OPT_NO_BRANCH_OFFSET,
"CS_OPT_ONLY_OFFSET_BRANCH": {
"type": cs.CS_OPT_ONLY_OFFSET_BRANCH,
"val": cs.CS_OPT_ON,
},
"CS_OPT_SYNTAX_DEFAULT": {

View File

@@ -7,7 +7,6 @@ from __future__ import annotations
import argparse
import logging
import subprocess as sp
import sys
import os
import yaml
@@ -405,34 +404,16 @@ class CSTest:
self.stats.print_evaluate()
def get_repo_root() -> str | None:
res = sp.run(["git", "rev-parse", "--show-toplevel"], capture_output=True)
if res.stderr:
log.error("Could not get repository root directory.")
return None
return res.stdout.decode("utf8").strip()
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
prog="Python CSTest",
description="Pyton binding cstest implementation.",
description="Python binding cstest implementation.",
)
parser.add_argument(
dest="search_dir",
help="Directory to search for .yaml test files.",
type=Path,
)
repo_root = get_repo_root()
if repo_root:
parser.add_argument(
dest="search_dir",
help="Directory to search for .yaml test files.",
default=Path(f"{repo_root}/tests/"),
type=Path,
)
else:
parser.add_argument(
dest="search_dir",
help="Directory to search for .yaml test files.",
required=True,
type=Path,
)
parser.add_argument(
"-e",
dest="exclude",

View File

@@ -752,29 +752,34 @@ def test_expected_aarch64(actual: CsInsn, expected: dict) -> bool:
return False
elif aop.type == AARCH64_OP_SYSREG:
if not compare_enum(
aop.value.sysop.sub_type, eop.get("sub_type"), "sub_type"
aop.sysop.sub_type, eop.get("sub_type"), "sub_type"
):
return False
if not compare_uint64(
aop.value.sysop.reg.raw_val, eop.get("sys_raw_val"), "sys_raw_val"
if not compare_int32(
aop.sysop.reg.raw_val, eop.get("sys_raw_val"), "sys_raw_val"
):
return False
elif aop.type == AARCH64_OP_SYSIMM:
if not compare_enum(
aop.value.sysop.sub_type, eop.get("sub_type"), "sub_type"
aop.sysop.sub_type, eop.get("sub_type"), "sub_type"
):
return False
if not compare_uint64(
aop.value.sysop.imm.raw_val, eop.get("sys_raw_val"), "sys_raw_val"
if not compare_int32(
aop.sysop.imm.raw_val, eop.get("sys_raw_val"), "sys_raw_val"
):
return False
# EXACTFPIMM operands
if not compare_fp(
aop.fp, eop.get("fp"), "fp"
):
return False
elif aop.type == AARCH64_OP_SYSALIAS:
if not compare_enum(
aop.value.sysop.sub_type, eop.get("sub_type"), "sub_type"
aop.sysop.sub_type, eop.get("sub_type"), "sub_type"
):
return False
if not compare_uint64(
aop.value.sysop.alias.raw_val, eop.get("sys_raw_val"), "sys_raw_val"
if not compare_int32(
aop.sysop.alias.raw_val, eop.get("sys_raw_val"), "sys_raw_val"
):
return False
elif aop.type == AARCH64_OP_PRED:
@@ -1187,6 +1192,10 @@ def test_expected_bpf(actual: CsInsn, expected: dict) -> bool:
return False
if not compare_enum(aop.access, eop.get("access"), "access"):
return False
if not compare_tbool(aop.is_pkt, eop.get("is_pkt"), "is_pkt"):
return False
if not compare_tbool(aop.is_signed, eop.get("is_signed"), "is_signed"):
return False
if aop.type == BPF_OP_REG:
if not compare_reg(actual, aop.reg, eop.get("reg"), "reg"):

View File

@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools"]
requires = ["setuptools", "build"]
build-backend = "setuptools.build_meta"

View File

@@ -1,33 +1,25 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 Antelox <anteloxrce@gmail.com>
# SPDX-License-Identifier: BSD-3
import glob
import logging
import os
import shutil
import sys
import platform
import logging
from setuptools import setup
from sysconfig import get_platform
from setuptools.command.build import build
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
from setuptools.command.bdist_egg import bdist_egg
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
SYSTEM = sys.platform
# adapted from commit e504b81 of Nguyen Tan Cong
# Reference: https://docs.python.org/2/library/platform.html#cross-platform
IS_64BITS = sys.maxsize > 2**32
# are we building from the repository or from a source distribution?
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
LIBS_DIR = os.path.join(ROOT_DIR, 'capstone', 'lib')
HEADERS_DIR = os.path.join(ROOT_DIR, 'capstone', 'include')
SRC_DIR = os.path.join(ROOT_DIR, 'src')
BUILD_DIR = SRC_DIR if os.path.exists(SRC_DIR) else os.path.join(ROOT_DIR, '../..')
BUILD_PYTHON = os.path.join(BUILD_DIR, 'build_python')
# Parse version from pkgconfig.mk
VERSION_DATA = {}
@@ -50,8 +42,8 @@ with open(os.path.join(BUILD_DIR, 'pkgconfig.mk')) as fp:
VERSION_DATA[k] = v
if 'PKG_MAJOR' not in VERSION_DATA or \
'PKG_MINOR' not in VERSION_DATA or \
'PKG_EXTRA' not in VERSION_DATA:
'PKG_MINOR' not in VERSION_DATA or \
'PKG_EXTRA' not in VERSION_DATA:
raise Exception("Malformed pkgconfig.mk")
if 'PKG_TAG' in VERSION_DATA:
@@ -59,18 +51,15 @@ if 'PKG_TAG' in VERSION_DATA:
else:
VERSION = '{PKG_MAJOR}.{PKG_MINOR}.{PKG_EXTRA}'.format(**VERSION_DATA)
if SYSTEM == 'darwin':
if sys.platform == 'darwin':
VERSIONED_LIBRARY_FILE = "libcapstone.{PKG_MAJOR}.dylib".format(**VERSION_DATA)
LIBRARY_FILE = "libcapstone.dylib"
STATIC_LIBRARY_FILE = 'libcapstone.a'
elif SYSTEM in ('win32', 'cygwin'):
elif sys.platform in ('win32', 'cygwin'):
VERSIONED_LIBRARY_FILE = "capstone.dll"
LIBRARY_FILE = "capstone.dll"
STATIC_LIBRARY_FILE = None
else:
VERSIONED_LIBRARY_FILE = "libcapstone.so.{PKG_MAJOR}".format(**VERSION_DATA)
LIBRARY_FILE = "libcapstone.so"
STATIC_LIBRARY_FILE = 'libcapstone.a'
def clean_bins():
@@ -79,7 +68,8 @@ def clean_bins():
def copy_sources():
"""Copy the C sources into the source directory.
"""
Copy the C sources into the source directory.
This rearranges the source files under the python distribution
directory.
"""
@@ -94,11 +84,11 @@ def copy_sources():
shutil.copytree(os.path.join(BUILD_DIR, "include"), os.path.join(SRC_DIR, "include"))
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.[ch]")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.m[dk]")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.in")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "LICENSES/*")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "README")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "*.TXT")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "RELEASE_NOTES")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "ChangeLog")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "CMakeLists.txt")))
for filename in src:
@@ -123,97 +113,69 @@ def build_libraries():
shutil.copytree(os.path.join(BUILD_DIR, 'include', 'capstone'), os.path.join(HEADERS_DIR, 'capstone'))
# if prebuilt libraries are available, use those and cancel build
if os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', LIBRARY_FILE)) and \
(not STATIC_LIBRARY_FILE or os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE))):
if os.path.exists(os.path.join(ROOT_DIR, 'prebuilt', LIBRARY_FILE)):
logger.info('Using prebuilt libraries')
shutil.copy(os.path.join(ROOT_DIR, 'prebuilt', LIBRARY_FILE), LIBS_DIR)
if STATIC_LIBRARY_FILE is not None:
shutil.copy(os.path.join(ROOT_DIR, 'prebuilt', STATIC_LIBRARY_FILE), LIBS_DIR)
return
os.chdir(BUILD_DIR)
if not os.path.exists(BUILD_PYTHON):
os.mkdir(BUILD_PYTHON)
# Windows build: this process requires few things:
# - MSVC installed
# - Run this command in an environment setup for MSVC
if not os.path.exists("build_py"):
os.mkdir("build_py")
os.chdir("build_py")
print("Build Directory: {}\n".format(os.getcwd()))
# Only build capstone.dll / libcapstone.dylib
if SYSTEM == "win32":
os.system('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCAPSTONE_BUILD_LEGACY_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -G "NMake Makefiles" ..')
logger.info("Build Directory: {}\n".format(BUILD_PYTHON))
conf = 'Debug' if int(os.getenv('DEBUG', 0)) else 'Release'
cmake_args = ['cmake',
'-DCAPSTONE_BUILD_SHARED_LIBS=ON',
'-DCAPSTONE_BUILD_STATIC_LIBS=OFF',
'-DCAPSTONE_BUILD_LEGACY_TESTS=OFF',
'-DCAPSTONE_BUILD_CSTOOL=OFF'
]
cmake_build = ['cmake',
'--build',
'.'
]
os.chdir(BUILD_PYTHON)
if sys.platform in ('win32', 'cygwin'):
# Windows build: this process requires few things:
# - MSVC installed
# - Run this command in an environment setup for MSVC
cmake_args += ['-DCMAKE_BUILD_TYPE=' + conf,
'-G "NMake Makefiles"'
]
elif 'AFL_NOOPT' in os.environ:
# build for test_corpus
os.system('cmake -DBUILD_SHARED_LIBS=ON -DCAPSTONE_BUILD_LEGACY_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF ..')
pass
else:
os.system('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCAPSTONE_BUILD_LEGACY_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -G "Unix Makefiles" ..')
os.system("cmake --build .")
cmake_args += ['-DCMAKE_BUILD_TYPE=' + conf,
'-G "Unix Makefiles"'
]
cmake_build += ['-j', str(os.getenv("THREADS", "4"))]
os.system(' '.join(cmake_args + ['..']))
os.system(' '.join(cmake_build))
shutil.copy(VERSIONED_LIBRARY_FILE, os.path.join(LIBS_DIR, LIBRARY_FILE))
# only copy static library if it exists (it's a build option)
if STATIC_LIBRARY_FILE and os.path.exists(STATIC_LIBRARY_FILE):
shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR)
os.chdir(cwd)
class custom_sdist(sdist):
class CustomSDist(sdist):
def run(self):
clean_bins()
copy_sources()
return sdist.run(self)
return super().run()
class custom_build(build):
class CustomBuild(build_py):
def run(self):
if 'LIBCAPSTONE_PATH' in os.environ:
logger.info('Skipping building C extensions since LIBCAPSTONE_PATH is set')
else:
logger.info('Building C extensions')
build_libraries()
return build.run(self)
return super().run()
class custom_bdist_egg(bdist_egg):
def run(self):
self.run_command('build')
return bdist_egg.run(self)
cmdclass = {}
cmdclass['build'] = custom_build
cmdclass['sdist'] = custom_sdist
cmdclass['bdist_egg'] = custom_bdist_egg
try:
from setuptools.command.develop import develop
class custom_develop(develop):
def run(self):
logger.info("Building C extensions")
build_libraries()
return develop.run(self)
cmdclass['develop'] = custom_develop
except ImportError:
print("Proper 'develop' support unavailable.")
if 'bdist_wheel' in sys.argv and '--plat-name' not in sys.argv:
# Inject the platform identifier into argv.
# Platform tags are described here:
# https://packaging.python.org/en/latest/specifications/platform-compatibility-tags
#
# I couldn't really find out in time why we need to inject the platform here?
# The cibuildwheel doesn't need it for the Windows job. But for Mac and Linux.
# This here is very dirty and will maybe break in the future.
# Sorry if this is the case and you read this.
# See: https://github.com/capstone-engine/capstone/issues/2445
idx = sys.argv.index('bdist_wheel') + 1
sys.argv.insert(idx, '--plat-name')
name = get_platform()
sys.argv.insert(idx + 1, name.replace('.', '_').replace('-', '_'))
setup(
provides=['capstone'],
packages=['capstone'],
@@ -228,14 +190,18 @@ setup(
python_requires='>=3.8',
classifiers=[
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
],
cmdclass=cmdclass,
zip_safe=False,
include_package_data=True,
cmdclass={'build_py': CustomBuild, 'sdist': CustomSDist},
package_data={
"capstone": ["lib/*", "include/capstone/*"],
},
has_ext_modules=lambda: True, # It's not a Pure Python wheel
install_requires=[
"importlib_resources;python_version<'3.9'",
],

View File

@@ -1,9 +1,20 @@
#!/usr/bin/env python3
import test_lite
import test_iter
import test_skipdata
import test_customized_mnem
import test_compatibility_layer
test_lite.test_class()
test_skipdata.test_class()
test_customized_mnem.test()
errors = []
errors.extend(test_lite.test_class())
errors.extend(test_iter.test_class())
errors.extend(test_skipdata.test_class())
errors.extend(test_customized_mnem.test())
errors.extend(test_compatibility_layer.test_compatibility())
if errors:
print("Some errors happened. Please check the output")
for error in errors:
print(error)
exit(1)

View File

@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# Copyright © 2024 Peace-Maker <peacemakerctf@gmail.com>
# SPDX-License-Identifier: BSD-3
import capstone.arm64
import capstone.sysz_const
from capstone import *
import capstone.aarch64
import capstone.arm
import capstone.systemz
from xprint import to_hex
AARCH64_CODE = b"\x21\x7c\x02\x9b\x21\x7c\x00\x53\x00\x40\x21\x4b\xe1\x0b\x40\xb9"
SYSZ_CODE = b"\xed\x00\x00\x00\x00\x1a\x5a\x0f\x1f\xff\xc2\x09\x80\x00\x00\x00\x07\xf7\xeb\x2a\xff\xff\x7f\x57\xe3\x01\xff\xff\x7f\x57\xeb\x00\xf0\x00\x00\x24\xb2\x4f\x00\x78"
all_tests = (
(CS_ARCH_ARM64, CS_MODE_ARM, AARCH64_CODE, "ARM64"),
(CS_ARCH_SYSZ, CS_MODE_BIG_ENDIAN, SYSZ_CODE, "SysZ"),
)
# Test arm64 and sysz compatibility layer
def test_compatibility():
errors = []
for arch, mode, code, comment in all_tests:
print("*" * 16)
print("Platform: %s" % comment)
print("Code: %s" % to_hex(code))
print("Disasm:")
try:
md = Cs(arch, mode)
md.detail = True
for insn in md.disasm(code, 0x1000):
print("0x%x:\t%s\t%s\t(cc: %s)" % (insn.address, insn.mnemonic, insn.op_str, insn.cc))
print("0x%x:" % (insn.address + insn.size))
print()
except CsError as e:
print("ERROR: %s" % e)
errors.append(str(e))
# Test ARM64_ constants
print("arm64.ARM64_CC_AL = %d" % capstone.arm64.ARM64_CC_AL)
print("aarch64.AArch64CC_AL = %d" % capstone.aarch64.AArch64CC_AL)
assert capstone.arm64.ARM64_CC_AL == capstone.aarch64.AArch64CC_AL
print("arm64.ARM64_INS_FDIV = %d" % capstone.arm64.ARM64_INS_FDIV)
print("aarch64.AARCH64_INS_FDIV = %d" % capstone.aarch64.AARCH64_INS_FDIV)
assert capstone.arm64.ARM64_INS_FDIV == capstone.aarch64.AARCH64_INS_FDIV
# Test SYSZ_ constants
print("systemz.SYSZ_INS_LG = %d" % capstone.systemz.SYSZ_INS_LG)
print("systemz.SYSTEMZ_INS_LG = %d" % capstone.systemz.SYSTEMZ_INS_LG)
assert capstone.systemz.SYSZ_INS_LG == capstone.systemz.SYSTEMZ_INS_LG
# Test ARM_CC_ constants
print("arm.ARM_CC_MI = %d" % capstone.arm.ARM_CC_MI)
print("arm.ARMCC_MI = %d" % capstone.arm.ARMCC_MI)
assert capstone.arm.ARM_CC_MI == capstone.arm.ARMCC_MI
print("arm.ARM_CC_INVALID = %d" % capstone.arm.ARM_CC_INVALID)
print("arm.ARMCC_Invalid = %d" % capstone.arm.ARMCC_Invalid)
assert capstone.arm.ARM_CC_INVALID == capstone.arm.ARMCC_Invalid
return errors
if __name__ == "__main__":
if test_compatibility():
print("Some errors happened. Please check the output")
exit(1)

View File

@@ -18,6 +18,7 @@ def print_insn(md, code):
def test():
errors = []
try:
md = Cs(CS_ARCH_X86, CS_MODE_32)
@@ -33,7 +34,11 @@ def test():
print_insn(md, X86_CODE32)
except CsError as e:
print("ERROR: %s" % e)
errors.append(str(e))
return errors
if __name__ == '__main__':
test()
if test():
print("Some errors happened. Please check the output")
exit(1)

View File

@@ -56,7 +56,7 @@ all_tests = (
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN + CS_MODE_QPX, PPC_CODE2, "PPC-64 + QPX", CS_OPT_SYNTAX_NOREGNAME),
(CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN, SPARC_CODE, "Sparc", None),
(CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN + CS_MODE_V9, SPARCV9_CODE, "SparcV9", None),
(CS_ARCH_SYSTEMZ, 0, SYSZ_CODE, "SystemZ", None),
(CS_ARCH_SYSTEMZ, CS_MODE_BIG_ENDIAN, SYSZ_CODE, "SystemZ", None),
(CS_ARCH_XCORE, 0, XCORE_CODE, "XCore", None),
(CS_ARCH_M68K, CS_MODE_BIG_ENDIAN | CS_MODE_M68K_040, M68K_CODE, "M68K (68040)", None),
(CS_ARCH_M680X, CS_MODE_M680X_6809, M680X_CODE, "M680X_M6809", None),
@@ -70,6 +70,7 @@ all_tests = (
# ## Test class Cs
def test_class():
errors = []
for (arch, mode, code, comment, syntax) in all_tests:
print('*' * 16)
print("Platform: %s" % comment)
@@ -89,6 +90,10 @@ def test_class():
print()
except CsError as e:
print("ERROR: %s" % e)
errors.append(str(e))
return errors
if __name__ == '__main__':
test_class()
if test_class():
print("Some errors happened. Please check the output")
exit(1)

View File

@@ -50,7 +50,7 @@ all_tests = (
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN + CS_MODE_QPX, PPC_CODE2, "PPC-64 + QPX", CS_OPT_SYNTAX_NOREGNAME),
(CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN, SPARC_CODE, "Sparc", None),
(CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN + CS_MODE_V9, SPARCV9_CODE, "SparcV9", None),
(CS_ARCH_SYSTEMZ, 0, SYSZ_CODE, "SystemZ", None),
(CS_ARCH_SYSTEMZ, CS_MODE_BIG_ENDIAN, SYSZ_CODE, "SystemZ", None),
(CS_ARCH_XCORE, 0, XCORE_CODE, "XCore", None),
(CS_ARCH_M68K, CS_MODE_BIG_ENDIAN | CS_MODE_M68K_040, M68K_CODE, "M68K (68040)", None),
(CS_ARCH_M680X, CS_MODE_M680X_6809, M680X_CODE, "M680X_M6809", None),
@@ -71,6 +71,7 @@ def test_cs_disasm_quick():
# ## Test class Cs
def test_class():
errors = []
for (arch, mode, code, comment, syntax) in all_tests:
print('*' * 16)
print("Platform: %s" % comment)
@@ -90,9 +91,13 @@ def test_class():
print()
except CsError as e:
print("ERROR: %s" % e)
errors.append(str(e))
return errors
# test_cs_disasm_quick()
# print "*" * 40
if __name__ == '__main__':
test_class()
if test_class():
print("Some errors happened. Please check the output")
exit(1)

View File

@@ -23,6 +23,7 @@ def testcb(buffer, size, offset, userdata):
# ## Test class Cs
def test_class():
errors = []
for (arch, mode, code, comment, syntax) in all_tests:
print('*' * 16)
print("Platform: %s" %comment)
@@ -65,7 +66,11 @@ def test_class():
print
except CsError as e:
print("ERROR: %s" % e)
errors.append(str(e))
return errors
if __name__ == '__main__':
test_class()
if test_class():
print("Some errors happened. Please check the output")
exit(1)