File: Remove-magic-for-loading-shared-libraries.patch

package info (click to toggle)
capstone 5.0.7-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,212 kB
  • sloc: ansic: 96,103; cpp: 67,489; cs: 29,510; python: 25,829; pascal: 24,412; java: 15,582; ml: 14,473; makefile: 1,274; sh: 479; ruby: 386
file content (76 lines) | stat: -rw-r--r-- 2,484 bytes parent folder | download | duplicates (3)
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
From: Hilko Bengen <bengen@debian.org>
Date: Wed, 25 Jul 2018 15:14:07 +0200
Subject: Remove magic for loading shared libraries

---
 bindings/python/capstone/__init__.py | 57 +-----------------------------------
 1 file changed, 1 insertion(+), 56 deletions(-)

diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py
index 6fb2612..82a8dbe 100755
--- a/bindings/python/capstone/__init__.py
+++ b/bindings/python/capstone/__init__.py
@@ -349,62 +349,7 @@ 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())
-
-if sys.platform == 'darwin':
-    _lib = "libcapstone.dylib"
-elif sys.platform in ('win32', 'cygwin'):
-    _lib = "capstone.dll"
-else:
-    _lib = "libcapstone.so"
-
-_found = False
-
-def _load_lib(path):
-    lib_file = join(path, _lib)
-    if os.path.exists(lib_file):
-        return ctypes.cdll.LoadLibrary(lib_file)
-    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.LoadLibrary(lib_file + '.{}'.format(CS_VERSION_MAJOR))
-    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