| 1 | From: Hilko Bengen <[email protected]> |
| 2 | Date: Wed, 25 Jul 2018 15:14:07 +0200 |
| 3 | Subject: Remove magic for loading shared libraries |
| 4 | |
| 5 | --- |
| 6 | bindings/python/capstone/__init__.py | 61 +----------------------------------- |
| 7 | 1 file changed, 1 insertion(+), 60 deletions(-) |
| 8 | |
| 9 | diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py |
| 10 | index 82164c7..4304555 100755 |
| 11 | --- a/bindings/python/capstone/__init__.py |
| 12 | +++ b/bindings/python/capstone/__init__.py |
| 13 | @@ -349,67 +349,8 @@ CS_OPT = {v:k for k,v in locals().items() if k.startswith('CS_OPT_')} |
| 14 | import ctypes, ctypes.util |
| 15 | from os.path import split, join, dirname |
| 16 | import sysconfig |
| 17 | -from pathlib import PurePath |
| 18 | - |
| 19 | -import inspect |
| 20 | - |
| 21 | -if sys.version_info >= (3, 9): |
| 22 | - import importlib.resources as resources |
| 23 | -else: |
| 24 | - import importlib_resources as resources |
| 25 | - |
| 26 | -if not hasattr(sys.modules[__name__], '__file__'): |
| 27 | - __file__ = inspect.getfile(inspect.currentframe()) |
| 28 | - |
| 29 | -mode = 0 |
| 30 | -if sys.platform == 'darwin': |
| 31 | - _lib = "libcapstone.dylib" |
| 32 | -elif sys.platform in ('win32', 'cygwin'): |
| 33 | - _lib = "capstone.dll" |
| 34 | -else: |
| 35 | - _lib = "libcapstone.so" |
| 36 | - mode = getattr(os, 'RTLD_DEEPBIND', 0) |
| 37 | - |
| 38 | -_found = False |
| 39 | - |
| 40 | -def _load_lib(path): |
| 41 | - lib_file = join(path, _lib) |
| 42 | - if os.path.exists(lib_file): |
| 43 | - return ctypes.CDLL(lib_file, mode=mode) |
| 44 | - else: |
| 45 | - # if we're on linux, try again with .so.5 extension |
| 46 | - if lib_file.endswith('.so'): |
| 47 | - if os.path.exists(lib_file + '.{}'.format(CS_VERSION_MAJOR)): |
| 48 | - return ctypes.CDLL( |
| 49 | - lib_file + '.{}'.format(CS_VERSION_MAJOR), |
| 50 | - mode=mode |
| 51 | - ) |
| 52 | - return None |
| 53 | - |
| 54 | -_cs = None |
| 55 | - |
| 56 | -# Loading attempts, in order |
| 57 | -# - user-provided environment variable |
| 58 | -# - importlib.resources can get us the path to the local libraries |
| 59 | -# - we can get the path to the local libraries by parsing our filename |
| 60 | -# - global load |
| 61 | -# - python's lib directory |
| 62 | -# - last-gasp attempt at some hardcoded paths on darwin and linux |
| 63 | - |
| 64 | -_path_list = [os.getenv('LIBCAPSTONE_PATH', None), |
| 65 | - str(resources.files(__name__) / "lib"), |
| 66 | - join(split(__file__)[0], 'lib'), |
| 67 | - '', |
| 68 | - sysconfig.get_path('platlib'), |
| 69 | - "/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64'] |
| 70 | - |
| 71 | -for _path in _path_list: |
| 72 | - if _path is None: continue |
| 73 | - _cs = _load_lib(_path) |
| 74 | - if _cs is not None: break |
| 75 | -else: |
| 76 | - raise ImportError("ERROR: fail to load the dynamic library.") |
| 77 | |
| 78 | +_cs = ctypes.cdll.LoadLibrary("libcapstone.so.5") |
| 79 | |
| 80 | # low-level structure for C code |
| 81 |