On 2025/03/05 19:55, Mikolaj Kucharski wrote:
> Hi,
> 
> Wanted to test how Binwalk works and it failed on a fresh install:
> 
> OpenBSD 7.7-beta (GENERIC.MP) #577: Sun Mar  2 23:34:56 MST 2025
>     dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> 
> $ pkg_info -qI binwalk
> binwalk-2.3.4p2
> 
> $ touch empty.txt
> $ binwalk empty.txt
> Traceback (most recent call last):
>   File "/usr/local/bin/binwalk", line 2, in <module>
>     from binwalk.__main__ import main
>   File "/usr/local/lib/python3.12/site-packages/binwalk/__init__.py", line 3, 
> in <module>
>     from binwalk.core.module import Modules
>   File "/usr/local/lib/python3.12/site-packages/binwalk/core/module.py", line 
> 18, in <module>
>     import binwalk.core.plugin
>   File "/usr/local/lib/python3.12/site-packages/binwalk/core/plugin.py", line 
> 4, in <module>
>     import imp
> ModuleNotFoundError: No module named 'imp'

imp was removed in py312.

this should fix it (basic usage seems ok, I haven't done anything with
plugins).

alternatively binwalk 3.x is a rewrite in rust

Index: Makefile
===================================================================
RCS file: /cvs/ports/sysutils/binwalk/Makefile,v
diff -u -p -r1.27 Makefile
--- Makefile    21 Dec 2024 11:38:51 -0000      1.27
+++ Makefile    6 Mar 2025 11:02:05 -0000
@@ -4,7 +4,7 @@ MODPY_DISTV =   2.3.4
 GH_ACCOUNT =   ReFirmLabs
 GH_PROJECT =   binwalk
 GH_TAGNAME =   v${MODPY_DISTV}
-REVISION =     2
+REVISION =     3
 
 CATEGORIES =   sysutils
 
Index: patches/patch-src_binwalk_core_module_py
===================================================================
RCS file: patches/patch-src_binwalk_core_module_py
diff -N patches/patch-src_binwalk_core_module_py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_binwalk_core_module_py    6 Mar 2025 11:02:05 -0000
@@ -0,0 +1,24 @@
+py312 doesn't have imp
+
+Index: src/binwalk/core/module.py
+--- src/binwalk/core/module.py.orig
++++ src/binwalk/core/module.py
+@@ -704,14 +704,16 @@ class Modules(object):
+                 modules[module] = module.PRIORITY
+ 
+         # user-defined modules
+-        import imp
++        import importlib.util
+         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))
++                spec = importlib.util.spec_from_file_location(module_name, 
os.path.join(user_modules, file_name))
++                user_module = importlib.util.module_from_spec(spec)
++                spec.loader.exec_module(user_module)
+             except KeyboardInterrupt as e:
+                 raise e
+             except Exception as e:
Index: patches/patch-src_binwalk_core_plugin_py
===================================================================
RCS file: patches/patch-src_binwalk_core_plugin_py
diff -N patches/patch-src_binwalk_core_plugin_py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_binwalk_core_plugin_py    6 Mar 2025 11:02:05 -0000
@@ -0,0 +1,36 @@
+py312 doesn't have imp
+
+Index: src/binwalk/core/plugin.py
+--- src/binwalk/core/plugin.py.orig
++++ src/binwalk/core/plugin.py
+@@ -1,7 +1,7 @@
+ # Core code for supporting and managing plugins.
+ 
+ import os
+-import imp
++import importlib.util
+ import inspect
+ import binwalk.core.common
+ import binwalk.core.settings
+@@ -180,7 +180,9 @@ class Plugins(object):
+                         module = file_name[:-len(self.MODULE_EXTENSION)]
+ 
+                         try:
+-                            plugin = imp.load_source(module, 
os.path.join(plugins[key]['path'], file_name))
++                            spec = 
importlib.util.spec_from_file_location(module, 
os.path.join(plugins[key]['path'], file_name))
++                            plugin = importlib.util.module_from_spec(spec)
++                            spec.loader.exec_module(plugin)
+                             plugin_class = self._find_plugin_class(plugin)
+ 
+                             plugins[key]['enabled'][module] = True
+@@ -222,7 +224,9 @@ class Plugins(object):
+                 continue
+ 
+             try:
+-                plugin = imp.load_source(module, file_path)
++                spec = importlib.util.spec_from_file_location(module, 
file_path)
++                plugin = importlib.util.module_from_spec(spec)
++                spec.loader.exec_module(plugin)
+                 plugin_class = self._find_plugin_class(plugin)
+ 
+                 class_instance = plugin_class(self.parent)

Reply via email to