void-packages/srcpkgs/binwalk/patches/python-3.12.patch

91 lines
3.4 KiB
Diff

--- a/src/binwalk/core/module.py
+++ b/src/binwalk/core/module.py
@@ -688,6 +688,16 @@ class Modules(object):
else:
return '--' + opt
+ @staticmethod
+ def _imp_load_source(name, path):
+ import importlib.util
+ import importlib.machinery
+ loader = importlib.machinery.SourceFileLoader(name, path)
+ spec = importlib.util.spec_from_file_location(name, path, loader=loader)
+ module = importlib.util.module_from_spec(spec)
+ loader.exec_module(module)
+ return module
+
def list(self, attribute="run"):
'''
Finds all modules with the specified attribute.
@@ -704,14 +714,13 @@ class Modules(object):
modules[module] = module.PRIORITY
# user-defined modules
- import imp
user_modules = binwalk.core.settings.Settings().user.modules
for file_name in os.listdir(user_modules):
if not file_name.endswith('.py'):
continue
module_name = file_name[:-3]
try:
- user_module = imp.load_source(module_name, os.path.join(user_modules, file_name))
+ user_module = _imp_load_source(module_name, os.path.join(user_modules, file_name))
except KeyboardInterrupt as e:
raise e
except Exception as e:
--- a/src/binwalk/core/plugin.py
+++ b/src/binwalk/core/plugin.py
@@ -1,7 +1,6 @@
# Core code for supporting and managing plugins.
import os
-import imp
import inspect
import binwalk.core.common
import binwalk.core.settings
@@ -131,6 +130,15 @@ class Plugins(object):
return klass
raise Exception("Failed to locate Plugin class in " + plugin)
+ def _imp_load_source(self, name, path):
+ import importlib.util
+ import importlib.machinery
+ loader = importlib.machinery.SourceFileLoader(name, path)
+ spec = importlib.util.spec_from_file_location(name, path, loader=loader)
+ module = importlib.util.module_from_spec(spec)
+ loader.exec_module(module)
+ return module
+
def list_plugins(self):
'''
Obtain a list of all user and system plugin modules.
@@ -180,7 +188,7 @@ class Plugins(object):
module = file_name[:-len(self.MODULE_EXTENSION)]
try:
- plugin = imp.load_source(module, os.path.join(plugins[key]['path'], file_name))
+ plugin = self._imp_load_source(module, os.path.join(plugins[key]['path'], file_name))
plugin_class = self._find_plugin_class(plugin)
plugins[key]['enabled'][module] = True
@@ -222,7 +230,7 @@ class Plugins(object):
continue
try:
- plugin = imp.load_source(module, file_path)
+ plugin = self._imp_load_source(module, file_path)
plugin_class = self._find_plugin_class(plugin)
class_instance = plugin_class(self.parent)
--- a/src/binwalk/core/magic.py
+++ b/src/binwalk/core/magic.py
@@ -428,7 +428,7 @@ class Magic(object):
# Regex rule to find format strings
self.fmtstr = re.compile("%[^%]")
# Regex rule to find periods (see self._do_math)
- self.period = re.compile("\.")
+ self.period = re.compile(r'\.')
def reset(self):
self.display_once = set()