Commit 702f5ec1 by devttys0

Fixed return values of several internal extractors; python-lzma no longer…

Fixed return values of several internal extractors; python-lzma no longer required (but recommended)
parent 2418a0b4
# Base64 index tables
0 string ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/= Standard base64 index table
0 string ACEGIKMOQSUWYBDFHJLNPRTVXZacegikmoqsuwybdfhjlnprtvxz0246813579=+/ SerComm base64 index table
# 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
from binwalk.core.module import Module, Option, Kwarg from binwalk.core.module import Module, Option, Kwarg
......
...@@ -70,4 +70,7 @@ class ArcadyanDeobfuscator(binwalk.core.plugin.Plugin): ...@@ -70,4 +70,7 @@ class ArcadyanDeobfuscator(binwalk.core.plugin.Plugin):
out = binwalk.core.common.BlockFile((os.path.splitext(fname)[0] + '.deobfuscated'), "wb") out = binwalk.core.common.BlockFile((os.path.splitext(fname)[0] + '.deobfuscated'), "wb")
out.write(deobfuscated) out.write(deobfuscated)
out.close() out.close()
return True
else:
return False
...@@ -19,6 +19,7 @@ class CPIOPlugin(binwalk.core.plugin.Plugin): ...@@ -19,6 +19,7 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
cmd=self.extractor) cmd=self.extractor)
def extractor(self, fname): def extractor(self, fname):
result = None
fname = os.path.abspath(fname) fname = os.path.abspath(fname)
out_dir = os.path.join(os.path.dirname(fname), self.CPIO_OUT_DIR) out_dir = os.path.join(os.path.dirname(fname), self.CPIO_OUT_DIR)
...@@ -36,17 +37,22 @@ class CPIOPlugin(binwalk.core.plugin.Plugin): ...@@ -36,17 +37,22 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
return return
try: try:
subprocess.call(['cpio', '-d', '-i', '--no-absolute-filenames'], result = subprocess.call(['cpio', '-d', '-i', '--no-absolute-filenames'],
stdin=fpin, stdin=fpin,
stderr=fperr, stderr=fperr,
stdout=fperr) stdout=fperr)
except OSError: except OSError:
pass result = -1
os.chdir(curdir) os.chdir(curdir)
fpin.close() fpin.close()
fperr.close() fperr.close()
if result == 0:
return True
else:
return False
def pre_scan(self): def pre_scan(self):
# Be sure to re-set this at the beginning of every scan # Be sure to re-set this at the beginning of every scan
self.found_archive = False self.found_archive = False
......
...@@ -3,11 +3,12 @@ import binwalk.core.plugin ...@@ -3,11 +3,12 @@ import binwalk.core.plugin
class LZMAExtractPlugin(binwalk.core.plugin.Plugin): class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
''' '''
Gzip extractor plugin. LZMA extractor plugin.
''' '''
MODULES = ['Signature'] MODULES = ['Signature']
def init(self): def init(self):
try:
import lzma import lzma
self.decompressor = lzma.decompress self.decompressor = lzma.decompress
...@@ -18,6 +19,8 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin): ...@@ -18,6 +19,8 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
regex="^lzma compressed data", regex="^lzma compressed data",
extension="7z", extension="7z",
cmd=self.extractor) cmd=self.extractor)
except ImportError as e:
pass
def extractor(self, fname): def extractor(self, fname):
fname = os.path.abspath(fname) fname = os.path.abspath(fname)
......
...@@ -22,12 +22,6 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin): ...@@ -22,12 +22,6 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
self.original_cmd = rule['cmd'] self.original_cmd = rule['cmd']
rule['cmd'] = self.lzma_cable_extractor rule['cmd'] = self.lzma_cable_extractor
break break
#rules = self.module.extractor.get_rules()
#for i in range(0, len(rules)):
# if rules[i]['regex'] and rules[i]['cmd'] and rules[i]['regex'].match(self.SIGNATURE):
# self.original_cmd = rules[i]['cmd']
# rules[i]['cmd'] = self.lzma_cable_extractor
# break
def lzma_cable_extractor(self, fname): def lzma_cable_extractor(self, fname):
# Try extracting the LZMA file without modification first # Try extracting the LZMA file without modification first
...@@ -59,7 +53,9 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin): ...@@ -59,7 +53,9 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
# Overwrite the original file so that it can be cleaned up if -r was specified # Overwrite the original file so that it can be cleaned up if -r was specified
shutil.move(out_name, fname) shutil.move(out_name, fname)
self.module.extractor.execute(self.original_cmd, fname) result = self.module.extractor.execute(self.original_cmd, fname)
return result
def scan(self, result): def scan(self, result):
# The modified cable modem LZMA headers all have valid dictionary sizes and a properties byte of 0x5D. # The modified cable modem LZMA headers all have valid dictionary sizes and a properties byte of 0x5D.
......
...@@ -16,12 +16,16 @@ class LZMAPlugin(binwalk.core.plugin.Plugin): ...@@ -16,12 +16,16 @@ class LZMAPlugin(binwalk.core.plugin.Plugin):
MAX_DATA_SIZE = 64 * 1024 MAX_DATA_SIZE = 64 * 1024
def init(self): def init(self):
try:
import lzma import lzma
self.decompressor = lzma.decompress self.decompressor = lzma.decompress
except ImportError as e:
self.decompressor = None
def is_valid_lzma(self, data): def is_valid_lzma(self, data):
valid = True valid = True
if self.decompressor is not None:
# 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:
self.decompressor(binwalk.core.compat.str2bytes(data)) self.decompressor(binwalk.core.compat.str2bytes(data))
......
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