From 824dc5e8fdcbd2ede87c6b798722cfb0dccd39cf Mon Sep 17 00:00:00 2001 From: kabeor Date: Tue, 7 Mar 2023 13:17:45 +0800 Subject: [PATCH] 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()