Commit d19ff934 by devttys0

Added verbose output to preceed scans.

parent 6161bcf6
...@@ -30,9 +30,12 @@ def cleanup_module_directory(): ...@@ -30,9 +30,12 @@ def cleanup_module_directory():
remove_tree(path + os.path.sep + "*") remove_tree(path + os.path.sep + "*")
except OSError as e: except OSError as e:
pass pass
except ImportError: except KeyboardInterrupt as e:
raise e
except Exception:
pass pass
# Change to the binwalk src directory # Change to the binwalk src directory
def warning(lines, terminate=True, prompt=True): def warning(lines, terminate=True, prompt=True):
WIDTH = 115 WIDTH = 115
......
import sys import sys
import csv as pycsv import csv as pycsv
import datetime
import binwalk.core.common
from binwalk.core.compat import *
class Display(object): class Display(object):
...@@ -15,6 +18,8 @@ class Display(object): ...@@ -15,6 +18,8 @@ class Display(object):
self.fp = None self.fp = None
self.csv = None self.csv = None
self.num_columns = 0 self.num_columns = 0
self.custom_verbose_format = ""
self.custom_verbose_args = []
self._configure_formatting() self._configure_formatting()
...@@ -37,8 +42,33 @@ class Display(object): ...@@ -37,8 +42,33 @@ class Display(object):
else: else:
self.fp.write(fmt % tuple(columns)) self.fp.write(fmt % tuple(columns))
def header(self, *args): def add_custom_header(self, fmt, args):
self.custom_verbose_format = fmt
self.custom_verbose_args = args
def header(self, *args, **kwargs):
file_name = None
self.num_columns = len(args) self.num_columns = len(args)
if has_key(kwargs, 'file_name'):
file_name = kwargs['file_name']
if self.verbose and file_name:
md5sum = binwalk.core.common.file_md5(file_name)
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if self.csv:
self.log("", ["FILE", "MD5SUM", "TIMESTAMP"])
self.log("", [file_name, md5sum, timestamp])
self._fprint("%s", "\n", csv=False)
self._fprint("Scan Time: %s\n", [timestamp], csv=False)
self._fprint("Target File: %s\n", [file_name], csv=False)
self._fprint("MD5 Checksum: %s\n", [md5sum], csv=False)
if self.custom_verbose_format and self.custom_verbose_args:
#self._pprint("Signatures: %d\n" % self.binwalk.parser.signature_count, nolog=nolog)
self._fprint(self.custom_verbose_format, self.custom_verbose_args, csv=False)
self._fprint("%s", "\n", csv=False) self._fprint("%s", "\n", csv=False)
self._fprint(self.header_format, args) self._fprint(self.header_format, args)
self._fprint("%s", ["-" * self.HEADER_WIDTH + "\n"], csv=False) self._fprint("%s", ["-" * self.HEADER_WIDTH + "\n"], csv=False)
...@@ -59,14 +89,15 @@ class Display(object): ...@@ -59,14 +89,15 @@ class Display(object):
def footer(self): def footer(self):
self._fprint("%s", "\n", csv=False) self._fprint("%s", "\n", csv=False)
def _fprint(self, fmt, columns, csv=True): def _fprint(self, fmt, columns, csv=True, stdout=True):
if not self.quiet: line = fmt % tuple(columns)
line = fmt % tuple(columns)
if filter and self.filter.valid_result(line): if filter and self.filter.valid_result(line):
if not self.quiet and stdout:
sys.stdout.write(self._format_line(line.strip()) + "\n") sys.stdout.write(self._format_line(line.strip()) + "\n")
if self.fp and not (self.csv and not csv): if self.fp and not (self.csv and not csv):
self.log(fmt, columns) self.log(fmt, columns)
def _append_to_data_parts(self, data, start, end): def _append_to_data_parts(self, data, start, end):
''' '''
......
...@@ -165,6 +165,9 @@ class Module(object): ...@@ -165,6 +165,9 @@ class Module(object):
#RESULT = ['offset', 'description'] #RESULT = ['offset', 'description']
RESULT = ["offset", "offset", "description"] RESULT = ["offset", "offset", "description"]
VERBOSE_HEADER_FORMAT = ""
VERBOSE_HEADER_ARGS = []
# If set to True, the progress status will be automatically updated for each result # If set to True, the progress status will be automatically updated for each result
# containing a valid file attribute. # containing a valid file attribute.
AUTO_UPDATE_STATUS = True AUTO_UPDATE_STATUS = True
...@@ -184,6 +187,7 @@ class Module(object): ...@@ -184,6 +187,7 @@ class Module(object):
self.target_file_list = [] self.target_file_list = []
self.status = None self.status = None
self.enabled = False self.enabled = False
self.current_target_file_name = None
self.name = self.__class__.__name__ self.name = self.__class__.__name__
self.plugins = binwalk.core.plugin.Plugins(self) self.plugins = binwalk.core.plugin.Plugins(self)
...@@ -303,7 +307,12 @@ class Module(object): ...@@ -303,7 +307,12 @@ class Module(object):
fp = self.target_file_list.pop(0) fp = self.target_file_list.pop(0)
self.status.clear() self.status.clear()
self.status.total = fp.length self.status.total = fp.length
if fp is not None:
self.current_target_file_name = fp.name
else:
self.current_target_file_name = None
return fp return fp
def clear(self, results=True, errors=True): def clear(self, results=True, errors=True):
...@@ -382,10 +391,12 @@ class Module(object): ...@@ -382,10 +391,12 @@ class Module(object):
def header(self): def header(self):
self.config.display.format_strings(self.HEADER_FORMAT, self.RESULT_FORMAT) self.config.display.format_strings(self.HEADER_FORMAT, self.RESULT_FORMAT)
self.config.display.add_custom_header(self.VERBOSE_HEADER_FORMAT, self.VERBOSE_HEADER_ARGS)
if type(self.HEADER) == type([]): if type(self.HEADER) == type([]):
self.config.display.header(*self.HEADER) self.config.display.header(*self.HEADER, file_name=self.current_target_file_name)
elif self.HEADER: elif self.HEADER:
self.config.display.header(self.HEADER) self.config.display.header(self.HEADER, file_name=self.current_target_file_name)
def footer(self): def footer(self):
self.config.display.footer() self.config.display.footer()
......
...@@ -45,6 +45,8 @@ class Signature(Module): ...@@ -45,6 +45,8 @@ class Signature(Module):
MAGIC_FLAGS = magic.MAGIC_NO_CHECK_TEXT | magic.MAGIC_NO_CHECK_ENCODING | magic.MAGIC_NO_CHECK_APPTYPE | magic.MAGIC_NO_CHECK_TOKENS MAGIC_FLAGS = magic.MAGIC_NO_CHECK_TEXT | magic.MAGIC_NO_CHECK_ENCODING | magic.MAGIC_NO_CHECK_APPTYPE | magic.MAGIC_NO_CHECK_TOKENS
VERBOSE_HEADER_FORMAT = "%s %d"
def init(self): def init(self):
# Create SmartSignature and MagicParser class instances. These are mostly for internal use. # Create SmartSignature and MagicParser class instances. These are mostly for internal use.
self.smart = binwalk.core.smart.SmartSignature(self.config.filter, ignore_smart_signatures=self.dumb_scan) self.smart = binwalk.core.smart.SmartSignature(self.config.filter, ignore_smart_signatures=self.dumb_scan)
...@@ -76,6 +78,8 @@ class Signature(Module): ...@@ -76,6 +78,8 @@ class Signature(Module):
# Once the temporary magic files are loaded into libmagic, we don't need them anymore; delete the temp files # Once the temporary magic files are loaded into libmagic, we don't need them anymore; delete the temp files
self.parser.rm_magic_files() self.parser.rm_magic_files()
self.VERBOSE_HEADER_ARGS = ["Signatures:", self.parser.signature_count]
def validate(self, r): def validate(self, r):
''' '''
Called automatically by self.result. Called automatically by self.result.
......
...@@ -23,7 +23,8 @@ class Plugin(object): ...@@ -23,7 +23,8 @@ class Plugin(object):
# If this result is a zlib signature match, try to decompress the data # If this result is a zlib signature match, try to decompress the data
if self.tinfl and result.file and result.description.lower().startswith('zlib'): if self.tinfl and result.file and result.description.lower().startswith('zlib'):
# Seek to and read the suspected zlib data # Seek to and read the suspected zlib data
fd = BlockFile(result.file.name, offset=result.offset, swap=self.module.config.swap_size) fd = self.module.config.open_file(result.file.name, offset=result.offset)
#BlockFile(result.file.name, offset=result.offset, swap=self.module.config.swap_size)
data = fd.read(self.MAX_DATA_SIZE) data = fd.read(self.MAX_DATA_SIZE)
fd.close() fd.close()
......
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