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.
# 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
from binwalk.core.module import Module, Option, Kwarg
......
......@@ -70,4 +70,7 @@ class ArcadyanDeobfuscator(binwalk.core.plugin.Plugin):
out = binwalk.core.common.BlockFile((os.path.splitext(fname)[0] + '.deobfuscated'), "wb")
out.write(deobfuscated)
out.close()
return True
else:
return False
......@@ -19,6 +19,7 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
cmd=self.extractor)
def extractor(self, fname):
result = None
fname = os.path.abspath(fname)
out_dir = os.path.join(os.path.dirname(fname), self.CPIO_OUT_DIR)
......@@ -36,17 +37,22 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
return
try:
subprocess.call(['cpio', '-d', '-i', '--no-absolute-filenames'],
result = subprocess.call(['cpio', '-d', '-i', '--no-absolute-filenames'],
stdin=fpin,
stderr=fperr,
stdout=fperr)
except OSError:
pass
result = -1
os.chdir(curdir)
fpin.close()
fperr.close()
if result == 0:
return True
else:
return False
def pre_scan(self):
# Be sure to re-set this at the beginning of every scan
self.found_archive = False
......
......@@ -3,11 +3,12 @@ import binwalk.core.plugin
class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
'''
Gzip extractor plugin.
LZMA extractor plugin.
'''
MODULES = ['Signature']
def init(self):
try:
import lzma
self.decompressor = lzma.decompress
......@@ -18,6 +19,8 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
regex="^lzma compressed data",
extension="7z",
cmd=self.extractor)
except ImportError as e:
pass
def extractor(self, fname):
fname = os.path.abspath(fname)
......
......@@ -22,12 +22,6 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
self.original_cmd = rule['cmd']
rule['cmd'] = self.lzma_cable_extractor
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):
# Try extracting the LZMA file without modification first
......@@ -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
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):
# 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):
MAX_DATA_SIZE = 64 * 1024
def init(self):
try:
import lzma
self.decompressor = lzma.decompress
except ImportError as e:
self.decompressor = None
def is_valid_lzma(self, data):
valid = True
if self.decompressor is not None:
# The only acceptable exceptions are those indicating that the input data was truncated.
try:
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