Test Python bindings in CI (#2161)

This commit is contained in:
peace-maker 2023-09-15 08:35:09 +02:00 • committed by GitHub
parent 4d76f87640
commit e00a210a3d
36 changed files with 485 additions and 234 deletions

View file

@ -90,9 +90,15 @@ jobs:
if: startsWith(matrix.config.build-system, 'cmake')
run: |
mkdir build && cd build
# build static library
cmake -DCAPSTONE_INSTALL=1 -DCMAKE_INSTALL_PREFIX=/usr ..
cmake --build . --config Release
# build shared library
cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr ..
sudo cmake --build . --config Release --target install
cp libcapstone.* ../
cp libcapstone.* ../tests/
cp test_* ../tests/
- name: cstest
run: |
@ -100,12 +106,41 @@ jobs:
python cstest_report.py -D -t build/cstest -d ../MC
python cstest_report.py -D -t build/cstest -f issues.cs; cd ..
- name: build python binding
- name: verify python binding
run: |
mkdir -p bindings/python/capstone/lib && cp libcapstone.so.5.* bindings/python/capstone/lib/libcapstone.so
cd bindings/python
make && make check
cd ../..
# check if the generated *_const.py files are up-to-date
mkdir capstone_old && cp capstone/*_const.py capstone_old/
make gen_const
for f in ./capstone/*_const.py; do
diff -u -w "$f" "./capstone_old/`basename $f`"
if [ ! $? -eq 0 ]; then
exit 1
fi
done
rm -rf capstone_old
# smoke test api usage
make check
- name: run python binding test
run: |
cp libcapstone.* bindings/python/prebuilt
cd bindings/python
make install3
cd ..
BUILD_TESTS=no make tests
- name: run cython binding test
run: |
pip install cython
cd bindings/python
make install3_cython
cd ..
python -c "import capstone;print(capstone.debug())" | grep Cython
BUILD_TESTS=no make tests
Windows:
runs-on: ${{ matrix.config.os }}

1
.gitignore vendored
View file

@ -74,6 +74,7 @@ tests/test_mos65xx
tests/test_bpf
tests/test_sh
tests/test_riscv
tests/test_sh
# regress binaries
suite/regress/invalid_read_in_print_operand

View file

@ -2,7 +2,9 @@ TMPDIR = /tmp/capstone_test
DIFF = diff -u -w
TEST = $(TMPDIR)/test
TEST_BASIC = $(TMPDIR)/test_basic
TEST_DETAIL = $(TMPDIR)/test_detail
TEST_CUSTOMIZED_MNEM = $(TMPDIR)/test_customized_mnem
TEST_ARM = $(TMPDIR)/test_arm
TEST_ARM64 = $(TMPDIR)/test_arm64
TEST_M68K = $(TMPDIR)/test_m68k
@ -13,10 +15,18 @@ TEST_SPARC = $(TMPDIR)/test_sparc
TEST_SYSZ = $(TMPDIR)/test_systemz
TEST_X86 = $(TMPDIR)/test_x86
TEST_XCORE = $(TMPDIR)/test_xcore
TEST_WASM = $(TMPDIR)/test_wasm
TEST_BPF = $(TMPDIR)/test_bpf
TEST_RISCV = $(TMPDIR)/test_riscv
TEST_EVM = $(TMPDIR)/test_evm
TEST_M680X = $(TMPDIR)/test_m680x
TEST_TRICORE = $(TMPDIR)/test_tricore
TEST_SH = $(TMPDIR)/test_sh
TEST_TMS320C64X = $(TMPDIR)/test_tms320c64x
PYTHON2 ?= python
PYTHON3 ?= python3
BUILD_TESTS ?= yes
.PHONY: all expected python java ocaml
@ -25,15 +35,17 @@ all:
cd java && $(MAKE) gen_const
cd ocaml && $(MAKE) gen_const
tests: expected python java #oclma ruby
tests: expected python #java oclma ruby
test_java: expected java
test_python: expected python
expected:
cd ../tests && $(MAKE)
if [ "$(BUILD_TESTS)" = "yes" ]; then cd ../tests && $(MAKE); fi
mkdir -p $(TMPDIR)
../tests/test > $(TEST)_e
../tests/test_basic > $(TEST_BASIC)_e
../tests/test_detail > $(TEST_DETAIL)_e
../tests/test_customized_mnem > $(TEST_CUSTOMIZED_MNEM)_e
../tests/test_arm > $(TEST_ARM)_e
../tests/test_arm64 > $(TEST_ARM64)_e
../tests/test_m68k > $(TEST_M68K)_e
@ -44,29 +56,43 @@ expected:
../tests/test_systemz > $(TEST_SYSZ)_e
../tests/test_x86 > $(TEST_X86)_e
../tests/test_xcore > $(TEST_XCORE)_e
../tests/test_wasm > $(TEST_WASM)_e
../tests/test_bpf > $(TEST_BPF)_e
../tests/test_riscv > $(TEST_RISCV)_e
../tests/test_evm > $(TEST_EVM)_e
../tests/test_m680x > $(TEST_M680X)_e
../tests/test_sh > $(TEST_SH)_e
../tests/test_tricore > $(TEST_TRICORE)_e
../tests/test_tms320c64x > $(TEST_TMS320C64X)_e
python: FORCE
cd python && $(MAKE)
$(PYTHON2) python/test.py > $(TEST)_o
$(PYTHON2) python/test_arm.py > $(TEST_ARM)_o
$(PYTHON2) python/test_arm64.py > $(TEST_ARM64)_o
$(PYTHON2) python/test_m68k.py > $(TEST_M68K)_o
$(PYTHON2) python/test_mips.py > $(TEST_MIPS)_o
$(PYTHON2) python/test_mos65xx.py > $(TEST_MOS65XX)_o
$(PYTHON2) python/test_ppc.py > $(TEST_PPC)_o
$(PYTHON2) python/test_sparc.py > $(TEST_SPARC)_o
$(PYTHON2) python/test_systemz.py > $(TEST_SYSZ)_o
$(PYTHON2) python/test_x86.py > $(TEST_X86)_o
$(PYTHON2) python/test_xcore.py > $(TEST_XCORE)_o
$(PYTHON2) python/test_bpf.py > $(TEST_BPF)_o
$(PYTHON2) python/test_riscv.py > $(TEST_RISCV)_o
$(PYTHON3) python/test_basic.py > $(TEST_BASIC)_o
$(PYTHON3) python/test_detail.py > $(TEST_DETAIL)_o
$(PYTHON3) python/test_customized_mnem.py > $(TEST_CUSTOMIZED_MNEM)_o
$(PYTHON3) python/test_arm.py > $(TEST_ARM)_o
$(PYTHON3) python/test_arm64.py > $(TEST_ARM64)_o
$(PYTHON3) python/test_m68k.py > $(TEST_M68K)_o
$(PYTHON3) python/test_mips.py > $(TEST_MIPS)_o
$(PYTHON3) python/test_mos65xx.py > $(TEST_MOS65XX)_o
$(PYTHON3) python/test_ppc.py > $(TEST_PPC)_o
$(PYTHON3) python/test_sparc.py > $(TEST_SPARC)_o
$(PYTHON3) python/test_systemz.py > $(TEST_SYSZ)_o
$(PYTHON3) python/test_x86.py > $(TEST_X86)_o
$(PYTHON3) python/test_xcore.py > $(TEST_XCORE)_o
$(PYTHON3) python/test_wasm.py > $(TEST_WASM)_o
$(PYTHON3) python/test_bpf.py > $(TEST_BPF)_o
$(PYTHON3) python/test_riscv.py > $(TEST_RISCV)_o
$(PYTHON3) python/test_evm.py > $(TEST_EVM)_o
$(PYTHON3) python/test_m680x.py > $(TEST_M680X)_o
$(PYTHON3) python/test_sh.py > $(TEST_SH)_o
$(PYTHON3) python/test_tricore.py > $(TEST_TRICORE)_o
$(PYTHON3) python/test_tms320c64x.py > $(TEST_TMS320C64X)_o
$(MAKE) test_diff
java: FORCE
cd java && $(MAKE)
cd java && ./run.sh > $(TEST)_o
cd java && ./run.sh > $(TEST_BASIC)_o
cd java && ./run.sh arm > $(TEST_ARM)_o
cd java && ./run.sh arm64 > $(TEST_ARM64)_o
cd java && ./run.sh mips > $(TEST_MIPS)_o
@ -80,7 +106,9 @@ java: FORCE
ocaml: FORCE
test_diff: FORCE
$(DIFF) $(TEST)_e $(TEST)_o
$(DIFF) $(TEST_BASIC)_e $(TEST_BASIC)_o
$(DIFF) $(TEST_DETAIL)_e $(TEST_DETAIL)_o
$(DIFF) $(TEST_CUSTOMIZED_MNEM)_e $(TEST_CUSTOMIZED_MNEM)_o
$(DIFF) $(TEST_ARM)_e $(TEST_ARM)_o
$(DIFF) $(TEST_ARM64)_e $(TEST_ARM64)_o
$(DIFF) $(TEST_M68K)_e $(TEST_M68K)_o
@ -91,7 +119,14 @@ test_diff: FORCE
$(DIFF) $(TEST_SYSZ)_e $(TEST_SYSZ)_o
$(DIFF) $(TEST_X86)_e $(TEST_X86)_o
$(DIFF) $(TEST_XCORE)_e $(TEST_XCORE)_o
$(DIFF) $(TEST_WASM)_e $(TEST_WASM)_o
$(DIFF) $(TEST_BPF)_e $(TEST_BPF)_o
$(DIFF) $(TEST_RISCV)_e $(TEST_RISCV)_o
$(DIFF) $(TEST_EVM)_e $(TEST_EVM)_o
$(DIFF) $(TEST_M680X)_e $(TEST_M680X)_o
$(DIFF) $(TEST_SH)_e $(TEST_SH)_o
$(DIFF) $(TEST_TRICORE)_e $(TEST_TRICORE)_o
$(DIFF) $(TEST_TMS320C64X)_e $(TEST_TMS320C64X)_o
clean:
rm -rf $(TMPDIR)

View file

@ -71,8 +71,8 @@ clean:
TESTS = test_basic.py test_detail.py test_arm.py test_arm64.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
TESTS += test_lite.py test_iter.py
TESTS += test_evm.py test_tricore.py test_wasm.py test_sh.py
TESTS += test_lite.py test_iter.py test_customized_mnem.py
check:
@for t in $(TESTS); do \

View file

@ -203,35 +203,40 @@ ARM_VECTORDATA_U16 = 10
ARM_VECTORDATA_U32 = 11
ARM_VECTORDATA_U64 = 12
ARM_VECTORDATA_P8 = 13
ARM_VECTORDATA_F16 = 14
ARM_VECTORDATA_F32 = 15
ARM_VECTORDATA_F64 = 16
ARM_VECTORDATA_F16F64 = 17
ARM_VECTORDATA_F64F16 = 18
ARM_VECTORDATA_F32F16 = 19
ARM_VECTORDATA_F16F32 = 20
ARM_VECTORDATA_F64F32 = 21
ARM_VECTORDATA_F32F64 = 22
ARM_VECTORDATA_S32F32 = 23
ARM_VECTORDATA_U32F32 = 24
ARM_VECTORDATA_F32S32 = 25
ARM_VECTORDATA_F32U32 = 26
ARM_VECTORDATA_F64S16 = 27
ARM_VECTORDATA_F32S16 = 28
ARM_VECTORDATA_F64S32 = 29
ARM_VECTORDATA_S16F64 = 30
ARM_VECTORDATA_S16F32 = 31
ARM_VECTORDATA_S32F64 = 32
ARM_VECTORDATA_U16F64 = 33
ARM_VECTORDATA_U16F32 = 34
ARM_VECTORDATA_U32F64 = 35
ARM_VECTORDATA_F64U16 = 36
ARM_VECTORDATA_F32U16 = 37
ARM_VECTORDATA_F64U32 = 38
ARM_VECTORDATA_F16U16 = 39
ARM_VECTORDATA_U16F16 = 40
ARM_VECTORDATA_F16U32 = 41
ARM_VECTORDATA_U32F16 = 42
ARM_VECTORDATA_P16 = 14
ARM_VECTORDATA_F16 = 15
ARM_VECTORDATA_F32 = 16
ARM_VECTORDATA_F64 = 17
ARM_VECTORDATA_F16F64 = 18
ARM_VECTORDATA_F64F16 = 19
ARM_VECTORDATA_F32F16 = 20
ARM_VECTORDATA_F16F32 = 21
ARM_VECTORDATA_F64F32 = 22
ARM_VECTORDATA_F32F64 = 23
ARM_VECTORDATA_S32F32 = 24
ARM_VECTORDATA_U32F32 = 25
ARM_VECTORDATA_F32S32 = 26
ARM_VECTORDATA_F32U32 = 27
ARM_VECTORDATA_F64S16 = 28
ARM_VECTORDATA_F32S16 = 29
ARM_VECTORDATA_F64S32 = 30
ARM_VECTORDATA_S16F64 = 31
ARM_VECTORDATA_S16F32 = 32
ARM_VECTORDATA_S32F64 = 33
ARM_VECTORDATA_U16F64 = 34
ARM_VECTORDATA_U16F32 = 35
ARM_VECTORDATA_U32F64 = 36
ARM_VECTORDATA_F64U16 = 37
ARM_VECTORDATA_F32U16 = 38
ARM_VECTORDATA_F64U32 = 39
ARM_VECTORDATA_F16U16 = 40
ARM_VECTORDATA_U16F16 = 41
ARM_VECTORDATA_F16U32 = 42
ARM_VECTORDATA_U32F16 = 43
ARM_VECTORDATA_F16S16 = 44
ARM_VECTORDATA_S16F16 = 45
ARM_VECTORDATA_F16S32 = 46
ARM_VECTORDATA_S32F16 = 47
ARM_REG_INVALID = 0
ARM_REG_APSR = 1

View file

@ -26,18 +26,6 @@ class PpcOp(ctypes.Structure):
('access', ctypes.c_uint),
)
class PpcBC(ctypes.Structure):
_fields_ = (
('bo', ctypes.c_uint8),
('bi', ctypes.c_uint8),
('crX_bit', ctypes.c_uint),
('crX', ctypes.c_uint),
('hint', ctypes.c_uint),
('pred_cr', ctypes.c_uint),
('pred_ctr', ctypes.c_uint),
('bh', ctypes.c_uint),
)
@property
def imm(self):
return self.value.imm
@ -50,6 +38,18 @@ class PpcBC(ctypes.Structure):
def mem(self):
return self.value.mem
class PpcBC(ctypes.Structure):
_fields_ = (
('bo', ctypes.c_uint8),
('bi', ctypes.c_uint8),
('crX_bit', ctypes.c_uint),
('crX', ctypes.c_uint),
('hint', ctypes.c_uint),
('pred_cr', ctypes.c_uint),
('pred_ctr', ctypes.c_uint),
('bh', ctypes.c_uint),
)
class CsPpc(ctypes.Structure):
_fields_ = (
('bc', PpcBC),

View file

@ -41,7 +41,7 @@ class CsDetail(object):
elif arch == capstone.CS_ARCH_MIPS:
self.operands = mips.get_arch_info(detail.arch.mips)
elif arch == capstone.CS_ARCH_PPC:
(self.bc, self.bh, self.update_cr0, self.operands) = \
(self.bc, self.update_cr0, self.operands) = \
ppc.get_arch_info(detail.arch.ppc)
elif arch == capstone.CS_ARCH_SPARC:
(self.cc, self.hint, self.operands) = sparc.get_arch_info(detail.arch.sparc)

View file

@ -127,6 +127,7 @@ def build_libraries():
# 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))):
log.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)

View file

@ -9,8 +9,6 @@ from distutils.command.build import build
from Cython.Distutils import build_ext
SYSTEM = sys.platform
VERSION = '5.0.0'
VERSION_PARTS = VERSION.split(".")
# adapted from commit e504b81 of Nguyen Tan Cong
# Reference: https://docs.python.org/2/library/platform.html#cross-platform
@ -25,8 +23,38 @@ BUILD_DIR = SRC_DIR if os.path.exists(SRC_DIR) else os.path.join(ROOT_DIR, '../.
PYPACKAGE_DIR = os.path.join(ROOT_DIR, 'capstone')
CYPACKAGE_DIR = os.path.join(ROOT_DIR, 'pyx')
# Parse version from pkgconfig.mk
VERSION_DATA = {}
with open(os.path.join(BUILD_DIR, 'pkgconfig.mk')) as fp:
lines = fp.readlines()
for line in lines:
line = line.strip()
if len(line) == 0:
continue
if line.startswith('#'):
continue
if '=' not in line:
continue
k, v = line.split('=', 1)
k = k.strip()
v = v.strip()
if len(k) == 0 or len(v) == 0:
continue
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:
raise Exception("Malformed pkgconfig.mk")
if 'PKG_TAG' in VERSION_DATA:
VERSION = '{PKG_MAJOR}.{PKG_MINOR}.{PKG_EXTRA}{PKG_TAG}'.format(**VERSION_DATA)
else:
VERSION = '{PKG_MAJOR}.{PKG_MINOR}.{PKG_EXTRA}'.format(**VERSION_DATA)
if SYSTEM == 'darwin':
VERSIONED_LIBRARY_FILE = "libcapstone.{}.dylib".format(VERSION_PARTS[0])
VERSIONED_LIBRARY_FILE = "libcapstone.{PKG_MAJOR}.dylib".format(**VERSION_DATA)
LIBRARY_FILE = "libcapstone.dylib"
STATIC_LIBRARY_FILE = 'libcapstone.a'
elif SYSTEM in ('win32', 'cygwin'):
@ -34,7 +62,7 @@ elif SYSTEM in ('win32', 'cygwin'):
LIBRARY_FILE = "capstone.dll"
STATIC_LIBRARY_FILE = None
else:
VERSIONED_LIBRARY_FILE = "libcapstone.so.{}".format(VERSION_PARTS[0])
VERSIONED_LIBRARY_FILE = "libcapstone.so.{PKG_MAJOR}".format(**VERSION_DATA)
LIBRARY_FILE = "libcapstone.so"
STATIC_LIBRARY_FILE = 'libcapstone.a'
@ -87,6 +115,15 @@ def build_libraries():
# copy public headers
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))):
log.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)
# platform description refers at https://docs.python.org/2/library/sys.html#sys.platform
@ -137,7 +174,7 @@ setup(
author = 'Nguyen Anh Quynh',
author_email = 'aquynh@gmail.com',
description = 'Capstone disassembly engine',
url = 'http://www.capstone-engine.org',
url = 'https://www.capstone-engine.org',
classifiers = [
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 2',

View file

@ -8,9 +8,9 @@ from capstone.arm import *
from xprint import to_hex, to_x_32
ARM_CODE = b"\x86\x48\x60\xf4\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3\x00\x02\x01\xf1\x05\x40\xd0\xe8\xf4\x80\x00\x00"
ARM_CODE = b"\x86\x48\x60\xf4\x4d\x0f\xe2\xf4\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3\x00\x02\x01\xf1\x05\x40\xd0\xe8\xf4\x80\x00\x00"
ARM_CODE2 = b"\xd1\xe8\x00\xf0\xf0\x24\x04\x07\x1f\x3c\xf2\xc0\x00\x00\x4f\xf0\x00\x01\x46\x6c"
THUMB_CODE = b"\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0"
THUMB_CODE = b"\x60\xf9\x1f\x04\xe0\xf9\x4f\x07\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0"
THUMB_CODE2 = b"\x4f\xf0\x00\x01\xbd\xe8\x00\x88\xd1\xe8\x00\xf0\x18\xbf\xad\xbf\xf3\xff\x0b\x0c\x86\xf3\x00\x89\x80\xf3\x00\x8c\x4f\xfa\x99\xf6\xd0\xff\xa2\x01"
THUMB_MCLASS = b"\xef\xf3\x02\x80"
ARMV8 = b"\xe0\x3b\xb2\xee\x42\x00\x01\xe1\x51\xf0\x7f\xf5"
@ -101,11 +101,11 @@ def print_insn_detail(insn):
print("\t\toperands[%u].neon_lane = %u" % (c, i.neon_lane))
if i.access == CS_AC_READ:
print("\t\toperands[%u].access: READ\n" % (c))
print("\t\toperands[%u].access: READ" % (c))
elif i.access == CS_AC_WRITE:
print("\t\toperands[%u].access: WRITE\n" % (c))
print("\t\toperands[%u].access: WRITE" % (c))
elif i.access == CS_AC_READ | CS_AC_WRITE:
print("\t\toperands[%u].access: READ | WRITE\n" % (c))
print("\t\toperands[%u].access: READ | WRITE" % (c))
if i.shift.type != ARM_SFT_INVALID and i.shift.value:
if i.shift.type < ARM_SFT_ASR_REG:
@ -181,6 +181,7 @@ def test_class():
for insn in md.disasm(code, 0x80001000):
print_insn_detail(insn)
print ()
print("0x%x:\n" % (insn.address + insn.size))
except CsError as e:
print("ERROR: %s" % e)

View file

@ -5,10 +5,10 @@
from __future__ import print_function
from capstone import *
from capstone.arm64 import *
from xprint import to_hex, to_x
from xprint import to_hex, to_x, to_x_32
ARM64_CODE = b"\x09\x00\x38\xd5\xbf\x40\x00\xd5\x0c\x05\x13\xd5\x20\x50\x02\x0e\x20\xe4\x3d\x0f\x00\x18\xa0\x5f\xa2\x00\xae\x9e\x9f\x37\x03\xd5\xbf\x33\x03\xd5\xdf\x3f\x03\xd5\x21\x7c\x02\x9b\x21\x7c\x00\x53\x00\x40\x21\x4b\xe1\x0b\x40\xb9\x20\x04\x81\xda\x20\x08\x02\x8b\x10\x5b\xe8\x3c"
ARM64_CODE = b"\x09\x00\x38\xd5\xbf\x40\x00\xd5\x0c\x05\x13\xd5\x20\x50\x02\x0e\x20\xe4\x3d\x0f\x00\x18\xa0\x5f\xa2\x00\xae\x9e\x9f\x37\x03\xd5\xbf\x33\x03\xd5\xdf\x3f\x03\xd5\x21\x7c\x02\x9b\x21\x7c\x00\x53\x00\x40\x21\x4b\xe1\x0b\x40\xb9\x20\x04\x81\xda\x20\x08\x02\x8b\x10\x5b\xe8\x3c\xfd\x7b\xba\xa9\xfd\xc7\x43\xf8"
all_tests = (
(CS_ARCH_ARM64, CS_MODE_ARM, ARM64_CODE, "ARM-64"),
@ -46,7 +46,7 @@ def print_insn_detail(insn):
% (c, insn.reg_name(i.mem.index)))
if i.mem.disp != 0:
print("\t\t\toperands[%u].mem.disp: 0x%s" \
% (c, to_x(i.mem.disp)))
% (c, to_x_32(i.mem.disp)))
if i.type == ARM64_OP_REG_MRS:
print("\t\toperands[%u].type: REG_MRS = 0x%x" % (c, i.reg))
if i.type == ARM64_OP_REG_MSR:
@ -74,6 +74,13 @@ def print_insn_detail(insn):
if i.sme_index.disp != 0 :
print("\t\t\toperands[%u].index.disp: 0x%x" %(c, i.sme_index.disp))
if i.access == CS_AC_READ:
print("\t\toperands[%u].access: READ" % (c))
elif i.access == CS_AC_WRITE:
print("\t\toperands[%u].access: WRITE" % (c))
elif i.access == CS_AC_READ | CS_AC_WRITE:
print("\t\toperands[%u].access: READ | WRITE" % (c))
if i.shift.type != ARM64_SFT_INVALID and i.shift.value:
print("\t\t\tShift: type = %u, value = %u" % (i.shift.type, i.shift.value))
@ -86,13 +93,6 @@ def print_insn_detail(insn):
if i.vector_index != -1:
print("\t\t\tVector Index: %u" % i.vector_index)
if i.access == CS_AC_READ:
print("\t\toperands[%u].access: READ\n" % (c))
elif i.access == CS_AC_WRITE:
print("\t\toperands[%u].access: WRITE\n" % (c))
elif i.access == CS_AC_READ | CS_AC_WRITE:
print("\t\toperands[%u].access: READ | WRITE\n" % (c))
if insn.writeback:
if insn.post_index:

View file

@ -34,7 +34,10 @@ XCORE_CODE = b"\xfe\x0f\xfe\x17\x13\x17\xc6\xfe\xec\x17\x97\xf8\xec\x4f\x1f\xfd\
M68K_CODE = b"\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28\x4E\xB9\x00\x00\x00\x12\x4E\x75"
TMS320C64X_CODE = b"\x01\xac\x88\x40\x81\xac\x88\x43\x00\x00\x00\x00\x02\x90\x32\x96\x02\x80\x46\x9e\x05\x3c\x83\xe6\x0b\x0c\x8b\x24"
M680X_CODE = b"\x06\x10\x19\x1a\x55\x1e\x01\x23\xe9\x31\x06\x34\x55\xa6\x81\xa7\x89\x7f\xff\xa6\x9d\x10\x00\xa7\x91\xa6\x9f\x10\x00\x11\xac\x99\x10\x00\x39"
EVM_CODE = b"\x60\x61"
WASM_CODE = b"\x20\x00\x20\x01\x41\x20\x10\xc9\x01\x45\x0b"
MOS65XX_CODE = b"\x0d\x34\x12\x00\x81\x65\x6c\x01\x00\x85\xFF\x10\x00\x19\x42\x42\x00\x49\x42"
EBPF_CODE = b"\x97\x09\x00\x00\x37\x13\x03\x00\xdc\x02\x00\x00\x20\x00\x00\x00\x30\x00\x00\x00\x00\x00\x00\x00\xdb\x3a\x00\x01\x00\x00\x00\x00\x84\x02\x00\x00\x00\x00\x00\x00\x6d\x33\x17\x02\x00\x00\x00\x00"
RISCV_CODE32 = b"\x37\x34\x00\x00\x97\x82\x00\x00\xef\x00\x80\x00\xef\xf0\x1f\xff\xe7\x00\x45\x00\xe7\x00\xc0\xff\x63\x05\x41\x00\xe3\x9d\x61\xfe\x63\xca\x93\x00\x63\x53\xb5\x00\x63\x65\xd6\x00\x63\x76\xf7\x00\x03\x88\x18\x00\x03\x99\x49\x00\x03\xaa\x6a\x00\x03\xcb\x2b\x01\x03\xdc\x8c\x01\x23\x86\xad\x03\x23\x9a\xce\x03\x23\x8f\xef\x01\x93\x00\xe0\x00\x13\xa1\x01\x01\x13\xb2\x02\x7d\x13\xc3\x03\xdd\x13\xe4\xc4\x12\x13\xf5\x85\x0c\x13\x96\xe6\x01\x13\xd7\x97\x01\x13\xd8\xf8\x40\x33\x89\x49\x01\xb3\x0a\x7b\x41\x33\xac\xac\x01\xb3\x3d\xde\x01\x33\xd2\x62\x40\xb3\x43\x94\x00\x33\xe5\xc5\x00\xb3\x76\xf7\x00\xb3\x54\x39\x01\xb3\x50\x31\x00\x33\x9f\x0f\x00"
RISCV_CODE64 = b"\x13\x04\xa8\x7a"
@ -58,15 +61,18 @@ all_tests = (
(CS_ARCH_ARM64, CS_MODE_ARM, ARM64_CODE, "ARM-64", None),
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, PPC_CODE, "PPC-64", None),
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, PPC_CODE, "PPC-64, print register with number only", CS_OPT_SYNTAX_NOREGNAME),
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN + CS_MODE_QPX, PPC_CODE2, "PPC-64 + QPX", CS_OPT_SYNTAX_NOREGNAME),
(CS_ARCH_PPC, CS_MODE_BIG_ENDIAN + CS_MODE_QPX, PPC_CODE2, "PPC-64 + QPX", None),
(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_SYSZ, 0, 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_M68K, CS_MODE_BIG_ENDIAN | CS_MODE_M68K_040, M68K_CODE, "M68K", None),
(CS_ARCH_TMS320C64X, 0, TMS320C64X_CODE, "TMS320C64x", None),
(CS_ARCH_M680X, CS_MODE_M680X_6809, M680X_CODE, "M680X_M6809", None),
(CS_ARCH_EVM, 0, EVM_CODE, "EVM", None),
(CS_ARCH_WASM, 0, WASM_CODE, "WASM", None),
(CS_ARCH_MOS65XX, 0, MOS65XX_CODE, "MOS65XX", None),
(CS_ARCH_BPF, CS_MODE_LITTLE_ENDIAN | CS_MODE_BPF_EXTENDED, EBPF_CODE, "eBPF", None),
(CS_ARCH_RISCV, CS_MODE_RISCV32, RISCV_CODE32, "RISCV32", None),
(CS_ARCH_RISCV, CS_MODE_RISCV64, RISCV_CODE64, "RISCV64", None),
)
@ -76,7 +82,7 @@ def test_cs_disasm_quick():
for arch, mode, code, comment, syntax in all_tests:
print('*' * 40)
print("Platform: %s" % comment)
print("Disasm:"),
print("Disasm:")
print(to_hex(code))
for insn in cs_disasm_quick(arch, mode, code, 0x1000):
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
@ -119,7 +125,7 @@ def test_class():
for insn in md.disasm(code, 0x1000):
# bytes = binascii.hexlify(insn.bytes)
# print("0x%x:\t%s\t%s\t// hex-code: %s" %(insn.address, insn.mnemonic, insn.op_str, bytes))
print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
print("0x%x:\t%s\t\t%s" % (insn.address, insn.mnemonic, insn.op_str))
print("0x%x:" % (insn.address + insn.size))
print()

View file

@ -6,7 +6,7 @@
from __future__ import print_function
from capstone import *
from capstone.bpf import *
from xprint import to_hex, to_x_32
from xprint import to_hex, to_x, to_x_32
CBPF_CODE = b"\x94\x09\x00\x00\x37\x13\x03\x00\x87\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00"
@ -37,7 +37,7 @@ def print_insn_detail(insn):
if op.type == BPF_OP_REG:
print("REG = " + insn.reg_name(op.reg))
elif op.type == BPF_OP_IMM:
print("IMM = " + hex(op.imm)[:-1])
print("IMM = 0x" + to_x(op.imm))
elif op.type == BPF_OP_OFF:
print("OFF = +0x" + to_x_32(op.off))
elif op.type == BPF_OP_MEM:

View file

@ -15,7 +15,7 @@ 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))
print("\t%s\t%s" % (insn.mnemonic, insn.op_str))
def test():
@ -25,11 +25,11 @@ def test():
print("Disassemble X86 code with default instruction mnemonic")
print_insn(md, X86_CODE32)
print("Now customize engine to change mnemonic from 'JNE' to 'JNZ'")
print("\nNow 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")
print("\nReset engine to use the default mnemonic")
md.mnemonic_setup(X86_INS_JNE, None)
print_insn(md, X86_CODE32)
except CsError as e:

View file

@ -4,6 +4,7 @@
from __future__ import print_function
from capstone import *
from xprint import to_hex
X86_CODE16 = b"\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
X86_CODE32 = b"\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
@ -11,15 +12,15 @@ X86_CODE64 = b"\x55\x48\x8b\x05\xb8\x13\x00\x00"
ARM_CODE = b"\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3"
ARM_CODE2 = b"\x10\xf1\x10\xe7\x11\xf2\x31\xe7\xdc\xa1\x2e\xf3\xe8\x4e\x62\xf3"
THUMB_CODE = b"\x70\x47\xeb\x46\x83\xb0\xc9\x68"
THUMB_CODE2 = b"\x4f\xf0\x00\x01\xbd\xe8\x00\x88"
THUMB_CODE2 = b"\x4f\xf0\x00\x01\xbd\xe8\x00\x88\xd1\xe8\x00\xf0"
THUMB_MCLASS = b"\xef\xf3\x02\x80"
ARMV8 = b"\xe0\x3b\xb2\xee\x42\x00\x01\xe1\x51\xf0\x7f\xf5"
MIPS_CODE = b"\x0C\x10\x00\x97\x00\x00\x00\x00\x24\x02\x00\x0c\x8f\xa2\x00\x00\x34\x21\x34\x56"
MIPS_CODE = b"\x0C\x10\x00\x97\x00\x00\x00\x00\x24\x02\x00\x0c\x8f\xa2\x00\x00\x34\x21\x34\x56\x00\x80\x04\x08"
MIPS_CODE2 = b"\x56\x34\x21\x34\xc2\x17\x01\x00"
MIPS_32R6M = b"\x00\x07\x00\x07\x00\x11\x93\x7c\x01\x8c\x8b\x7c\x00\xc7\x48\xd0"
MIPS_32R6 = b"\xec\x80\x00\x19\x7c\x43\x22\xa0"
ARM64_CODE = b"\x09\x00\x38\xd5\xbf\x40\x00\xd5\x0c\x05\x13\xd5\x20\x50\x02\x0e\x20\xe4\x3d\x0f\x00\x18\xa0\x5f\xa2\x00\xae\x9e\x9f\x37\x03\xd5\xbf\x33\x03\xd5\xdf\x3f\x03\xd5\x21\x7c\x02\x9b\x21\x7c\x00\x53\x00\x40\x21\x4b\xe1\x0b\x40\xb9\x20\x04\x81\xda\x20\x08\x02\x8b\x10\x5b\xe8\x3c"
PPC_CODE = b"\x80\x20\x00\x00\x80\x3f\x00\x00\x10\x43\x23\x0e\xd0\x44\x00\x80\x4c\x43\x22\x02\x2d\x03\x00\x80\x7c\x43\x20\x14\x7c\x43\x20\x93\x4f\x20\x00\x21\x4c\xc8\x00\x21"
PPC_CODE = b"\x80\x20\x00\x00\x80\x3f\x00\x00\x10\x43\x23\x0e\xd0\x44\x00\x80\x4c\x43\x22\x02\x2d\x03\x00\x80\x7c\x43\x20\x14\x7c\x43\x20\x93\x4f\x20\x00\x21\x4c\xc8\x00\x21\x40\x82\x00\x14"
PPC_CODE2 = b"\x10\x60\x2a\x10\x10\x64\x28\x88\x7c\x4a\x5d\x0f"
SPARC_CODE = b"\x80\xa0\x40\x02\x85\xc2\x60\x08\x85\xe8\x20\x01\x81\xe8\x00\x00\x90\x10\x20\x01\xd5\xf6\x10\x16\x21\x00\x00\x0a\x86\x00\x40\x02\x01\x00\x00\x00\x12\xbf\xff\xff\x10\xbf\xff\xff\xa0\x02\x00\x09\x0d\xbf\xff\xff\xd4\x20\x60\x00\xd4\x4e\x00\x16\x2a\xc2\x80\x03"
SPARCV9_CODE = b"\x81\xa8\x0a\x24\x89\xa0\x10\x20\x89\xa0\x1a\x60\x89\xa0\x00\xe0"
@ -27,6 +28,8 @@ SYSZ_CODE = b"\xed\x00\x00\x00\x00\x1a\x5a\x0f\x1f\xff\xc2\x09\x80\x00\x00\x00\x
XCORE_CODE = b"\xfe\x0f\xfe\x17\x13\x17\xc6\xfe\xec\x17\x97\xf8\xec\x4f\x1f\xfd\xec\x37\x07\xf2\x45\x5b\xf9\xfa\x02\x06\x1b\x10"
M68K_CODE = b"\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28\x4E\xB9\x00\x00\x00\x12\x4E\x75"
M680X_CODE = b"\x06\x10\x19\x1a\x55\x1e\x01\x23\xe9\x31\x06\x34\x55\xa6\x81\xa7\x89\x7f\xff\xa6\x9d\x10\x00\xa7\x91\xa6\x9f\x10\x00\x11\xac\x99\x10\x00\x39"
MOS65XX_CODE = b"\x0A\x00\xFE\x34\x12\xD0\xFF\xEA\x19\x56\x34\x46\x80"
EBPF_CODE = b"\x97\x09\x00\x00\x37\x13\x03\x00\xdc\x02\x00\x00\x20\x00\x00\x00\x30\x00\x00\x00\x00\x00\x00\x00\xdb\x3a\x00\x01\x00\x00\x00\x00\x84\x02\x00\x00\x00\x00\x00\x00\x6d\x33\x17\x02\x00\x00\x00\x00"
all_tests = (
(CS_ARCH_X86, CS_MODE_16, X86_CODE16, "X86 16bit (Intel syntax)", None),
@ -50,8 +53,10 @@ all_tests = (
(CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN + CS_MODE_V9, SPARCV9_CODE, "SparcV9", None),
(CS_ARCH_SYSZ, 0, 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_M68K, CS_MODE_BIG_ENDIAN | CS_MODE_M68K_040, M68K_CODE, "M68K", None),
(CS_ARCH_M680X, CS_MODE_M680X_6809, M680X_CODE, "M680X_M6809", None),
(CS_ARCH_MOS65XX, 0, MOS65XX_CODE, "MOS65XX", None),
(CS_ARCH_BPF, CS_MODE_LITTLE_ENDIAN | CS_MODE_BPF_EXTENDED, EBPF_CODE, "eBPF", None),
)
@ -65,29 +70,30 @@ def print_detail(insn):
return
if len(insn.regs_read) > 0:
print("\tImplicit registers read: ", end=''),
print("\tImplicit registers read: ", end='')
for m in insn.regs_read:
print("%s " % insn.reg_name(m), end=''),
print("%s " % insn.reg_name(m), end='')
print()
if len(insn.regs_write) > 0:
print("\tImplicit registers modified: ", end=''),
print("\tImplicit registers modified: ", end='')
for m in insn.regs_write:
print("%s " % insn.reg_name(m), end=''),
print("%s " % insn.reg_name(m), end='')
print()
if len(insn.groups) > 0:
print("\tThis instruction belongs to groups: ", end=''),
print("\tThis instruction belongs to groups: ", end='')
for m in insn.groups:
print("%s " % insn.group_name(m), end=''),
print("%s " % insn.group_name(m), end='')
print()
# ## Test class Cs
def test_class():
for (arch, mode, code, comment, syntax) in all_tests:
print('*' * 40)
print('*' * 16)
print("Platform: %s" % comment)
print("Code: %s" % to_hex(code))
print("Disasm:")
try:
@ -100,6 +106,7 @@ def test_class():
for insn in md.disasm(code, 0x1000):
print_detail(insn)
print("0x%x:" % (insn.address + insn.size))
print()
except CsError as e:
print("ERROR: %s" % e)

View file

@ -21,6 +21,7 @@ all_tests = (
def test_class():
address = 0x80001000
for (arch, mode, code, comment) in all_tests:
print("*" * 16)
print("Platform: %s" % comment)
print("Code: %s " % to_hex(code))
print("Disasm:")
@ -41,6 +42,7 @@ def test_class():
for m in i.groups:
print("%s " % i.group_name(m), end=''),
print()
print ("0x%x:\n" % (i.address + i.size))
except CsError as e:
print("ERROR: %s" % e.__str__())

View file

@ -4,9 +4,9 @@
from __future__ import print_function
from capstone import *
from capstone.m68k import *
from xprint import to_hex, to_x
from xprint import to_hex
M68K_CODE = b"\x4c\x00\x54\x04\x48\xe7\xe0\x30\x4c\xdf\x0c\x07\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28\x4e\xb9\x00\x00\x00\x12\x4e\x75"
M68K_CODE = b"\xf0\x10\xf0\x00\x48\xaf\xff\xff\x7f\xff\x11\xb0\x01\x37\x7f\xff\xff\xff\x12\x34\x56\x78\x01\x33\x10\x10\x10\x10\x32\x32\x32\x32\x4C\x00\x54\x04\x48\xe7\xe0\x30\x4C\xDF\x0C\x07\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28\x4E\xB9\x00\x00\x00\x12\x4E\x75"
all_tests = (
(CS_ARCH_M68K, CS_MODE_BIG_ENDIAN | CS_MODE_M68K_040, M68K_CODE, "M68K"),
@ -54,9 +54,9 @@ def print_read_write_regs(insn):
def print_insn_detail(insn):
if len(insn.operands) > 0:
print("\top_count: %u" % (len(insn.operands)))
print("\tgroups_count: %u" % len(insn.groups))
print_read_write_regs(insn)
print("\tgroups_count: %u" % len(insn.groups))
for i, op in enumerate(insn.operands):
if op.type == M68K_OP_REG:
@ -80,10 +80,14 @@ def print_insn_detail(insn):
print("\t\taddress mode: %s" % (s_addressing_modes[op.address_mode]))
elif op.type == M68K_OP_FP_SINGLE:
print("\t\toperands[%u].type: FP_SINGLE" % i)
print("\t\toperands[%u].simm: %f", i, op.simm)
print("\t\toperands[%u].simm: %f" % (i, op.simm))
elif op.type == M68K_OP_FP_DOUBLE:
print("\t\toperands[%u].type: FP_DOUBLE" % i)
print("\t\toperands[%u].dimm: %lf", i, op.dimm)
print("\t\toperands[%u].dimm: %lf" % (i, op.dimm))
elif op.type == M68K_OP_REG_BITS:
print("\t\toperands[%u].type: REG_BITS = $%x" % (i, op.register_bits))
elif op.type == M68K_OP_REG_PAIR:
print("\t\toperands[%u].type: REG_PAIR = (%s, %s)" % (i, insn.reg_name(op.reg_pair.reg_0), insn.reg_name(op.reg_pair.reg_1)))
elif op.type == M68K_OP_BR_DISP:
print("\t\toperands[%u].br_disp.disp: 0x%x" % (i, op.br_disp.disp))
print("\t\toperands[%u].br_disp.disp_size: %d" % (i, op.br_disp.disp_size))

View file

@ -11,12 +11,15 @@ MIPS_CODE = b"\x0C\x10\x00\x97\x00\x00\x00\x00\x24\x02\x00\x0c\x8f\xa2\x00\x00\x
MIPS_CODE2 = b"\x56\x34\x21\x34\xc2\x17\x01\x00"
MIPS_32R6M = b"\x00\x07\x00\x07\x00\x11\x93\x7c\x01\x8c\x8b\x7c\x00\xc7\x48\xd0"
MIPS_32R6 = b"\xec\x80\x00\x19\x7c\x43\x22\xa0"
MIPS_64SD = b"\x70\x00\xb2\xff"
all_tests = (
(CS_ARCH_MIPS, CS_MODE_MIPS32 + CS_MODE_BIG_ENDIAN, MIPS_CODE, "MIPS-32 (Big-endian)"),
(CS_ARCH_MIPS, CS_MODE_MIPS64 + CS_MODE_LITTLE_ENDIAN, MIPS_CODE2, "MIPS-64-EL (Little-endian)"),
(CS_ARCH_MIPS, CS_MODE_MIPS32R6 + CS_MODE_MICRO + CS_MODE_BIG_ENDIAN, MIPS_32R6M, "MIPS-32R6 | Micro (Big-endian)"),
(CS_ARCH_MIPS, CS_MODE_MIPS32R6 + CS_MODE_BIG_ENDIAN, MIPS_32R6, "MIPS-32R6 (Big-endian)"),
(CS_ARCH_MIPS, CS_MODE_MIPS64 | CS_MODE_MIPS2 | CS_MODE_LITTLE_ENDIAN, MIPS_64SD, "MIPS-64-EL + Mips II (Little-endian)"),
(CS_ARCH_MIPS, CS_MODE_MIPS64 | CS_MODE_LITTLE_ENDIAN, MIPS_64SD, "MIPS-64-EL (Little-endian)"),
)

View file

@ -6,7 +6,17 @@ from capstone import *
from capstone.mos65xx import *
from xprint import to_hex, to_x
MOS65XX_CODE = b"\x0d\x34\x12\x00\x81\x65\x6c\x01\x00\x85\xFF\x10\x00\x19\x42\x42\x00\x49\x42"
M6502_CODE = b"\xa1\x12\xa5\x12\xa9\x12\xad\x34\x12\xb1\x12\xb5\x12\xb9\x34\x12\xbd\x34\x12\x0d\x34\x12\x00\x81\x87\x6c\x01\x00\x85\xFF\x10\x00\x19\x42\x42\x00\x49\x42"
M65C02_CODE = b"\x1a\x3a\x02\x12\x03\x5c\x34\x12"
MW65C02_CODE = b"\x07\x12\x27\x12\x47\x12\x67\x12\x87\x12\xa7\x12\xc7\x12\xe7\x12\x10\xfe\x0f\x12\xfd\x4f\x12\xfd\x8f\x12\xfd\xcf\x12\xfd"
M65816_CODE = b"\xa9\x34\x12\xad\x34\x12\xbd\x34\x12\xb9\x34\x12\xaf\x56\x34\x12\xbf\x56\x34\x12\xa5\x12\xb5\x12\xb2\x12\xa1\x12\xb1\x12\xa7\x12\xb7\x12\xa3\x12\xb3\x12\xc2\x00\xe2\x00\x54\x34\x12\x44\x34\x12\x02\x12"
all_tests = (
(CS_ARCH_MOS65XX, CS_MODE_MOS65XX_6502, M6502_CODE, "MOS65XX_6502"),
(CS_ARCH_MOS65XX, CS_MODE_MOS65XX_65C02, M65C02_CODE, "MOS65XX_65C02"),
(CS_ARCH_MOS65XX, CS_MODE_MOS65XX_W65C02, MW65C02_CODE, "MOS65XX_W65C02"),
(CS_ARCH_MOS65XX, CS_MODE_MOS65XX_65816_LONG_MX, M65816_CODE, "MOS65XX_65816 (long m/x)"),
)
address_modes=[
"No address mode",
@ -35,7 +45,7 @@ address_modes=[
"absolute long indexed with x",
"stack relative",
"stack relative indirect indexed with y",
];
]
def print_insn_detail(insn):
@ -62,21 +72,23 @@ def print_insn_detail(insn):
# ## Test class Cs
def test_class():
print("*" * 16)
print("Platform: %s" % "MOS65XX")
print("Code: %s" % to_hex(MOS65XX_CODE))
print("Disasm:")
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(CS_ARCH_MOS65XX, 0)
md.detail = True
for insn in md.disasm(MOS65XX_CODE, 0x1000):
print_insn_detail(insn)
print()
try:
md = Cs(arch, mode)
md.detail = True
md.syntax = CS_OPT_SYNTAX_MOTOROLA
for insn in md.disasm(code, 0x1000):
print_insn_detail(insn)
print()
print("0x%x:\n" % (insn.address + insn.size))
except CsError as e:
print("ERROR: %s" % e)
print("0x%x:\n" % (insn.address + insn.size))
except CsError as e:
print("ERROR: %s" % e)
if __name__ == '__main__':

View file

@ -4,7 +4,7 @@
from __future__ import print_function
from capstone import *
from capstone.ppc import *
from xprint import to_hex, to_x_32
from xprint import to_hex, to_x, to_x_32
PPC_CODE = b"\x43\x20\x0c\x07\x41\x56\xff\x17\x80\x20\x00\x00\x80\x3f\x00\x00\x10\x43\x23\x0e\xd0\x44\x00\x80\x4c\x43\x22\x02\x2d\x03\x00\x80\x7c\x43\x20\x14\x7c\x43\x20\x93\x4f\x20\x00\x21\x4c\xc8\x00\x21\x40\x82\x00\x14"
PPC_CODE2 = b"\x10\x60\x2a\x10\x10\x64\x28\x88\x7c\x4a\x5d\x0f"
@ -30,41 +30,41 @@ def print_insn_detail(insn):
c = 0
for i in insn.operands:
if i.type == PPC_OP_REG:
print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.value.reg)))
print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg)))
if i.type == PPC_OP_IMM:
print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x_32(i.value.imm)))
print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x(i.imm)))
if i.type == PPC_OP_MEM:
print("\t\toperands[%u].type: MEM" % c)
if i.value.mem.base != 0:
if i.mem.base != PPC_REG_INVALID:
print("\t\t\toperands[%u].mem.base: REG = %s" \
% (c, insn.reg_name(i.value.mem.base)))
if i.value.mem.offset != 0:
print("\t\t\toperands[%u].mem.offset: REG = %s\n" \
% (c, insn.reg_name(i.value.mem.offset)))
if i.value.mem.disp != 0:
% (c, insn.reg_name(i.mem.base)))
if i.mem.offset != 0:
print("\t\t\toperands[%u].mem.offset: REG = %s" \
% (c, insn.reg_name(i.mem.offset)))
if i.mem.disp != 0:
print("\t\t\toperands[%u].mem.disp: 0x%s" \
% (c, to_x_32(i.value.mem.disp)))
% (c, to_x_32(i.mem.disp)))
if i.access == CS_AC_READ:
print("\t\toperands[%u].access: READ\n" % (c))
print("\t\toperands[%u].access: READ" % (c))
elif i.access == CS_AC_WRITE:
print("\t\toperands[%u].access: WRITE\n" % (c))
print("\t\toperands[%u].access: WRITE" % (c))
elif i.access == CS_AC_READ | CS_AC_WRITE:
print("\t\toperands[%u].access: READ | WRITE\n" % (c))
print("\t\toperands[%u].access: READ | WRITE" % (c))
c += 1
if insn.bc.pred_cr != PPC_PRED_INVALID or \
insn.bc.pred_ctr != PPC_PRED_INVALID:
print("\tBranch:\n")
print("\t\tbi: %u\n" % insn.bc.bi)
print("\t\tbo: %u\n" % insn.bc.bo)
if insn.bc.bh != PPC_BH_INVALID:
print("\t\tbh: %u\n" %insn.bc.bh)
if insn.bc.pred_cr != PPC_PRED_INVALID:
print("\t\tcrX: %s\n" % insn.reg_name(insn.bc.crX))
print("\t\tpred CR-bit: %u\n" % insn.bc.pred_cr)
if insn.bc.pred_ctr != PPC_PRED_INVALID:
print("\t\tpred CTR: %u\n" % insn.bc.pred_ctr)
if insn.bc.hint != PPC_BH_INVALID:
print("\t\thint: %u\n" % insn.bc.hint)
if insn.bc.pred_cr != PPC_PRED_INVALID or \
insn.bc.pred_ctr != PPC_PRED_INVALID:
print("\tBranch:")
print("\t\tbi: %u" % insn.bc.bi)
print("\t\tbo: %u" % insn.bc.bo)
if insn.bc.bh != PPC_BH_INVALID:
print("\t\tbh: %u" %insn.bc.bh)
if insn.bc.pred_cr != PPC_PRED_INVALID:
print("\t\tcrX: %s" % insn.reg_name(insn.bc.crX))
print("\t\tpred CR-bit: %u" % insn.bc.pred_cr)
if insn.bc.pred_ctr != PPC_PRED_INVALID:
print("\t\tpred CTR: %u" % insn.bc.pred_ctr)
if insn.bc.hint != PPC_BR_NOT_GIVEN:
print("\t\thint: %u" % insn.bc.hint)
if insn.update_cr0:
print("\tUpdate-CR0: True")

View file

@ -41,6 +41,9 @@ def print_insn_detail(insn):
print("\t\t\toperands[%u].mem.disp: 0x%s" \
% (c, to_x(i.mem.disp)))
c += 1
if len(insn.groups) > 0:
print('\tgroups: ' + ' '.join(map(lambda g: insn.group_name(g), insn.groups)))
# ## Test class Cs

View file

@ -67,7 +67,29 @@ def print_insn_detail(insn):
if i.type == TMS320C64X_OP_REGPAIR:
print("\t\toperands[%u].type: REGPAIR = %s:%s" % (c, insn.reg_name(i.reg + 1), insn.reg_name(i.reg)))
c += 1
print("\tFunctional unit: ", end="")
if insn.funit.unit == TMS320C64X_FUNIT_D:
print("D%u" % insn.funit.side)
elif insn.funit.unit == TMS320C64X_FUNIT_L:
print("L%u" % insn.funit.side)
elif insn.funit.unit == TMS320C64X_FUNIT_M:
print("M%u" % insn.funit.side)
elif insn.funit.unit == TMS320C64X_FUNIT_S:
print("S%u" % insn.funit.side)
elif insn.funit.unit == TMS320C64X_FUNIT_NO:
print("No Functional Unit")
else:
print("Unknown (Unit %u, Side %u)" % (insn.funit.unit, insn.funit.side))
if insn.funit.crosspath == 1:
print("\tCrosspath: 1")
if insn.condition.reg != TMS320C64X_REG_INVALID:
print("\tCondition: [%c%s]" % ("!" if insn.condition.zero == 1 else " ", insn.reg_name(insn.condition.reg)))
print("\tParallel: %s" % ("true" if insn.parallel == 1 else "false"))
print()
# ## Test class Cs
def test_class():
@ -83,7 +105,6 @@ def test_class():
md.detail = True
for insn in md.disasm(code, 0x1000):
print_insn_detail(insn)
print ()
print("0x%x:\n" % (insn.address + insn.size))
except CsError as e:
print("ERROR: %s" %e)

View file

@ -5,10 +5,9 @@
from __future__ import print_function
from capstone import *
from capstone.tricore import *
from xprint import to_x, to_hex
from xprint import to_x_32, to_hex
TRICORE_CODE = b"\x16\x01\x20\x01\x1d\x00\x02\x00\x8f\x70\x00\x11\x40\xae\x89\xee\x04\x09\x42\xf2\xe2\xf2\xc2\x11\x19" \
b"\xff\xc0\x70\x19\xff\x20\x10"
TRICORE_CODE = b"\x09\xcf\xbc\xf5\x09\xf4\x01\x00\x89\xfb\x8f\x74\x89\xfe\x48\x01\x29\x00\x19\x25\x29\x03\x09\xf4\x85\xf9\x68\x0f\x16\x01"
all_tests = (
(CS_ARCH_TRICORE, CS_MODE_TRICORE_162, TRICORE_CODE, "TriCore"),
@ -30,7 +29,7 @@ def print_insn_detail(insn):
if i.type == TRICORE_OP_REG:
print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg)))
if i.type == TRICORE_OP_IMM:
print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x(i.imm)))
print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x_32(i.imm)))
if i.type == TRICORE_OP_MEM:
print("\t\toperands[%u].type: MEM" % c)
if i.mem.base != 0:
@ -38,8 +37,9 @@ def print_insn_detail(insn):
% (c, insn.reg_name(i.mem.base)))
if i.mem.disp != 0:
print("\t\t\toperands[%u].mem.disp: 0x%s" \
% (c, to_x(i.mem.disp)))
% (c, to_x_32(i.mem.disp)))
c += 1
print()
# ## Test class Cs
@ -55,8 +55,7 @@ def test_class():
md.detail = True
for insn in md.disasm(code, 0x1000):
print_insn_detail(insn)
print()
print("0x%x:\n" % (insn.address + insn.size))
print("0x%x:" % (insn.address + insn.size))
except CsError as e:
print("ERROR: %s" % e)

View file

@ -115,6 +115,50 @@ def get_eflag_name(eflag):
else:
return None
def get_fpu_flag_name(flag):
if flag == X86_FPU_FLAGS_MODIFY_C0:
return "MOD_C0"
elif flag == X86_FPU_FLAGS_MODIFY_C1:
return "MOD_C1"
elif flag == X86_FPU_FLAGS_MODIFY_C2:
return "MOD_C2"
elif flag == X86_FPU_FLAGS_MODIFY_C3:
return "MOD_C3"
elif flag == X86_FPU_FLAGS_RESET_C0:
return "RESET_C0"
elif flag == X86_FPU_FLAGS_RESET_C1:
return "RESET_C1"
elif flag == X86_FPU_FLAGS_RESET_C2:
return "RESET_C2"
elif flag == X86_FPU_FLAGS_RESET_C3:
return "RESET_C3"
elif flag == X86_FPU_FLAGS_SET_C0:
return "SET_C0"
elif flag == X86_FPU_FLAGS_SET_C1:
return "SET_C1"
elif flag == X86_FPU_FLAGS_SET_C2:
return "SET_C2"
elif flag == X86_FPU_FLAGS_SET_C3:
return "SET_C3"
elif flag == X86_FPU_FLAGS_UNDEFINED_C0:
return "UNDEF_C0"
elif flag == X86_FPU_FLAGS_UNDEFINED_C1:
return "UNDEF_C1"
elif flag == X86_FPU_FLAGS_UNDEFINED_C2:
return "UNDEF_C2"
elif flag == X86_FPU_FLAGS_UNDEFINED_C3:
return "UNDEF_C3"
elif flag == X86_FPU_FLAGS_TEST_C0:
return "TEST_C0"
elif flag == X86_FPU_FLAGS_TEST_C1:
return "TEST_C1"
elif flag == X86_FPU_FLAGS_TEST_C2:
return "TEST_C2"
elif flag == X86_FPU_FLAGS_TEST_C3:
return "TEST_C3"
else:
return None
def print_insn_detail(mode, insn):
def print_string_hex(comment, str):
@ -150,7 +194,7 @@ def print_insn_detail(mode, insn):
print("\tmodrm_offset: 0x%x" % (insn.encoding.modrm_offset))
# print displacement value
print("\tdisp: 0x%s" % to_x_32(insn.disp))
print("\tdisp: 0x%s" % to_x(insn.disp))
# print displacement offset (offset into instruction bytes)
if insn.encoding.disp_offset != 0:
@ -236,11 +280,11 @@ def print_insn_detail(mode, insn):
print("\t\toperands[%u].size: %u" % (c, i.size))
if i.access == CS_AC_READ:
print("\t\toperands[%u].access: READ\n" % (c))
print("\t\toperands[%u].access: READ" % (c))
elif i.access == CS_AC_WRITE:
print("\t\toperands[%u].access: WRITE\n" % (c))
print("\t\toperands[%u].access: WRITE" % (c))
elif i.access == CS_AC_READ | CS_AC_WRITE:
print("\t\toperands[%u].access: READ | WRITE\n" % (c))
print("\t\toperands[%u].access: READ | WRITE" % (c))
(regs_read, regs_write) = insn.regs_access()
@ -255,13 +299,22 @@ def print_insn_detail(mode, insn):
for r in regs_write:
print(" %s" %(insn.reg_name(r)), end="")
print("")
if insn.eflags:
if insn.eflags or insn.fpu_flags:
updated_flags = []
for i in range(0,46):
if insn.eflags & (1 << i):
updated_flags.append(get_eflag_name(1 << i))
print("\tEFLAGS: %s" % (','.join(p for p in updated_flags)))
for group in insn.groups:
if group == X86_GRP_FPU:
for i in range(64):
if insn.fpu_flags & (1 << i):
updated_flags.append(get_fpu_flag_name(1 << i))
print("\tFPU_FLAGS: %s" % (' '.join(p for p in updated_flags)))
break
if not updated_flags:
for i in range(64):
if insn.eflags & (1 << i):
updated_flags.append(get_eflag_name(1 << i))
print("\tEFLAGS: %s" % (' '.join(p for p in updated_flags)))
# ## Test class Cs

View file

@ -130,6 +130,7 @@ CFLAGS += -DCAPSTONE_HAS_BPF
SOURCES += test_bpf.c
endif
ifneq (,$(findstring tricore,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_TRICORE
SOURCES += test_tricore.c
endif
ifneq (,$(findstring sh,$(CAPSTONE_ARCHS)))

View file

@ -159,7 +159,7 @@ static void print_insn_detail(csh cs_handle, cs_insn *ins)
}
if (op->subtracted)
printf("\t\tSubtracted: True\n");
printf("\t\toperands[%u].subtracted = True\n", i);
}
if (arm->cc != ARMCC_AL && arm->cc != ARMCC_UNDEF)
@ -171,8 +171,12 @@ static void print_insn_detail(csh cs_handle, cs_insn *ins)
if (arm->update_flags)
printf("\tUpdate-flags: True\n");
if (ins->detail->writeback)
printf("\tWrite-back: True\n");
if (ins->detail->writeback) {
if (arm->post_index)
printf("\tWrite-back: Post\n");
else
printf("\tWrite-back: Pre\n");
}
if (arm->cps_mode)
printf("\tCPSI-mode: %u\n", arm->cps_mode);

View file

@ -67,7 +67,7 @@ static void test()
#define XCORE_CODE "\xfe\x0f\xfe\x17\x13\x17\xc6\xfe\xec\x17\x97\xf8\xec\x4f\x1f\xfd\xec\x37\x07\xf2\x45\x5b\xf9\xfa\x02\x06\x1b\x10"
#endif
#ifdef CAPSTONE_HAS_M68K
#define M68K_CODE "\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28"
#define M68K_CODE "\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28\x4E\xB9\x00\x00\x00\x12\x4E\x75"
#endif
#ifdef CAPSTONE_HAS_TMS320C64X
#define TMS320C64X_CODE "\x01\xac\x88\x40\x81\xac\x88\x43\x00\x00\x00\x00\x02\x90\x32\x96\x02\x80\x46\x9e\x05\x3c\x83\xe6\x0b\x0c\x8b\x24"
@ -84,8 +84,9 @@ static void test()
#ifdef CAPSTONE_HAS_MOS65XX
#define MOS65XX_CODE "\x0d\x34\x12\x00\x81\x65\x6c\x01\x00\x85\xFF\x10\x00\x19\x42\x42\x00\x49\x42"
#endif
#ifdef CAPSTONE_HAS_BPF
#define EBPF_CODE "\x97\x09\x00\x00\x37\x13\x03\x00\xdc\x02\x00\x00\x20\x00\x00\x00\x30\x00\x00\x00\x00\x00\x00\x00\xdb\x3a\x00\x01\x00\x00\x00\x00\x84\x02\x00\x00\x00\x00\x00\x00\x6d\x33\x17\x02\x00\x00\x00\x00"
#endif
#ifdef CAPSTONE_HAS_RISCV
#define RISCV_CODE32 "\x37\x34\x00\x00\x97\x82\x00\x00\xef\x00\x80\x00\xef\xf0\x1f\xff\xe7\x00\x45\x00\xe7\x00\xc0\xff\x63\x05\x41\x00\xe3\x9d\x61\xfe\x63\xca\x93\x00\x63\x53\xb5\x00\x63\x65\xd6\x00\x63\x76\xf7\x00\x03\x88\x18\x00\x03\x99\x49\x00\x03\xaa\x6a\x00\x03\xcb\x2b\x01\x03\xdc\x8c\x01\x23\x86\xad\x03\x23\x9a\xce\x03\x23\x8f\xef\x01\x93\x00\xe0\x00\x13\xa1\x01\x01\x13\xb2\x02\x7d\x13\xc3\x03\xdd\x13\xe4\xc4\x12\x13\xf5\x85\x0c\x13\x96\xe6\x01\x13\xd7\x97\x01\x13\xd8\xf8\x40\x33\x89\x49\x01\xb3\x0a\x7b\x41\x33\xac\xac\x01\xb3\x3d\xde\x01\x33\xd2\x62\x40\xb3\x43\x94\x00\x33\xe5\xc5\x00\xb3\x76\xf7\x00\xb3\x54\x39\x01\xb3\x50\x31\x00\x33\x9f\x0f\x00"
#define RISCV_CODE64 "\x13\x04\xa8\x7a" // aaa80413

View file

@ -67,7 +67,7 @@ static void test()
#define XCORE_CODE "\xfe\x0f\xfe\x17\x13\x17\xc6\xfe\xec\x17\x97\xf8\xec\x4f\x1f\xfd\xec\x37\x07\xf2\x45\x5b\xf9\xfa\x02\x06\x1b\x10"
#endif
#ifdef CAPSTONE_HAS_M68K
#define M68K_CODE "\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28"
#define M68K_CODE "\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28\x4E\xB9\x00\x00\x00\x12\x4E\x75"
#endif
#ifdef CAPSTONE_HAS_M680X
#define M680X_CODE "\x06\x10\x19\x1a\x55\x1e\x01\x23\xe9\x31\x06\x34\x55\xa6\x81\xa7\x89\x7f\xff\xa6\x9d\x10\x00\xa7\x91\xa6\x9f\x10\x00\x11\xac\x99\x10\x00\x39"
@ -75,7 +75,9 @@ static void test()
#ifdef CAPSTONE_HAS_MOS65XX
#define MOS65XX_CODE "\x0A\x00\xFE\x34\x12\xD0\xFF\xEA\x19\x56\x34\x46\x80"
#endif
#ifdef CAPSTONE_HAS_BPF
#define EBPF_CODE "\x97\x09\x00\x00\x37\x13\x03\x00\xdc\x02\x00\x00\x20\x00\x00\x00\x30\x00\x00\x00\x00\x00\x00\x00\xdb\x3a\x00\x01\x00\x00\x00\x00\x84\x02\x00\x00\x00\x00\x00\x00\x6d\x33\x17\x02\x00\x00\x00\x00"
#endif
struct platform platforms[] = {
#ifdef CAPSTONE_HAS_X86
@ -118,13 +120,6 @@ static void test()
sizeof(ARM_CODE) - 1,
"ARM"
},
{
CS_ARCH_ARM,
CS_MODE_THUMB,
(unsigned char *)THUMB_CODE2,
sizeof(THUMB_CODE2) - 1,
"THUMB-2"
},
{
CS_ARCH_ARM,
CS_MODE_ARM,
@ -139,6 +134,13 @@ static void test()
sizeof(THUMB_CODE) - 1,
"THUMB"
},
{
CS_ARCH_ARM,
CS_MODE_THUMB,
(unsigned char *)THUMB_CODE2,
sizeof(THUMB_CODE2) - 1,
"THUMB-2"
},
{
CS_ARCH_ARM,
(cs_mode)(CS_MODE_THUMB + CS_MODE_MCLASS),
@ -154,6 +156,15 @@ static void test()
"Arm-V8"
},
#endif
#ifdef CAPSTONE_HAS_ARM64
{
CS_ARCH_ARM64,
CS_MODE_ARM,
(unsigned char *)ARM64_CODE,
sizeof(ARM64_CODE) - 1,
"ARM-64"
},
#endif
#ifdef CAPSTONE_HAS_MIPS
{
CS_ARCH_MIPS,
@ -184,15 +195,6 @@ static void test()
"MIPS-32R6 (Big-endian)"
},
#endif
#ifdef CAPSTONE_HAS_ARM64
{
CS_ARCH_ARM64,
CS_MODE_ARM,
(unsigned char *)ARM64_CODE,
sizeof(ARM64_CODE) - 1,
"ARM-64"
},
#endif
#ifdef CAPSTONE_HAS_POWERPC
{
CS_ARCH_PPC,

View file

@ -57,6 +57,7 @@ const char* s_addressing_modes[] = {
"Absolute Data Addressing - Short",
"Absolute Data Addressing - Long",
"Immediate value",
"Branch Displacement",
};
static void print_read_write_regs(cs_detail* detail)
@ -143,6 +144,10 @@ static void print_insn_detail(cs_insn *ins)
cs_reg_name(handle, op->reg_pair.reg_0),
cs_reg_name(handle, op->reg_pair.reg_1));
break;
case M68K_OP_BR_DISP:
printf("\t\toperands[%u].br_disp.disp: 0x%x", i, op->br_disp.disp);
printf("\t\toperands[%u].br_disp.disp_size: %d", i, op->br_disp.disp_size);
break;
}
}

View file

@ -23,7 +23,7 @@ static void print_string_hex(const char *comment, unsigned char *str, size_t len
printf("%s", comment);
for (c = str; c < str + len; c++) {
printf(" 0x%02x", *c & 0xff);
printf("0x%02x ", *c & 0xff);
}
printf("\n");
@ -197,7 +197,7 @@ static void test()
printf("****************\n");
printf("Platform: %s\n", platforms[i].comment);
print_string_hex("Code:", platforms[i].code, platforms[i].size);
print_string_hex("Code: ", platforms[i].code, platforms[i].size);
printf("Disasm:\n");
for (j = 0; j < count; j++) {

View file

@ -57,20 +57,37 @@ static void print_insn_detail(cs_insn *ins)
if (op->mem.base != PPC_REG_INVALID)
printf("\t\t\toperands[%u].mem.base: REG = %s\n",
i, cs_reg_name(handle, op->mem.base));
if (op->mem.offset != 0)
printf("\t\t\toperands[%u].mem.offset: REG = %s\n",
i, cs_reg_name(handle, op->mem.offset));
if (op->mem.disp != 0)
printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
break;
}
if (op->access == CS_AC_READ)
printf("\t\t\toperands[%u].access: READ\n", i);
else if (op->access == CS_AC_WRITE)
printf("\t\t\toperands[%u].access: WRITE\n", i);
else if (op->access == (CS_AC_READ | CS_AC_WRITE))
printf("\t\t\toperands[%u].access: READ | WRITE\n", i);
}
if (ppc->bc.pred_cr != PPC_PRED_INVALID)
printf("\t\tpred CR-bit: %d\n", ppc->bc.pred_cr);
if (ppc->bc.pred_ctr != PPC_PRED_INVALID)
printf("\t\tpred CTR: %d\n", ppc->bc.pred_ctr);
if (ppc->bc.hint != PPC_BR_NOT_GIVEN)
printf("\tBranch hint: %u\n", ppc->bc.hint);
if (ppc->bc.pred_cr != PPC_PRED_INVALID || ppc->bc.pred_ctr != PPC_PRED_INVALID) {
printf("\tBranch:\n");
printf("\t\tbi: %u\n", ppc->bc.bi);
printf("\t\tbo: %u\n", ppc->bc.bo);
if (ppc->bc.bh != PPC_BH_INVALID)
printf("\t\tbh: %u\n", ppc->bc.bh);
if (ppc->bc.pred_cr != PPC_PRED_INVALID) {
printf("\t\tcrX: %s\n", cs_reg_name(handle, ppc->bc.crX));
printf("\t\tpred CR-bit: %u\n", ppc->bc.pred_cr);
}
if (ppc->bc.pred_ctr != PPC_PRED_INVALID)
printf("\t\tpred CTR: %u\n", ppc->bc.pred_ctr);
if (ppc->bc.hint != PPC_BR_NOT_GIVEN)
printf("\t\thint: %u\n", ppc->bc.hint);
}
if (ppc->update_cr0)
printf("\tUpdate-CR0: True\n");

View file

@ -69,7 +69,7 @@ static void print_insn_detail(cs_insn *ins)
//print the groups this instruction belongs to
if (detail->groups_count > 0) {
printf("\tThis instruction belongs to groups: ");
printf("\tgroups: ");
for (n = 0; n < detail->groups_count; n++) {
printf("%s ", cs_group_name(handle, detail->groups[n]));
}

View file

@ -29,14 +29,6 @@ static void print_string_hex(const char *comment, unsigned char *str, size_t len
printf("\n");
}
static void print_string_hex_short(unsigned char *str, size_t len)
{
unsigned char *c;
for (c = str; c < str + len; c++)
printf("%02x", *c & 0xff);
}
static void print_read_write_regs(csh handle, cs_detail *detail)
{
int i;
@ -73,6 +65,7 @@ static void print_insn_detail(csh handle, cs_insn *insn)
cs_detail *detail = insn->detail;
cs_sh *sh = NULL;
int i;
int n;
// detail can be NULL on "data" instruction if SKIPDATA option is turned ON
if (detail == NULL)
@ -151,8 +144,12 @@ static void print_insn_detail(csh handle, cs_insn *insn)
print_read_write_regs(handle, detail);
if (detail->groups_count) {
printf("\tgroups_count: %u\n", detail->groups_count);
if (detail->groups_count > 0) {
printf("\tgroups: ");
for (n = 0; n < detail->groups_count; n++) {
printf("%s ", cs_group_name(handle, detail->groups[n]));
}
printf("\n");
}
printf("\n");
@ -166,11 +163,11 @@ static bool consistency_checks()
static void test()
{
#define SH4A_CODE \
"\xc\x31\x10\x20\x22\x21\x36\x64\x46\x25\x12\x12\x1c\x2\x8\xc1\x5\xc7\xc" \
"\x71\x1f\x2\x22\xcf\x6\x89\x23\x0\x2b\x41\xb\x0\xe\x40\x32\x0\xa\xf1\x9\x0"
"\x0c\x31\x10\x20\x22\x21\x36\x64\x46\x25\x12\x12\x1c\x02\x08\xc1\x05\xc7\x0c" \
"\x71\x1f\x02\x22\xcf\x06\x89\x23\x00\x2b\x41\x0b\x00\x0e\x40\x32\x00\x0a\xf1\x09\x00"
#define SH2A_CODE \
"\x32\x11\x92\x0\x32\x49\x31\x0"
"\x32\x11\x92\x00\x32\x49\x31\x00"
struct platform platforms[] = {
{
@ -194,7 +191,6 @@ static void test()
cs_insn *insn;
int i;
size_t count;
const char *nine_spaces = " ";
if (!consistency_checks())
abort();
@ -219,33 +215,25 @@ static void test()
if (count) {
size_t j;
printf("********************\n");
printf("****************\n");
printf("Platform: %s\n", platforms[i].comment);
print_string_hex("Code: ", platforms[i].code,
platforms[i].size);
printf("Disasm:\n");
for (j = 0; j < count; j++) {
int slen;
printf("0x%08x: ", (uint32_t)insn[j].address);
print_string_hex_short(insn[j].bytes,
insn[j].size);
printf("%.*s", 1 + ((5 - insn[j].size) * 2),
nine_spaces);
printf("%s", insn[j].mnemonic);
slen = (int)strlen(insn[j].mnemonic);
printf("%.*s", 1 + (5 - slen), nine_spaces);
printf("%s\n", insn[j].op_str);
printf("0x%"PRIx64":\t%s\t%s\n", insn[j].address, insn[j].mnemonic, insn[j].op_str);
#ifdef WITH_DETAILS
print_insn_detail(handle, &insn[j]);
#endif
}
printf("0x%" PRIx64 ":\n", insn[j-1].address + insn[j-1].size);
// free memory allocated by cs_disasm()
cs_free(insn, count);
}
else {
printf("********************\n");
printf("****************\n");
printf("Platform: %s\n", platforms[i].comment);
print_string_hex("Code:", platforms[i].code,
platforms[i].size);

View file

@ -59,11 +59,11 @@ static void print_insn_detail(cs_insn *ins)
printf("\t\t\toperands[%u].mem.disptype: ", i);
if(op->mem.disptype == TMS320C64X_MEM_DISP_INVALID) {
printf("Invalid\n");
printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
}
if(op->mem.disptype == TMS320C64X_MEM_DISP_CONSTANT) {
printf("Constant\n");
printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
}
if(op->mem.disptype == TMS320C64X_MEM_DISP_REGISTER) {
printf("Register\n");

View file

@ -132,8 +132,6 @@ static void test()
printf("ERROR: Failed to disasm given code!\n");
}
printf("\n");
cs_close(&handle);
}
}

View file

@ -78,10 +78,20 @@ static void print_insn_detail(csh cs_handle, cs_insn *ins)
printf("\t\tOperand[%u] type: varuint64\n", i);
printf("\t\tOperand[%u] value: 0x%" PRIx64 "\n", i, wasm->operands[i].varuint64);
break;
case WASM_OP_IMM:
printf("\t\tOperand[%u] type: imm\n", i);
printf("\t\tOperand[%u] value: 0x%x 0x%x\n", i, wasm->operands[i].immediate[0], wasm->operands[i].immediate[1]);
break;
case WASM_OP_BRTABLE:
printf("\t\tOperand[%u] type: brtable\n", i);
printf("\t\tOperand[%u] value: length=0x%x, address=0x%" PRIx64 ", default_target=%x\n", i, wasm->operands[i].brtable.length, wasm->operands[i].brtable.address, wasm->operands[i].brtable.default_target);
break;
}
printf("\t\tOperand[%u] size: %u\n", i, wasm->operands[i].size);
}
}
printf("\n");
}
static void test()