diff --git a/security/binwalk/files/patch-src_binwalk_core_magic.py b/security/binwalk/files/patch-src_binwalk_core_magic.py new file mode 100644 index 000000000000..82c106df2b72 --- /dev/null +++ b/security/binwalk/files/patch-src_binwalk_core_magic.py @@ -0,0 +1,11 @@ +--- src/binwalk/core/magic.py.orig 2021-09-10 19:46:40.000000000 +0200 ++++ src/binwalk/core/magic.py 2026-08-02 21:33:59.983203000 +0200 +@@ -428,7 +428,7 @@ + # 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() diff --git a/security/binwalk/files/patch-src_binwalk_core_module.py b/security/binwalk/files/patch-src_binwalk_core_module.py new file mode 100644 index 000000000000..abdbf28e3682 --- /dev/null +++ b/security/binwalk/files/patch-src_binwalk_core_module.py @@ -0,0 +1,45 @@ +--- src/binwalk/core/module.py.orig 2021-09-10 19:46:40.000000000 +0200 ++++ src/binwalk/core/module.py 2026-08-02 21:33:59.983754000 +0200 +@@ -704,18 +704,32 @@ + modules[module] = module.PRIORITY + + # user-defined modules +- import imp ++ import importlib.util ++ import sys ++ + 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)) ++ # Creates module specification from file path ++ file_path = os.path.join(user_modules, file_name) ++ spec = importlib.util.spec_from_file_location(module_name, file_path) ++ ++ # Loads the module into memory using the created specification ++ if spec and spec.loader: ++ user_module = importlib.util.module_from_spec(spec) ++ sys.modules[module_name] = user_module ++ spec.loader.exec_module(user_module) ++ else: ++ raise ImportError(f"Não foi possível criar a especificação para {file_name}") ++ + except KeyboardInterrupt as e: + raise e + except Exception as e: + binwalk.core.common.warning("Error loading module '%s': %s" % (file_name, str(e))) ++ continue # Jumps to the next file if it fails + + for (name, module) in inspect.getmembers(user_module): + if inspect.isclass(module) and hasattr(module, attribute): +@@ -723,6 +737,7 @@ + + return sorted(modules, key=modules.get, reverse=True) + ++ + def help(self): + ''' + Generates formatted help output. diff --git a/security/binwalk/files/patch-src_binwalk_core_plugin.py b/security/binwalk/files/patch-src_binwalk_core_plugin.py new file mode 100644 index 000000000000..c308ee2237c9 --- /dev/null +++ b/security/binwalk/files/patch-src_binwalk_core_plugin.py @@ -0,0 +1,83 @@ +--- src/binwalk/core/plugin.py.orig 2021-09-10 19:46:40.000000000 +0200 ++++ src/binwalk/core/plugin.py 2026-08-02 21:33:59.984158000 +0200 +@@ -1,7 +1,7 @@ + # Core code for supporting and managing plugins. + + import os +-import imp ++import importlib + import inspect + import binwalk.core.common + import binwalk.core.settings +@@ -168,6 +168,9 @@ + } + } + ++ import importlib.util ++ import sys ++ + for key in plugins.keys(): + if key == 'user': + plugins[key]['path'] = self.settings.user.plugins +@@ -180,7 +183,18 @@ + module = file_name[:-len(self.MODULE_EXTENSION)] + + try: +- plugin = imp.load_source(module, os.path.join(plugins[key]['path'], file_name)) ++ # Define full module path ++ file_path = os.path.join(plugins[key]['path'], file_name) ++ spec = importlib.util.spec_from_file_location(module, file_path) ++ ++ # Loads the plugin dynamically if the specification is valid ++ if spec and spec.loader: ++ plugin = importlib.util.module_from_spec(spec) ++ sys.modules[module] = plugin ++ spec.loader.exec_module(plugin) ++ else: ++ raise ImportError(f"Não foi possível criar a especificação para {file_name}") ++ + plugin_class = self._find_plugin_class(plugin) + + plugins[key]['enabled'][module] = True +@@ -196,6 +210,7 @@ + except Exception as e: + binwalk.core.common.warning("Error loading plugin '%s': %s" % (file_name, str(e))) + plugins[key]['enabled'][module] = False ++ continue # Skips reading description if plugin failed to load + + try: + plugins[key]['descriptions'][ +@@ -207,12 +222,16 @@ + module] = 'No description' + return plugins + ++ + def load_plugins(self): + plugins = self.list_plugins() + self._load_plugin_modules(plugins['user']) + self._load_plugin_modules(plugins['system']) + + def _load_plugin_modules(self, plugins): ++ import importlib.util ++ import sys ++ + for module in plugins['modules']: + try: + file_path = os.path.join(plugins['path'], module + self.MODULE_EXTENSION) +@@ -222,7 +241,15 @@ + continue + + try: +- plugin = imp.load_source(module, file_path) ++ # Creates the specification and loads the module dynamically ++ spec = importlib.util.spec_from_file_location(module, file_path) ++ if spec and spec.loader: ++ plugin = importlib.util.module_from_spec(spec) ++ sys.modules[module] = plugin ++ spec.loader.exec_module(plugin) ++ else: ++ raise ImportError(f"Não foi possível criar a especificação para {file_path}") ++ + plugin_class = self._find_plugin_class(plugin) + + class_instance = plugin_class(self.parent)