Squiblydoo / debloat

A GUI and CLI tool for removing bloat from executables
BSD 3-Clause "New" or "Revised" License
301 stars 25 forks source link

check_section_compression is expected to return two values, but only returns one #32

Closed gdesmar closed 1 month ago

gdesmar commented 1 month ago

In this specific case, the result_code is missing, which makes process_pe error out. If you are interested by a file that would trigger this situation, this one works for me on debloat 1.5.5.

>>> import os
>>> import pefile
>>> import debloat.processor
>>> file_path = "3644efb050a5e1733ca9dc4f6a32fba33883497c41121cf5a7de4837236690e0"
>>> file_size = os.path.getsize(file_path)
>>> binary = pefile.PE(file_path, fast_load=True)
>>> debloat.processor.process_pe(binary, out_path="/tmp/out_path", last_ditch_processing=False, log_message=print, beginning_file_size=file_size)
Section: .text   Compression Ratio: 242.37%     Size of section: 2.0 KB.
Section: .rdata  Compression Ratio: 100.09%     Size of section: 48.5 MB.
Section: .bss    Compression Ratio: 0.0%        Size of section: 0 bytes.
Section: .rsrc   Compression Ratio: 308.43%     Size of section: 6.0 KB.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../debloat/processor.py", line 557, in process_pe
    result, result_code = check_section_compression(pe, data_to_delete, log_message=log_message)
    ^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable NoneType object
Squiblydoo commented 1 month ago

As always, thanks for the report. This issue should now be fixed in 1.5.6 :https://github.com/Squiblydoo/debloat/blob/8a19f0ea77d8850ee9ecb0c564a3b4b3e0fba71d/src/debloat/processor.py#L400

Please note: 1.5.6 also added an argument to be passed to the process_pe method. 1.5.6 added a function to preserve the authenticode certificate on a binary (when there is one). Please let us know if there are any issues.