From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Sun, 10 Apr 2022 23:16:05 +0200
Subject: Do not install libunicorn.so with Python module

Forwarded: not-needed
---
 bindings/python/unicorn/unicorn_py2.py         | 30 +--------
 bindings/python/unicorn/unicorn_py3/unicorn.py | 91 +-------------------------
 2 files changed, 2 insertions(+), 119 deletions(-)

diff --git a/bindings/python/unicorn/unicorn_py2.py b/bindings/python/unicorn/unicorn_py2.py
index 0b9f560..18be54b 100644
--- a/bindings/python/unicorn/unicorn_py2.py
+++ b/bindings/python/unicorn/unicorn_py2.py
@@ -73,35 +73,7 @@ def _load_lib(path):
         # print('FAIL to load %s' %lib_file, e)
         return None
 
-
-_uc = None
-
-# Loading attempts, in order
-# - user-provided environment variable
-# - pkg_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('LIBUNICORN_PATH', None),
-              pkg_resources.resource_filename(__name__, 'lib'),
-              os.path.join(os.path.split(__file__)[0], 'lib'),
-              '',
-              distutils.sysconfig.get_python_lib(),
-              "/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64',
-              os.getenv('PATH', '')]
-
-# print(_path_list)
-# print("-" * 80)
-
-for _path in _path_list:
-    if _path is None: continue
-    _uc = _load_lib(_path)
-    if _uc is not None: break
-else:
-    raise ImportError("ERROR: fail to load the dynamic library.")
-
+_uc = ctypes.cdll.LoadLibrary("libunicorn.so.2")
 
 # __version__ = "%u.%u.%u" % (uc.UC_VERSION_MAJOR, uc.UC_VERSION_MINOR, uc.UC_VERSION_EXTRA)
 
diff --git a/bindings/python/unicorn/unicorn_py3/unicorn.py b/bindings/python/unicorn/unicorn_py3/unicorn.py
index 6f50eab..fac9b41 100644
--- a/bindings/python/unicorn/unicorn_py3/unicorn.py
+++ b/bindings/python/unicorn/unicorn_py3/unicorn.py
@@ -62,96 +62,7 @@ class uc_tlb_entry(UcTupledStruct[TLBEntryStruct]):
 
 
 def __load_uc_lib() -> ctypes.CDLL:
-    from pathlib import Path, PurePath
-
-    import inspect
-    import os
-    import sys
-
-    loaded_dlls = set()
-
-    def __load_win_support(path: Path) -> None:
-        # Windows DLL in dependency order
-        all_dlls = (
-            'libwinpthread-1.dll',
-            'libgcc_s_seh-1.dll',
-            'libgcc_s_dw2-1.dll'
-        )
-
-        for dllname in all_dlls:
-            if dllname not in loaded_dlls:
-                lib_file = path / dllname
-
-                if str(path.parent) == '.' or lib_file.exists():
-                    try:
-                        ctypes.cdll.LoadLibrary(str(lib_file))
-                    except OSError:
-                        continue
-                    else:
-                        loaded_dlls.add(dllname)
-
-    platform = sys.platform
-
-    # Initial attempt: load all dlls globally
-    if platform in ('win32', 'cygwin'):
-        __load_win_support(Path())
-
-    def _load_lib(path: Path, lib_name: str):
-        if platform in ('win32', 'cygwin'):
-            __load_win_support(path)
-
-        lib_file = path / lib_name
-
-        try:
-            return ctypes.cdll.LoadLibrary(str(lib_file))
-        except OSError:
-            return None
-
-    # Loading attempts, in order
-    # - user-provided environment variable
-    # - importlib.resources/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
-
-    if sys.version_info >= (3, 9):
-        import importlib.resources as resources
-    else:
-        import importlib_resources as resources
-
-    canonicals = resources.files('unicorn') / 'lib'
-
-    lib_locations = [
-        os.getenv('LIBUNICORN_PATH'),
-        canonicals,
-        PurePath(inspect.getfile(__load_uc_lib)).parent / 'lib',
-        '',
-        r'/usr/local/lib' if sys.platform == 'darwin' else r'/usr/lib64',
-    ] + [PurePath(p) / 'unicorn' / 'lib' for p in sys.path]
-
-    # filter out None elements
-    lib_locations = tuple(Path(loc) for loc in lib_locations if loc is not None)
-
-    lib_name = {
-        'cygwin': 'cygunicorn.dll',
-        'darwin': 'libunicorn.2.dylib',
-        'linux':  'libunicorn.so.2',
-        'linux2': 'libunicorn.so.2',
-        'win32':  'unicorn.dll'
-    }.get(platform, "libunicorn.so")
-
-    def __attempt_load(libname: str):
-        T = TypeVar('T')
-
-        def __pick_first_valid(it: Iterable[T]) -> Optional[T]:
-            """Iterate till encountering a non-None element and return it.
-            """
-
-            return next((elem for elem in it if elem is not None), None)
-
-        return __pick_first_valid(_load_lib(loc, libname) for loc in lib_locations)
-
-    lib = __attempt_load(lib_name) or __attempt_load('libunicorn.so')
+    lib = ctypes.cdll.LoadLibrary("libunicorn.so.2")
 
     if lib is None:
         raise ImportError('Failed to load the Unicorn dynamic library')
