Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python2 leftovers v2 #2395

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CITest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
run: |
cp libcapstone.* bindings/python/prebuilt
cd bindings/python
make install3
make install
cd ..
BUILD_TESTS=no make tests

Expand All @@ -188,7 +188,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
Expand Down
11 changes: 3 additions & 8 deletions bindings/python/BUILDING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand All @@ -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
Expand Down
29 changes: 1 addition & 28 deletions bindings/python/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
PYTHON2 ?= python2
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

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}"; \
Expand All @@ -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}"; \
Expand All @@ -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

Expand Down
20 changes: 4 additions & 16 deletions bindings/python/capstone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
import os, sys
from platform import system
_python2 = sys.version_info[0] < 3
if _python2:
range = xrange
import os
import sys

__all__ = [
'Cs',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_aarch64.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.aarch64 import *
from xprint import to_hex, to_x, to_x_32
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Dmitry Sibirtsev <sibirtsev_dl@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.alpha import *
from xprint import to_x, to_hex
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.arm import *
from xprint import to_hex, to_x_32
Expand Down
10 changes: 1 addition & 9 deletions bindings/python/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#!/usr/bin/env python3
# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

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"
Expand Down Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_bpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Capstone Python bindings
# BPF tests by david942j <david942j@gmail.com>, 2019

from __future__ import print_function
from capstone import *
from capstone.bpf import *
from xprint import to_hex, to_x, to_x_32
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_customized_mnem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.x86 import *
from xprint import to_hex
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_detail.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
from __future__ import print_function
from capstone import *

from xprint import to_hex
Expand Down
4 changes: 0 additions & 4 deletions bindings/python/test_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

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"

Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_hppa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Dmitry Sibirtsev <sibirtsev_dl@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.hppa import *
from xprint import to_x, to_hex
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_iter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
from __future__ import print_function
from capstone import *
from xprint import to_hex

Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_lite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
from __future__ import print_function
from capstone import *
from xprint import to_hex

Expand Down
8 changes: 1 addition & 7 deletions bindings/python/test_m680x.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

# Capstone Python bindings, by Wolfgang Schwotzer <wolfgang.schwotzer@gmx.net>

from __future__ import print_function
import sys
from capstone import *
from capstone.m680x import *
_python3 = sys.version_info.major == 3


s_access = (
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_m68k.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

# Capstone Python bindings, by Nicolas PLANEL <nplanel@gmail.com>
from __future__ import print_function
from capstone import *
from capstone.m68k import *
from xprint import to_hex
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_mips.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
from __future__ import print_function
from capstone import *
from capstone.mips import *
from xprint import to_hex, to_x
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_mos65xx.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

# Capstone Python bindings, by Sebastian Macke <Sebastian Macke>
from __future__ import print_function
from capstone import *
from capstone.mos65xx import *
from xprint import to_hex, to_x
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_ppc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
from __future__ import print_function
from capstone import *
from capstone.ppc import *
from xprint import to_hex, to_x, to_x_32
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_riscv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.riscv import *
from xprint import to_x, to_hex
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Peace-Maker <peacemakerctf@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.sh import *
from xprint import to_x, to_hex
Expand Down
2 changes: 0 additions & 2 deletions bindings/python/test_skipdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
import binascii
from xprint import to_hex


Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_sparc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.sparc import *
from xprint import to_hex, to_x_32
Expand Down
1 change: 0 additions & 1 deletion bindings/python/test_systemz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>

from __future__ import print_function
from capstone import *
from capstone.systemz import *
from xprint import to_x, to_hex
Expand Down
Loading
Loading