From 91d78afca4c9482c8df615093cf8a0ffd14230d1 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Sat, 1 Jun 2024 14:16:38 -0700 Subject: [PATCH 1/3] Remove python2 leftovers --- bindings/python/Makefile | 27 ------------------------- bindings/python/capstone/__init__.py | 20 ++++-------------- bindings/python/setup.py | 10 ++------- bindings/python/test_aarch64.py | 1 - bindings/python/test_alpha.py | 1 - bindings/python/test_arm.py | 1 - bindings/python/test_basic.py | 10 +-------- bindings/python/test_bpf.py | 1 - bindings/python/test_customized_mnem.py | 1 - bindings/python/test_detail.py | 1 - bindings/python/test_evm.py | 4 ---- bindings/python/test_hppa.py | 1 - bindings/python/test_iter.py | 1 - bindings/python/test_lite.py | 1 - bindings/python/test_m680x.py | 8 +------- bindings/python/test_m68k.py | 1 - bindings/python/test_mips.py | 1 - bindings/python/test_mos65xx.py | 1 - bindings/python/test_ppc.py | 1 - bindings/python/test_riscv.py | 1 - bindings/python/test_sh.py | 1 - bindings/python/test_skipdata.py | 2 -- bindings/python/test_sparc.py | 1 - bindings/python/test_systemz.py | 1 - bindings/python/test_tms320c64x.py | 1 - bindings/python/test_tricore.py | 1 - bindings/python/test_wasm.py | 1 - bindings/python/test_x86.py | 3 +-- bindings/python/test_xcore.py | 1 - bindings/python/xprint.py | 21 ++++--------------- 30 files changed, 13 insertions(+), 113 deletions(-) diff --git a/bindings/python/Makefile b/bindings/python/Makefile index 10b9af3134..ea271c0533 100644 --- a/bindings/python/Makefile +++ b/bindings/python/Makefile @@ -1,4 +1,3 @@ -PYTHON2 ?= python2 PYTHON3 ?= python3 .PHONY: gen_const install install3 install_cython sdist sdist3 bdist bdist3 clean check @@ -7,14 +6,6 @@ gen_const: cd .. && $(PYTHON3) const_generator.py python install: - rm -rf src/ - if test -n "${DESTDIR}"; then \ - $(PYTHON2) setup.py build install --root="${DESTDIR}"; \ - else \ - $(PYTHON2) setup.py build install; \ - fi - -install3: rm -rf src/ if test -n "${DESTDIR}"; then \ $(PYTHON3) setup.py build install --root="${DESTDIR}"; \ @@ -24,14 +15,6 @@ install3: # NOTE: Newer cython can be installed by: sudo pip install --upgrade cython install_cython: - rm -rf src/ - if test -n "${DESTDIR}"; then \ - $(PYTHON2) setup_cython.py build install --root="${DESTDIR}"; \ - else \ - $(PYTHON2) setup_cython.py build install; \ - fi - -install3_cython: rm -rf src/ if test -n "${DESTDIR}"; then \ $(PYTHON3) setup_cython.py build install --root="${DESTDIR}"; \ @@ -41,21 +24,11 @@ install3_cython: # build & upload PyPi package with source code of the core sdist: - rm -rf src/ dist/ - $(PYTHON2) setup.py sdist register upload - -# build & upload PyPi package with source code of the core -sdist3: rm -rf src/ dist/ $(PYTHON3) setup.py sdist register upload # build & upload PyPi package with prebuilt core bdist: - rm -rf src/ dist/ - $(PYTHON2) setup.py bdist_wheel register upload - -# build & upload PyPi package with prebuilt core -bdist3: rm -rf src/ dist/ $(PYTHON3) setup.py bdist_wheel register upload diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 154e6f1105..288b705688 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -1,9 +1,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -import os, sys -from platform import system -_python2 = sys.version_info[0] < 3 -if _python2: - range = xrange +import os +import sys __all__ = [ 'Cs', @@ -549,13 +546,8 @@ class CsError(Exception): def __init__(self, errno): self.errno = errno - if _python2: - def __str__(self): - return _cs.cs_strerror(self.errno) - - else: - def __str__(self): - return _cs.cs_strerror(self.errno).decode() + def __str__(self): + return _cs.cs_strerror(self.errno).decode() # return the core's version @@ -1215,10 +1207,6 @@ def group_name(self, group_id, default=None): # Disassemble binary & return disassembled instructions in CsInsn objects def disasm(self, code, offset, count=0): all_insn = ctypes.POINTER(_cs_insn)() - '''if not _python2: - print(code) - code = code.encode() - print(code)''' # Pass a bytearray by reference size = len(code) view = memoryview(code) diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 9cbd35b8bd..02f64f16f3 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -13,10 +13,6 @@ from distutils.command.sdist import sdist from setuptools.command.bdist_egg import bdist_egg -PYTHON2 = sys.version_info[0] == 2 -if PYTHON2: - import io - SYSTEM = sys.platform # adapted from commit e504b81 of Nguyen Tan Cong @@ -220,13 +216,11 @@ def run(self): author_email='aquynh@gmail.com', description='Capstone disassembly engine', url='https://www.capstone-engine.org', - long_description=io.open('README.txt', encoding="utf8").read() if PYTHON2 else open('README.txt', encoding="utf8").read(), + long_description=open('README.txt', encoding="utf8").read(), long_description_content_type='text/markdown', - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', + python_requires='>=3.6', classifiers=[ 'License :: OSI Approved :: BSD License', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', ], cmdclass=cmdclass, diff --git a/bindings/python/test_aarch64.py b/bindings/python/test_aarch64.py index 62031f0f3c..20d213679a 100755 --- a/bindings/python/test_aarch64.py +++ b/bindings/python/test_aarch64.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.aarch64 import * from xprint import to_hex, to_x, to_x_32 diff --git a/bindings/python/test_alpha.py b/bindings/python/test_alpha.py index 404371ea31..056288ae2d 100755 --- a/bindings/python/test_alpha.py +++ b/bindings/python/test_alpha.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Dmitry Sibirtsev -from __future__ import print_function from capstone import * from capstone.alpha import * from xprint import to_x, to_hex diff --git a/bindings/python/test_arm.py b/bindings/python/test_arm.py index fb02aa1fd1..794234fc85 100755 --- a/bindings/python/test_arm.py +++ b/bindings/python/test_arm.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.arm import * from xprint import to_hex, to_x_32 diff --git a/bindings/python/test_basic.py b/bindings/python/test_basic.py index 025715abb7..dfec322c42 100755 --- a/bindings/python/test_basic.py +++ b/bindings/python/test_basic.py @@ -1,15 +1,10 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * -import binascii -import sys from xprint import to_hex -_python3 = sys.version_info.major == 3 - X86_CODE16 = b"\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00" X86_CODE32 = b"\xba\xcd\xab\x00\x00\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00" @@ -102,10 +97,7 @@ def test_cs_disasm_quick(): def test_different_data_formats(): - if _python3: - data = bytes.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05') - else: - data = bytes(bytearray.fromhex('4831C948F7E1043B48BB0A2F62696E2F2F736852530A545F5257545E0F05')) + data = bytes.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/bindings/python/test_bpf.py b/bindings/python/test_bpf.py index 2e7d64d8b7..b7e23d76be 100755 --- a/bindings/python/test_bpf.py +++ b/bindings/python/test_bpf.py @@ -3,7 +3,6 @@ # Capstone Python bindings # BPF tests by david942j , 2019 -from __future__ import print_function from capstone import * from capstone.bpf import * from xprint import to_hex, to_x, to_x_32 diff --git a/bindings/python/test_customized_mnem.py b/bindings/python/test_customized_mnem.py index 57dd12a0f7..553ae3e020 100755 --- a/bindings/python/test_customized_mnem.py +++ b/bindings/python/test_customized_mnem.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.x86 import * from xprint import to_hex diff --git a/bindings/python/test_detail.py b/bindings/python/test_detail.py index 56555871c8..1189433b84 100755 --- a/bindings/python/test_detail.py +++ b/bindings/python/test_detail.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from xprint import to_hex diff --git a/bindings/python/test_evm.py b/bindings/python/test_evm.py index 97838a75a3..500de55a3e 100755 --- a/bindings/python/test_evm.py +++ b/bindings/python/test_evm.py @@ -2,14 +2,10 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * -import sys from xprint import to_hex -_python3 = sys.version_info.major == 3 - EVM_CODE = b"\x60\x61\x50" diff --git a/bindings/python/test_hppa.py b/bindings/python/test_hppa.py index 15e0e6017e..dfbe08fa3d 100755 --- a/bindings/python/test_hppa.py +++ b/bindings/python/test_hppa.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Dmitry Sibirtsev -from __future__ import print_function from capstone import * from capstone.hppa import * from xprint import to_x, to_hex diff --git a/bindings/python/test_iter.py b/bindings/python/test_iter.py index abdac0678a..5a6d8da6be 100755 --- a/bindings/python/test_iter.py +++ b/bindings/python/test_iter.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from xprint import to_hex diff --git a/bindings/python/test_lite.py b/bindings/python/test_lite.py index 1576cb852c..bfb07d9991 100755 --- a/bindings/python/test_lite.py +++ b/bindings/python/test_lite.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from xprint import to_hex diff --git a/bindings/python/test_m680x.py b/bindings/python/test_m680x.py index efe28a3dc3..7f6158eac5 100755 --- a/bindings/python/test_m680x.py +++ b/bindings/python/test_m680x.py @@ -2,11 +2,8 @@ # Capstone Python bindings, by Wolfgang Schwotzer -from __future__ import print_function -import sys from capstone import * from capstone.m680x import * -_python3 = sys.version_info.major == 3 s_access = ( @@ -40,10 +37,7 @@ # print hex dump from string all upper case def to_hex_uc(string): - if _python3: - return " ".join("0x%02x" % c for c in string) - else: - return " ".join("0x%02x" % ord(c) for c in string) + return " ".join("0x%02x" % c for c in string) # print short hex dump from byte array all upper case def to_hex_short_uc(byte_array): diff --git a/bindings/python/test_m68k.py b/bindings/python/test_m68k.py index 2f6b53791e..c6aebb0e54 100755 --- a/bindings/python/test_m68k.py +++ b/bindings/python/test_m68k.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # Capstone Python bindings, by Nicolas PLANEL -from __future__ import print_function from capstone import * from capstone.m68k import * from xprint import to_hex diff --git a/bindings/python/test_mips.py b/bindings/python/test_mips.py index b775ef5d93..f8b14a9e20 100755 --- a/bindings/python/test_mips.py +++ b/bindings/python/test_mips.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.mips import * from xprint import to_hex, to_x diff --git a/bindings/python/test_mos65xx.py b/bindings/python/test_mos65xx.py index 387f1a14cc..f65d481002 100755 --- a/bindings/python/test_mos65xx.py +++ b/bindings/python/test_mos65xx.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # Capstone Python bindings, by Sebastian Macke -from __future__ import print_function from capstone import * from capstone.mos65xx import * from xprint import to_hex, to_x diff --git a/bindings/python/test_ppc.py b/bindings/python/test_ppc.py index deb89d58cf..b3937df6af 100755 --- a/bindings/python/test_ppc.py +++ b/bindings/python/test_ppc.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.ppc import * from xprint import to_hex, to_x, to_x_32 diff --git a/bindings/python/test_riscv.py b/bindings/python/test_riscv.py index 0df298c6f8..575facde42 100755 --- a/bindings/python/test_riscv.py +++ b/bindings/python/test_riscv.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.riscv import * from xprint import to_x, to_hex diff --git a/bindings/python/test_sh.py b/bindings/python/test_sh.py index 1afe31c3eb..b22daee098 100755 --- a/bindings/python/test_sh.py +++ b/bindings/python/test_sh.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Peace-Maker -from __future__ import print_function from capstone import * from capstone.sh import * from xprint import to_x, to_hex diff --git a/bindings/python/test_skipdata.py b/bindings/python/test_skipdata.py index 726a086dda..d46b0c3d01 100755 --- a/bindings/python/test_skipdata.py +++ b/bindings/python/test_skipdata.py @@ -2,9 +2,7 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * -import binascii from xprint import to_hex diff --git a/bindings/python/test_sparc.py b/bindings/python/test_sparc.py index 96fae5bd2b..14a4b800d2 100755 --- a/bindings/python/test_sparc.py +++ b/bindings/python/test_sparc.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.sparc import * from xprint import to_hex, to_x_32 diff --git a/bindings/python/test_systemz.py b/bindings/python/test_systemz.py index ca9deb729b..2048be4d20 100755 --- a/bindings/python/test_systemz.py +++ b/bindings/python/test_systemz.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.systemz import * from xprint import to_x, to_hex diff --git a/bindings/python/test_tms320c64x.py b/bindings/python/test_tms320c64x.py index c2c960ae8d..81ce556ce6 100755 --- a/bindings/python/test_tms320c64x.py +++ b/bindings/python/test_tms320c64x.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Fotis Loukos -from __future__ import print_function from capstone import * from capstone.tms320c64x import * from xprint import to_x, to_hex, to_x_32 diff --git a/bindings/python/test_tricore.py b/bindings/python/test_tricore.py index eace8759a7..29c053e009 100755 --- a/bindings/python/test_tricore.py +++ b/bindings/python/test_tricore.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.tricore import * from xprint import to_hex, to_x diff --git a/bindings/python/test_wasm.py b/bindings/python/test_wasm.py index 2645711320..a6c242308e 100755 --- a/bindings/python/test_wasm.py +++ b/bindings/python/test_wasm.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Peace-Maker -from __future__ import print_function from capstone import * from capstone.wasm import * from xprint import to_hex diff --git a/bindings/python/test_x86.py b/bindings/python/test_x86.py index 3ac5348dab..d4e6e2f790 100755 --- a/bindings/python/test_x86.py +++ b/bindings/python/test_x86.py @@ -1,10 +1,9 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.x86 import * -from xprint import to_hex, to_x, to_x_32 +from xprint import to_hex, to_x X86_CODE64 = b"\x55\x48\x8b\x05\xb8\x13\x00\x00\xe9\xea\xbe\xad\xde\xff\x25\x23\x01\x00\x00\xe8\xdf\xbe\xad\xde\x74\xff" diff --git a/bindings/python/test_xcore.py b/bindings/python/test_xcore.py index 0460a6d419..02298075ca 100755 --- a/bindings/python/test_xcore.py +++ b/bindings/python/test_xcore.py @@ -2,7 +2,6 @@ # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function from capstone import * from capstone.xcore import * from xprint import to_x, to_hex diff --git a/bindings/python/xprint.py b/bindings/python/xprint.py index 70affaca5c..5e31dcf448 100755 --- a/bindings/python/xprint.py +++ b/bindings/python/xprint.py @@ -1,28 +1,15 @@ #!/usr/bin/env python # Capstone Python bindings, by Nguyen Anh Quynnh -from __future__ import print_function -import sys -_python3 = sys.version_info.major == 3 - def to_hex(s, prefix_0x = True): - if _python3: - if prefix_0x: - return " ".join("0x{0:02x}".format(c) for c in s) # <-- Python 3 is OK - else: - return " ".join("{0:02x}".format(c) for c in s) # <-- Python 3 is OK + if prefix_0x: + return " ".join("0x{0:02x}".format(c) for c in s) # <-- Python 3 is OK else: - if prefix_0x: - return " ".join("0x{0:02x}".format(ord(c)) for c in s) - else: - return " ".join("{0:02x}".format(ord(c)) for c in s) + return " ".join("{0:02x}".format(c) for c in s) # <-- Python 3 is OK def to_hex2(s): - if _python3: - r = "".join("{0:02x}".format(c) for c in s) # <-- Python 3 is OK - else: - r = "".join("{0:02x}".format(ord(c)) for c in s) + r = "".join("{0:02x}".format(c) for c in s) # <-- Python 3 is OK while r[0] == '0': r = r[1:] return r From edd94de4ee34b39fd4682cf7812ddacd37d8fc66 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Sat, 1 Jun 2024 14:25:58 -0700 Subject: [PATCH 2/3] Remove python2 references from BUILDING.txt --- bindings/python/BUILDING.txt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/bindings/python/BUILDING.txt b/bindings/python/BUILDING.txt index e527b153eb..8b84b44927 100644 --- a/bindings/python/BUILDING.txt +++ b/bindings/python/BUILDING.txt @@ -6,11 +6,6 @@ $ sudo make install - To install Capstone for Python 3, run the command below: - (Note: this requires python3 installed in your machine) - - $ sudo make install3 - To control the install destination, set the DESTDIR environment variable. 2. For better Python performance, install cython-based binding with: @@ -19,7 +14,7 @@ Note that this requires Cython installed first. To install Cython, see below. - + 3. To install Cython, you have to ensure that the header files and the static library for Python are installed beforehand. @@ -38,13 +33,13 @@ install the required Cython version using your repository. E.g. on Ubuntu, do: - + $ sudo apt-get install cython However, our cython-based binding requires Cython version 0.19 or newer, but sometimes distributions only provide older version. Make sure to verify the current installed version before going into section 2 above. - + E.g, on Ubuntu, you can verify the current Cython version with: $ apt-cache policy cython From 1dcb76c27fe11dcacbd37aa728bdf09d0962d8b2 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Sun, 2 Jun 2024 00:36:37 -0700 Subject: [PATCH 3/3] Remove some leftover install3 references --- .github/workflows/CITest.yml | 4 ++-- bindings/python/Makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index c8fd87c663..261948d69b 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -139,7 +139,7 @@ jobs: run: | cp libcapstone.* bindings/python/prebuilt cd bindings/python - make install3 + make install cd .. BUILD_TESTS=no make tests @@ -147,7 +147,7 @@ jobs: run: | pip install cython cd bindings/python - make install3_cython + make install_cython cd .. python -c "import capstone;print(capstone.debug())" | grep Cython BUILD_TESTS=no make tests diff --git a/bindings/python/Makefile b/bindings/python/Makefile index ea271c0533..4fc8b8f49e 100644 --- a/bindings/python/Makefile +++ b/bindings/python/Makefile @@ -1,6 +1,6 @@ PYTHON3 ?= python3 -.PHONY: gen_const install install3 install_cython sdist sdist3 bdist bdist3 clean check +.PHONY: gen_const install install_cython sdist bdist clean check gen_const: cd .. && $(PYTHON3) const_generator.py python