ReFirmLabs / binwalk

Firmware Analysis Tool
MIT License
11.28k stars 1.56k forks source link

AttributeError: module 'capstone' has no attribute 'CS_ARCH_ARM64' #688

Closed 1392081456 closed 1 month ago

1392081456 commented 1 month ago

System information:Linux kali 6.10.9-amd64 #1 SMP PREEMPT_DYNAMIC Kali 6.10.9-1kali1 (2024-09-09) x86_64 GNU/Linux python information: 3.12.6

When I run binwalk, it appears: Traceback (most recent call last): File "/usr/bin/binwalk", line 33, in sys.exit(load_entry_point('binwalk==2.4.2', 'console_scripts', 'binwalk')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/bin/binwalk", line 25, in importlib_load_entry_point return next(matches).load() ^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/importlib/metadata/init.py", line 205, in load module = import_module(match.group('module')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in _load_unlocked File "", line 995, in exec_module File "", line 488, in _call_with_frames_removed File "/usr/lib/python3/dist-packages/binwalk/main.py", line 24, in import binwalk.modules File "/usr/lib/python3/dist-packages/binwalk/modules/init.py", line 3, in from binwalk.modules.disasm import Disasm File "/usr/lib/python3/dist-packages/binwalk/modules/disasm.py", line 21, in class Disasm(Module): File "/usr/lib/python3/dist-packages/binwalk/modules/disasm.py", line 60, in Disasm Architecture(type=capstone.CS_ARCH_ARM64, ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'capstone' has no attribute 'CS_ARCH_ARM64'. Did you mean: 'CS_ARCH_ARM'?

I try to update binwalk,but it is the newest. Then I followed the instructions to find the corresponding disasm.py and modify it。I modify the "ARM64" to "ARM", just like: ARCHITECTURES =[ Architecture(type=capstone.CS_ARCH_ARM, mode=capstone.CS_MoDE_ARM, endiannesS=capstone.CS_MODE_BIG_ENDIAN, description="ARM executable code, 32-bit, big endian"), Architecture(type=capstone.CS_ARCH_ARM, mode=capstone.CS_MoDE_ARM, endiannesS=capstone.CS_MODE_LITTLE_ENDIAN, description="ARM executable code, 32-bit, little endian"), Architecture(type=capstone.CS_ARCH_ARM, mode=capstone.CS_MODE_ARM, endianness=capstone.CS_MODE_BIG_ENDIAN, description="ARM executable code, 64-bit, big endian"), Architecture(type=capstone.CS_ARCH_ARM, mode=capstone.CS_MODE_ARM, romendiannesS=capstone.CS_MODE_LITTLE_ENDIAN, Devicesdescription="ARM executable code, 64-bit, little endian"),

binwalk is then ready to run。

I would like to know why this is, and does my modification affect binwalk?

1392081456 commented 1 month ago

Do I need to uninstall it and reinstall it?

devttys0 commented 1 month ago

It looks like this error is due to a change to the Capstone API.

Your patch will only affect CPU opcode detection (--opcodes) for ARM: you won't be able to detect ARM64, and/or ARM32 may be reported as ARM64.

Note that current development efforts are focused on Binwalkv3, which no longer supports the --opcodes argument. As a replacement I recommend the cpu_rec tool, which is much better for identifying raw CPU instructions in a file.

1392081456 commented 1 month ago

Thank you for your reply! The version of capstone I found is (6.0.0a1),which version is more suitable?