Commit d6e09d49 by devttys0

Fixed Python3 bugs in lzmavalid and zlibextract plugins

parent 2e4a21ec
import lzma import lzma
import binwalk.core.plugin import binwalk.core.plugin
import binwalk.core.compat
from binwalk.core.common import BlockFile from binwalk.core.common import BlockFile
class LZMAPlugin(binwalk.core.plugin.Plugin): class LZMAPlugin(binwalk.core.plugin.Plugin):
...@@ -18,15 +19,18 @@ class LZMAPlugin(binwalk.core.plugin.Plugin): ...@@ -18,15 +19,18 @@ class LZMAPlugin(binwalk.core.plugin.Plugin):
def is_valid_lzma(self, data): def is_valid_lzma(self, data):
valid = True valid = True
# The only acceptable exception is that of IOError "unknown BUF error", # The only acceptable exceptions are those indicating that the input data was truncated.
# which indicates that the input data was truncated.
try: try:
d = lzma.decompress(data) lzma.decompress(binwalk.core.compat.str2bytes(data))
except IOError as e: except IOError as e:
if e.message != "unknown BUF error": # The Python2 module gives this error on truncated input data.
if str(e) != "unknown BUF error":
valid = False valid = False
except Exception as e: except Exception as e:
valid = False # The Python3 module gives this error on truncated input data.
# The inconsistency between modules is a bit worrisome.
if str(e) != "Compressed data ended before the end-of-stream marker was reached":
valid = False
return valid return valid
......
import os import os
import zlib import zlib
import binwalk.core.compat
import binwalk.core.common import binwalk.core.common
import binwalk.core.plugin import binwalk.core.plugin
...@@ -25,12 +26,12 @@ class ZLIBExtractPlugin(binwalk.core.plugin.Plugin): ...@@ -25,12 +26,12 @@ class ZLIBExtractPlugin(binwalk.core.plugin.Plugin):
fpin = binwalk.core.common.BlockFile(fname) fpin = binwalk.core.common.BlockFile(fname)
fpout = binwalk.core.common.BlockFile(outfile, 'w') fpout = binwalk.core.common.BlockFile(outfile, 'w')
plaintext = zlib.decompress(fpin.read()) plaintext = zlib.decompress(binwalk.core.compat.str2bytes(fpin.read()))
fpout.write(plaintext) fpout.write(plaintext)
fpin.close() fpin.close()
fpout.close() fpout.close()
except Exception, e: except Exception as e:
return False return False
return True return True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment