Commit d6e09d49 by devttys0

Fixed Python3 bugs in lzmavalid and zlibextract plugins

parent 2e4a21ec
import lzma
import binwalk.core.plugin
import binwalk.core.compat
from binwalk.core.common import BlockFile
class LZMAPlugin(binwalk.core.plugin.Plugin):
......@@ -18,14 +19,17 @@ class LZMAPlugin(binwalk.core.plugin.Plugin):
def is_valid_lzma(self, data):
valid = True
# The only acceptable exception is that of IOError "unknown BUF error",
# which indicates that the input data was truncated.
# The only acceptable exceptions are those indicating that the input data was truncated.
try:
d = lzma.decompress(data)
lzma.decompress(binwalk.core.compat.str2bytes(data))
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
except Exception as e:
# 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
......
import os
import zlib
import binwalk.core.compat
import binwalk.core.common
import binwalk.core.plugin
......@@ -25,12 +26,12 @@ class ZLIBExtractPlugin(binwalk.core.plugin.Plugin):
fpin = binwalk.core.common.BlockFile(fname)
fpout = binwalk.core.common.BlockFile(outfile, 'w')
plaintext = zlib.decompress(fpin.read())
plaintext = zlib.decompress(binwalk.core.compat.str2bytes(fpin.read()))
fpout.write(plaintext)
fpin.close()
fpout.close()
except Exception, e:
except Exception as e:
return False
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