From: Hilko Bengen Date: Wed, 25 Jul 2018 15:14:07 +0200 Subject: Remove magic for loading shared libraries --- bindings/python/capstone/__init__.py | 61 +----------------------------------- 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 82164c7..4304555 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -349,67 +349,8 @@ CS_OPT = {v:k for k,v in locals().items() if k.startswith('CS_OPT_')} import ctypes, ctypes.util from os.path import split, join, dirname import sysconfig -from pathlib import PurePath - -import inspect - -if sys.version_info >= (3, 9): - import importlib.resources as resources -else: - import importlib_resources as resources - -if not hasattr(sys.modules[__name__], '__file__'): - __file__ = inspect.getfile(inspect.currentframe()) - -mode = 0 -if sys.platform == 'darwin': - _lib = "libcapstone.dylib" -elif sys.platform in ('win32', 'cygwin'): - _lib = "capstone.dll" -else: - _lib = "libcapstone.so" - mode = getattr(os, 'RTLD_DEEPBIND', 0) - -_found = False - -def _load_lib(path): - lib_file = join(path, _lib) - if os.path.exists(lib_file): - return ctypes.CDLL(lib_file, mode=mode) - else: - # if we're on linux, try again with .so.5 extension - if lib_file.endswith('.so'): - if os.path.exists(lib_file + '.{}'.format(CS_VERSION_MAJOR)): - return ctypes.CDLL( - lib_file + '.{}'.format(CS_VERSION_MAJOR), - mode=mode - ) - return None - -_cs = None - -# Loading attempts, in order -# - user-provided environment variable -# - importlib.resources can get us the path to the local libraries -# - we can get the path to the local libraries by parsing our filename -# - global load -# - python's lib directory -# - last-gasp attempt at some hardcoded paths on darwin and linux - -_path_list = [os.getenv('LIBCAPSTONE_PATH', None), - str(resources.files(__name__) / "lib"), - join(split(__file__)[0], 'lib'), - '', - sysconfig.get_path('platlib'), - "/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64'] - -for _path in _path_list: - if _path is None: continue - _cs = _load_lib(_path) - if _cs is not None: break -else: - raise ImportError("ERROR: fail to load the dynamic library.") +_cs = ctypes.cdll.LoadLibrary("libcapstone.so.5") # low-level structure for C code