Commit ecb7b7d6 by devttys0

Updated signature module to not load if lzma is not available

parent 347ac4b0
...@@ -10,7 +10,12 @@ try: ...@@ -10,7 +10,12 @@ try:
except ImportError: except ImportError:
pass pass
from binwalk.modules.signature import Signature # Don't load the signature module if the lzma module can't be found
try:
from binwalk.modules.signature import Signature
except ImportError:
pass
from binwalk.modules.hexdiff import HexDiff from binwalk.modules.hexdiff import HexDiff
from binwalk.modules.general import General from binwalk.modules.general import General
from binwalk.modules.extractor import Extractor from binwalk.modules.extractor import Extractor
......
# Basic signature scan module. This is the default (and primary) feature of binwalk. # Basic signature scan module. This is the default (and primary) feature of binwalk.
# This module does not directly use the lzma module, but some plugins for this module do.
# If the lzma import fails, this module won't be loaded at all.
import lzma
import binwalk.core.magic import binwalk.core.magic
import binwalk.core.smart import binwalk.core.smart
import binwalk.core.parser import binwalk.core.parser
......
import lzma
import binwalk.core.plugin import binwalk.core.plugin
import binwalk.core.compat import binwalk.core.compat
from binwalk.core.common import BlockFile from binwalk.core.common import BlockFile
...@@ -16,12 +15,16 @@ class LZMAPlugin(binwalk.core.plugin.Plugin): ...@@ -16,12 +15,16 @@ class LZMAPlugin(binwalk.core.plugin.Plugin):
# Check up to the first 64KB # Check up to the first 64KB
MAX_DATA_SIZE = 64 * 1024 MAX_DATA_SIZE = 64 * 1024
def init(self):
import lzma
self.decompressor = lzma.decompress
def is_valid_lzma(self, data): def is_valid_lzma(self, data):
valid = True valid = True
# The only acceptable exceptions are those indicating that the input data was truncated. # The only acceptable exceptions are those indicating that the input data was truncated.
try: try:
lzma.decompress(binwalk.core.compat.str2bytes(data)) self.decompressor(binwalk.core.compat.str2bytes(data))
except IOError as e: except IOError as e:
# The Python2 module gives this error on truncated input data. # The Python2 module gives this error on truncated input data.
if str(e) != "unknown BUF error": if str(e) != "unknown BUF error":
......
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