From 796f8c986122eef69cc219eb6dd7af6261cacc61 Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 12:03:16 +0800 Subject: [PATCH 1/8] fix warning --- cs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cs.c b/cs.c index 73c70fd529..2588c340b8 100644 --- a/cs.c +++ b/cs.c @@ -369,8 +369,8 @@ bool CAPSTONE_API cs_support(int query) (1 << CS_ARCH_M68K) | (1 << CS_ARCH_TMS320C64X) | (1 << CS_ARCH_M680X) | (1 << CS_ARCH_EVM) | (1 << CS_ARCH_RISCV) | (1 << CS_ARCH_MOS65XX) | - (1 << CS_ARCH_WASM) | (1 << CS_ARCH_BPF)) | - (1 << CS_ARCH_SH); + (1 << CS_ARCH_WASM) | (1 << CS_ARCH_BPF) | + (1 << CS_ARCH_SH)); if ((unsigned int)query < CS_ARCH_MAX) return all_arch & (1 << query); From 93b13a20f83fd2f145d079b1ac9a1e05c842298c Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 12:03:47 +0800 Subject: [PATCH 2/8] fix python binding build --- .github/workflows/CITest.yml | 14 +++++++------- Makefile | 3 ++- bindings/python/setup_cython.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index de92c8dfb6..9d266b721e 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -99,17 +99,17 @@ jobs: if: startsWith(matrix.config.build-system, 'cmake') shell: 'script -q -e -c "bash {0}"' run: | - mkdir build - cd build - cmake -DCAPSTONE_INSTALL=1 .. - cmake --build . --config Release - sudo make install + mkdir build && cd build; + cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 ..; + cmake --build . --config Release; + sudo make install; - name: build python binding shell: 'script -q -e -c "bash {0}"' run: | - cp libcapstone.so.* bindings/python/libcapstone.so - cd bindings/python && make check; cd ../..; + mkdir -p ~/capstone/bindings/python/capstone/lib && cp libcapstone.so.5.* ~/capstone/bindings/python/capstone/lib/libcapstone.so; + cd ~/capstone/bindings/python; + make check; cd ../..; - name: cstest shell: 'script -q -e -c "bash {0}"' diff --git a/Makefile b/Makefile index aa70b7a166..d050c27d2b 100644 --- a/Makefile +++ b/Makefile @@ -324,6 +324,7 @@ endif endif API_MAJOR=$(shell echo `grep -e CS_API_MAJOR include/capstone/capstone.h | grep -v = | awk '{print $$3}'` | awk '{print $$1}') +API_MINOR=$(shell echo `grep -e CS_API_MINOR include/capstone/capstone.h | grep -v = | awk '{print $$3}'` | awk '{print $$1}') VERSION_EXT = IS_APPLE := $(shell $(CC) -dM -E - < /dev/null 2> /dev/null | grep __apple_build_version__ | wc -l | tr -d " ") @@ -374,7 +375,7 @@ CFLAGS := $(CFLAGS:-fPIC=) else # Linux, *BSD EXT = so -VERSION_EXT = $(EXT).$(API_MAJOR) +VERSION_EXT = $(EXT).$(API_MAJOR).$(API_MINOR) AR_EXT = a $(LIBNAME)_LDFLAGS += -Wl,-soname,lib$(LIBNAME).$(VERSION_EXT) endif diff --git a/bindings/python/setup_cython.py b/bindings/python/setup_cython.py index 23e5ac8947..5751f309be 100644 --- a/bindings/python/setup_cython.py +++ b/bindings/python/setup_cython.py @@ -9,7 +9,7 @@ from Cython.Distutils import build_ext SYSTEM = sys.platform -VERSION = '4.0.0' +VERSION = '5.0.0' # adapted from commit e504b81 of Nguyen Tan Cong # Reference: https://docs.python.org/2/library/platform.html#cross-platform From 6f63b25d6b14e8fc38402937c77809a34f2a4881 Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 12:05:05 +0800 Subject: [PATCH 3/8] provide limited tests for make --- .github/workflows/CITest.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 9d266b721e..eb27f0cc1d 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -30,28 +30,28 @@ jobs: matrix: config: - { - name: 'ubuntu-18.04 x64 python2.7 make', + name: 'ubuntu-18.04 x64 python2.7 cmake', os: ubuntu-18.04, arch: x64, python-arch: x64, python-version: '2.7', - build-system: 'make', + build-system: 'cmake', } - { - name: 'ubuntu-18.04 x64 python3.6 make', + name: 'ubuntu-18.04 x64 python3.6 cmake', os: ubuntu-18.04, arch: x64, python-arch: x64, python-version: '3.6', - build-system: 'make', + build-system: 'cmake', } - { - name: 'ubuntu-20.04 x64 python2.7 make', + name: 'ubuntu-20.04 x64 python2.7 cmake', os: ubuntu-20.04, arch: x64, python-arch: x64, python-version: '2.7', - build-system: 'make', + build-system: 'cmake', } - { name: 'ubuntu-20.04 x64 python3.9 make', From 4ec38db0ce41e77751564170a9e969f1ca217189 Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 12:11:52 +0800 Subject: [PATCH 4/8] fix ci lib path --- .github/workflows/CITest.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index eb27f0cc1d..df20c36628 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -93,7 +93,7 @@ jobs: run: | ./make.sh make check - sudo make install + # sudo make install - name: cmake if: startsWith(matrix.config.build-system, 'cmake') @@ -102,13 +102,16 @@ jobs: mkdir build && cd build; cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 ..; cmake --build . --config Release; - sudo make install; + # sudo make install; - name: build python binding shell: 'script -q -e -c "bash {0}"' run: | + pwd; + ls; mkdir -p ~/capstone/bindings/python/capstone/lib && cp libcapstone.so.5.* ~/capstone/bindings/python/capstone/lib/libcapstone.so; cd ~/capstone/bindings/python; + pwd; make check; cd ../..; - name: cstest From e294aea4032e7d7a417fbc9f9c1df31631597629 Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 12:38:41 +0800 Subject: [PATCH 5/8] fix ci lib path --- .github/workflows/CITest.yml | 15 +++++++-------- CMakeLists.txt | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index df20c36628..2a57075aa1 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -91,8 +91,9 @@ jobs: if: startsWith(matrix.config.build-system, 'make') shell: 'script -q -e -c "bash {0}"' run: | - ./make.sh - make check + ./make.sh; + make check; + mkdir build && mv libcapstone.* build/ && cd build; # sudo make install - name: cmake @@ -107,12 +108,10 @@ jobs: - name: build python binding shell: 'script -q -e -c "bash {0}"' run: | - pwd; - ls; - mkdir -p ~/capstone/bindings/python/capstone/lib && cp libcapstone.so.5.* ~/capstone/bindings/python/capstone/lib/libcapstone.so; - cd ~/capstone/bindings/python; - pwd; - make check; cd ../..; + mkdir -p ../bindings/python/capstone/lib && cp libcapstone.so.5.* ../bindings/python/capstone/lib/libcapstone.so; + cd ../bindings/python; + make && make check ; + cd ../..; - name: cstest shell: 'script -q -e -c "bash {0}"' diff --git a/CMakeLists.txt b/CMakeLists.txt index 012a2a02e7..88f941476e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0091 NEW) project(capstone - VERSION 5.0.0 + VERSION 5.0 ) # to configure the options specify them in in the command line or change them in the cmake UI. From fd9be6eed3567f6a3399c8806c5f86b8bd8204e0 Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 12:43:08 +0800 Subject: [PATCH 6/8] ci fix --- .github/workflows/CITest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 2a57075aa1..c872985ae2 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -108,6 +108,7 @@ jobs: - name: build python binding shell: 'script -q -e -c "bash {0}"' run: | + pwd && ls; mkdir -p ../bindings/python/capstone/lib && cp libcapstone.so.5.* ../bindings/python/capstone/lib/libcapstone.so; cd ../bindings/python; make && make check ; From 7ef8e5b4e584e16b27787e1a1010380b6e3f0e74 Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 12:49:12 +0800 Subject: [PATCH 7/8] fix ci --- .github/workflows/CITest.yml | 6 +++--- Makefile | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index c872985ae2..0bbfc98176 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -93,7 +93,6 @@ jobs: run: | ./make.sh; make check; - mkdir build && mv libcapstone.* build/ && cd build; # sudo make install - name: cmake @@ -103,14 +102,15 @@ jobs: mkdir build && cd build; cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 ..; cmake --build . --config Release; + cp libcapstone.* ../; # sudo make install; - name: build python binding shell: 'script -q -e -c "bash {0}"' run: | pwd && ls; - mkdir -p ../bindings/python/capstone/lib && cp libcapstone.so.5.* ../bindings/python/capstone/lib/libcapstone.so; - cd ../bindings/python; + mkdir -p bindings/python/capstone/lib && cp libcapstone.so.5.* bindings/python/capstone/lib/libcapstone.so; + cd bindings/python; make && make check ; cd ../..; diff --git a/Makefile b/Makefile index d050c27d2b..aa70b7a166 100644 --- a/Makefile +++ b/Makefile @@ -324,7 +324,6 @@ endif endif API_MAJOR=$(shell echo `grep -e CS_API_MAJOR include/capstone/capstone.h | grep -v = | awk '{print $$3}'` | awk '{print $$1}') -API_MINOR=$(shell echo `grep -e CS_API_MINOR include/capstone/capstone.h | grep -v = | awk '{print $$3}'` | awk '{print $$1}') VERSION_EXT = IS_APPLE := $(shell $(CC) -dM -E - < /dev/null 2> /dev/null | grep __apple_build_version__ | wc -l | tr -d " ") @@ -375,7 +374,7 @@ CFLAGS := $(CFLAGS:-fPIC=) else # Linux, *BSD EXT = so -VERSION_EXT = $(EXT).$(API_MAJOR).$(API_MINOR) +VERSION_EXT = $(EXT).$(API_MAJOR) AR_EXT = a $(LIBNAME)_LDFLAGS += -Wl,-soname,lib$(LIBNAME).$(VERSION_EXT) endif From 824dc5e8fdcbd2ede87c6b798722cfb0dccd39cf Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 13:17:45 +0800 Subject: [PATCH 8/8] fix python binding --- .github/workflows/CITest.yml | 2 +- bindings/python/test_basic.py | 5 ++++- suite/regress/test_arm64_ldr_registers.py | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index 0bbfc98176..5de2c8f8e9 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -93,6 +93,7 @@ jobs: run: | ./make.sh; make check; + cp libcapstone.so.5 libcapstone.so.5.0 # sudo make install - name: cmake @@ -108,7 +109,6 @@ jobs: - name: build python binding shell: 'script -q -e -c "bash {0}"' run: | - pwd && ls; mkdir -p bindings/python/capstone/lib && cp libcapstone.so.5.* bindings/python/capstone/lib/libcapstone.so; cd bindings/python; make && make check ; diff --git a/bindings/python/test_basic.py b/bindings/python/test_basic.py index a580f05d85..1f4c721a9f 100755 --- a/bindings/python/test_basic.py +++ b/bindings/python/test_basic.py @@ -82,7 +82,10 @@ def test_cs_disasm_quick(): def test_different_data_formats(): - data = bytes.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05') + if _python3: + data = bytes.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05') + else: + data = bytes(bytearray.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05')) mnemonics = ['xor', 'mul', 'add', 'movabs', 'push', 'pop', 'push', 'push', 'push', 'pop', 'syscall'] disassembler = Cs(CS_ARCH_X86, CS_MODE_64) for name, code in ( diff --git a/suite/regress/test_arm64_ldr_registers.py b/suite/regress/test_arm64_ldr_registers.py index d366c40379..fded0ae896 100644 --- a/suite/regress/test_arm64_ldr_registers.py +++ b/suite/regress/test_arm64_ldr_registers.py @@ -2,6 +2,9 @@ from capstone import * from capstone.arm64 import * +_python3 = sys.version_info.major == 3 + + class SubRegTest(unittest.TestCase): PATTERNS = [ @@ -18,7 +21,10 @@ def setUp(self): self.cs.detail = True for pattern, asm in self.PATTERNS: - l = list(self.cs.disasm(bytes.fromhex(pattern), 0)) + if _python3: + l = list(self.cs.disasm(bytes.fromhex(pattern), 0)) + else: + l = list(self.cs.disasm(bytearray.fromhex(pattern), 0)) self.assertTrue(len(l) == 1) _, expected_reg_written, expected_reg_read = asm.split()