ReFirmLabs / binwalk

Firmware Analysis Tool
MIT License
10.35k stars 1.49k forks source link

Name 'np' is not defined while calculating file entropy. #663

Open erucix opened 7 months ago

erucix commented 7 months ago

Steps to reproduce

Result

----------------------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/binwalk/core/module.py", line 595, in main
    retval = self.run()
             ^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/binwalk/modules/entropy.py", line 136, in run
    self._run()
  File "/usr/lib/python3/dist-packages/binwalk/modules/entropy.py", line 158, in _run
    self.calculate_file_entropy(fp)
  File "/usr/lib/python3/dist-packages/binwalk/modules/entropy.py", line 199, in calculate_file_entropy
    entropy = self.algorithm(data[i:i + block_size])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/binwalk/modules/entropy.py", line 256, in shannon_numpy
    return self._shannon_numpy(bytes2str(data))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/numba/core/dispatcher.py", line 468, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/usr/lib/python3/dist-packages/numba/core/dispatcher.py", line 409, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
NameError: name 'np' is not defined
----------------------------------------------------------------------------------------------------

Device Details Linux user 6.5.0-kali3-amd64 SMP PREEMPT_DYNAMIC Debian 6.5.6-1kali1 (2023-10-09) x86_64 GNU/Linux

Wizardwa commented 5 months ago

Solved this with a chain of events first I installed python3.10.8 from source to be able to install scipy version 1.7.3 pip3.10 install scipy==1.7.3 from that I did pip3.10 install numba-scipy. It return an error: RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf . Check the section C-API incompatibility at the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility for indications on how to solve this problem . which I solved with pip install numpy --upgrade After that got a warning: WARNING: Failed to import matplotlib module, visual entropy graphing will be disabled which I solved with: sudo apt-get install python3-matplotlib