File: 0001-Do-not-install-libunicorn.so-with-Python-module.patch

package info (click to toggle)
unicorn-engine 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 23,812 kB
  • sloc: ansic: 379,830; python: 9,213; sh: 9,011; java: 8,609; ruby: 4,241; pascal: 1,805; haskell: 1,379; xml: 490; cs: 424; makefile: 343; cpp: 298; asm: 64
file content (153 lines) | stat: -rw-r--r-- 5,157 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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')