Commit ddad9c6d by devttys0

Initial module framework in place; replaced prettyprint.py with display.py.

parent f856cd77
import sys
import csv as pycsv
import binwalk.common
class Display(object):
BUFFER_WIDTH = 32
HEADER_WIDTH = 115
MAX_LINE_LEN = 0
DEFAULT_FORMAT = "%s\n"
def __init__(self, quiet=False, verbose=0, log=None, csv=False, fit_to_screen=False):
self.quiet = quiet
self.verbose = verbose
self.fit_to_screen = fit_to_screen
self.fp = None
self.csv = None
self._configure_formatting()
if log:
self.fp = binwalk.common.BlockFile(log, mode="w")
if self.csv:
self.csv = pycsv.writer(self.fp)
def format_strings(self, header, result):
self.result_format = result
self.header_format = header
def log(self, fmt, columns):
if self.fp:
if self.csv:
self.csv.writerow(columns)
else:
self.fp.write(fmt % tuple(columns))
def header(self, *args):
self._fprint(self.header_format, args)
self._fprint("%s", ["-" * self.HEADER_WIDTH + "\n"], csv=False)
def result(self, *args):
self._fprint(self.result_format, args)
def footer(self):
self._fprint("%s", "\n", csv=False)
def _fprint(self, fmt, columns, csv=True):
if not self.quiet:
sys.stdout.write(fmt % tuple(columns))
if not (self.csv and not csv):
self.log(fmt, columns)
def _append_to_data_parts(self, data, start, end):
'''
Intelligently appends data to self.string_parts.
For use by self._format.
'''
try:
while data[start] == ' ':
start += 1
if start == end:
end = len(data[start:])
self.string_parts.append(data[start:end])
except:
try:
self.string_parts.append(data[start:])
except:
pass
return start
def _format_line(self, line):
'''
Formats a line of text to fit in the terminal window.
For Tim.
'''
offset = 0
space_offset = 0
self.string_parts = []
delim = '\n' + ' ' * self.BUFFER_WIDTH
if self.fit_to_screen:
while len(line[offset:]) > self.MAX_LINE_LEN:
space_offset = line[offset:offset+self.MAX_LINE_LEN].rfind(' ')
if space_offset == -1 or space_offset == 0:
space_offset = self.MAX_LINE_LEN
self._append_to_data_parts(line, offset, offset+space_offset)
offset += space_offset
self._append_to_data_parts(line, offset, offset+len(data[offset:]))
return delim.join(self.string_parts)
def _configure_formatting(self):
'''
Configures output formatting, and fitting output to the current terminal width.
Returns None.
'''
self.format_strings(self.DEFAULT_FORMAT, self.DEFAULT_FORMAT)
if self.fit_to_screen:
try:
import fcntl
import struct
import termios
# Get the terminal window width
hw = struct.unpack('hh', fcntl.ioctl(1, termios.TIOCGWINSZ, '1234'))
self.HEADER_WIDTH = hw[1]
except Exception as e:
pass
self.MAX_LINE_LEN = self.HEADER_WIDTH - self.BUFFER_WIDTH
import io
import sys
import argparse
import binwalk.common
from binwalk.compat import *
class ModuleOption(object):
def __init__(self, kwargs={}, nargs=0, priority=0, description="", short="", long="", type=str):
'''
Class constructor.
@kwargs - A dictionary of kwarg key-value pairs affected by this command line option.
@nargs - The number of arguments this option accepts (only 1 or 0 is currently supported).
@priority - A value from 0 to 100. Higher priorities will override kwarg values set by lower priority options.
@description - A description to be displayed in the help output.
@short - The short option to use (optional).
@long - The long option to use (if None, this option will not be displayed in help output).
@type - The accepted data type (one of: io.FileIO/argparse.FileType/binwalk.common.BlockFile, list, str, int, float).
'''
self.kwargs = kwargs
self.nargs = nargs
self.priority = priority
self.description = description
self.short = short
self.long = long
self.type = type
class ModuleKwarg(object):
def __init__(self, name="", default=None, description=""):
'''
Class constructor.
@name - Kwarg name.
@default - Default kwarg value.
@description - Description string.
Return None.
'''
self.name = name
self.default = default
self.description = description
def list_modules():
pass
def process_argv(module, config=None, argv=sys.argv[1:]):
'''
Processes argv for any options specific to the specified module.
@module - The module to process argv for.
@config - An instance of the binwalk.modules.configuration.Configuration class.
@argv - A list of command line arguments (excluding argv[0]).
Returns a dictionary of kwargs for the specified module.
'''
kwargs = {}
last_priority = {}
longs = []
shorts = ""
parser = argparse.ArgumentParser(add_help=False)
if hasattr(module, "CLI"):
for module_option in module.CLI:
if not module_option.long:
continue
if module_option.nargs == 0:
action = 'store_true'
else:
action = None
if module_option.short:
parser.add_argument('-' + module_option.short, '--' + module_option.long, action=action, dest=module_option.long)
else:
parser.add_argument('--' + module_option.long, action=action, dest=module_option.long)
args, unknown = parser.parse_known_args(argv)
args = args.__dict__
for module_option in module.CLI:
if module_option.type in [io.FileIO, argparse.FileType, binwalk.common.BlockFile]:
for k in get_keys(module_option.kwargs):
kwargs[k] = []
for unk in unknown:
if not unk.startswith('-'):
kwargs[k].append(unk)
elif has_key(args, module_option.long) and args[module_option.long] not in [None, False]:
i = 0
for (name, value) in iterator(module_option.kwargs):
if not has_key(last_priority, name) or last_priority[name] <= module_option.priority:
if module_option.nargs > i:
value = args[module_option.long]
i += 1
last_priority[name] = module_option.priority
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values
if module_option.type == int:
kwargs[name] = int(kwargs[name], 0)
elif module_option.type == float:
kwargs[name] = float(kwargs[name])
elif module_option.type == dict:
if not has_key(kwargs, name):
kwargs[name] = {}
kwargs[name][len(kwargs[name])] = value
elif module_option.type == list:
if not has_key(kwargs, name):
kwargs[name] = []
kwargs[name].append(value)
else:
kwargs[name] = value
else:
raise Exception("binwalk.module.process_argv: %s has no attribute 'CLI'" % str(module))
if config is not None and not has_key(kwargs, 'config'):
kwargs['config'] = config
return kwargs
def process_kwargs(module, kwargs):
'''
Processes a module's kwargs. All modules should use this for kwarg processing.
@module - An instance of the module (e.g., self)
@kwargs - The kwargs passed to the module
Returns None.
'''
if hasattr(module, "KWARGS"):
for module_argument in module.KWARGS:
if has_key(kwargs, module_argument.name):
arg_value = kwargs[module_argument.name]
else:
arg_value = module_argument.default
setattr(module, module_argument.name, arg_value)
if has_key(kwargs, 'config'):
setattr(module, 'config', kwargs['config'])
else:
raise Exception("binwalk.module.parse_module_kwargs: %s has no attribute 'KWARGS'" % str(module))
import os
import sys
import binwalk.common
import binwalk.module
import binwalk.display
class Configuration(object):
CLI = [
binwalk.module.ModuleOption(long='length',
short='l',
nargs=1,
type=int,
kwargs={'length' : 0},
description='Number of bytes to scan'),
binwalk.module.ModuleOption(long='offset',
short='o',
nargs=1,
type=int,
kwargs={'offset' : 0},
description='Start scan at this file offset'),
binwalk.module.ModuleOption(long='grep',
short='g',
nargs=1,
kwargs={'grep' : []},
type=list,
description='Grep results for the specified text'),
binwalk.module.ModuleOption(long='log',
short='f',
nargs=1,
kwargs={'log_file' : None},
description='Log results to file'),
binwalk.module.ModuleOption(long='csv',
short='c',
kwargs={'csv' : True},
description='Log results to file in CSV format'),
binwalk.module.ModuleOption(long='skip-unopened',
short='O',
kwargs={'skip_unopened' : True},
description='Ignore file open errors and process only the files that can be opened'),
binwalk.module.ModuleOption(long='term',
short='t',
kwargs={'format_to_terminal' : True},
description='Format output to fit the terminal window'),
binwalk.module.ModuleOption(long='quiet',
short='q',
kwargs={'quiet' : True},
description='Supress output to stdout'),
binwalk.module.ModuleOption(long='verbose',
short='v',
type=list,
kwargs={'verbose' : True},
description='Enable verbose output (specify twice for more verbosity)'),
binwalk.module.ModuleOption(long=None,
short=None,
type=binwalk.common.BlockFile,
kwargs={'target_files' : []}),
]
KWARGS = [
binwalk.module.ModuleKwarg(name='length', default=None),
binwalk.module.ModuleKwarg(name='offset', default=None),
binwalk.module.ModuleKwarg(name='log_file', default=None),
binwalk.module.ModuleKwarg(name='csv', default=False),
binwalk.module.ModuleKwarg(name='format_to_terminal', default=False),
binwalk.module.ModuleKwarg(name='grep', default=[]),
binwalk.module.ModuleKwarg(name='quiet', default=False),
binwalk.module.ModuleKwarg(name='verbose', default=[]),
binwalk.module.ModuleKwarg(name='debug_verbose', default=False),
binwalk.module.ModuleKwarg(name='skip_unopened', default=False),
binwalk.module.ModuleKwarg(name='target_files', default=[]),
]
def __init__(self, **kwargs):
binwalk.module.process_kwargs(self, kwargs)
self._test_target_files()
self._set_verbosity()
self.display = binwalk.display.Display(log=self.log_file,
csv=self.csv,
quiet=self.quiet,
verbose=self.verbose,
fit_to_screen=self.format_to_terminal)
def _set_verbosity(self):
'''
Sets the appropriate verbosity.
Must be called after self._test_target_files so that self.target_files is properly set.
'''
self.verbose = len(self.verbose)
# If more than one target file was specified, enable verbose mode; else, there is
# nothing in some outputs to indicate which scan corresponds to which file.
if len(self.target_files) > 1 and self.verbose == 0:
self.verbose = 1
def _test_target_files(self):
'''
Checks if the target files can be opened.
Any files that cannot be opened are removed from the self.target_files list.
'''
failed_open_count = 0
# Validate the target files listed in target_files
for tfile in self.target_files:
# Ignore directories.
if not os.path.isdir(tfile):
# Make sure we can open the target files
try:
fd = open(tfile, "rb")
fd.close()
except Exception as e:
sys.stderr.write("Cannot open file : %s\n" % str(e))
self.target_files.pop(self.target_files.index(tfile))
failed_open_count += 1
# Unless -O was specified, don't run the scan unless we are able to scan all specified files
if failed_open_count > 0 and not self.skip_unopened:
if failed_open_count > 1:
plural = 's'
else:
plural = ''
raise Exception("Failed to open %d file%s for scanning" % (failed_open_count, plural))
......@@ -4,10 +4,10 @@ import magic
import fnmatch
import ctypes
import ctypes.util
import binwalk.common
import binwalk.module
import binwalk.smartstrings
from binwalk.compat import *
from binwalk.common import strings
from binwalk.prettyprint import PrettyPrint
class HashResult(object):
'''
......@@ -24,6 +24,43 @@ class HashMatch(object):
'''
Class for fuzzy hash matching of files and directories.
'''
DEFAULT_CUTOFF = 0
CONSERVATIVE_CUTOFF = 90
CLI = [
binwalk.module.ModuleOption(short='c',
long='cutoff',
nargs=1,
priority=100,
type=int,
kwargs={'cutoff' : DEFAULT_CUTOFF},
description='Set the cutoff percentage'),
binwalk.module.ModuleOption(short='S',
long='strings',
kwargs={'strings' : True},
description='Diff strings inside files instead of the entire file'),
binwalk.module.ModuleOption(short='s',
long='same',
kwargs={'same' : True, 'cutoff' : CONSERVATIVE_CUTOFF},
description='Only show files that are the same'),
binwalk.module.ModuleOption(short='d',
long='diff',
kwargs={'same' : False, 'cutoff' : CONSERVATIVE_CUTOFF},
description='Only show files that are different'),
]
KWARGS = [
binwalk.module.ModuleKwarg(name='cutoff', default=DEFAULT_CUTOFF),
binwalk.module.ModuleKwarg(name='strings', default=False),
binwalk.module.ModuleKwarg(name='same', default=True),
binwalk.module.ModuleKwarg(name='symlinks', default=False),
binwalk.module.ModuleKwarg(name='name', default=False),
binwalk.module.ModuleKwarg(name='max_results', default=None),
binwalk.module.ModuleKwarg(name='abspath', default=False),
binwalk.module.ModuleKwarg(name='matches', default={}),
binwalk.module.ModuleKwarg(name='types', default={}),
]
# Requires libfuzzy.so
LIBRARY_NAME = "fuzzy"
......@@ -32,10 +69,11 @@ class HashMatch(object):
# Files smaller than this won't produce meaningful fuzzy results (from ssdeep.h)
FUZZY_MIN_FILE_SIZE = 4096
DEFAULT_CUTOFF = 0
CONSERVATIVE_CUTOFF = 90
HEADER = ["SIMILARITY", "FILE NAME"]
HEADER_FORMAT = "\n%s" + " " * 11 + "%s\n"
RESULT_FORMAT = "%4d%%" + " " * 16 + "%s\n"
def __init__(self, cutoff=None, strings=False, same=False, symlinks=False, name=False, max_results=None, display=False, log=None, csv=False, quiet=False, format_to_screen=False, abspath=False, matches={}, types={}):
def __init__(self, **kwargs):
'''
Class constructor.
......@@ -45,36 +83,16 @@ class HashMatch(object):
@symlinks - Set to True to include symbolic link files.
@name - Set to True to only compare files whose base names match.
@max_results - Stop searching after x number of matches.
@display - Set to True to display results to stdout, or pass an instance of binwalk.prettyprint.PrettyPrint.
@log - Specify a log file to log results to.
@csv - Set to True to log data in CSV format.
@quiet - Set to True to suppress output to stdout.
@format_to_screen - Set to True to format the output to the terminal window width.
@abspath - Set to True to display absolute file paths.
@matches - A dictionary of file names to diff.
@types - A dictionary of file types to diff.
Returns None.
'''
self.cutoff = cutoff
self.strings = strings
self.show_same = same
self.symlinks = symlinks
self.matches = matches
self.name = name
self.types = types
self.abspath = abspath
self.max_results = max_results
if display:
if isinstance(display, PrettyPrint):
self.pretty_print = display
else:
self.pretty_print = PrettyPrint(log=log, csv=csv, format_to_screen=format_to_screen, quiet=quiet)
binwalk.module.process_kwargs(self, kwargs)
self.pretty_print.header(header="PERCENTAGE\t\t\tFILE", csv=True)
else:
self.pretty_print = None
self.config.display.format_strings(self.HEADER_FORMAT, self.RESULT_FORMAT)
self.config.display.header(*self.HEADER)
self.total = 0
self.last_file1 = HashResult(None)
......@@ -85,9 +103,6 @@ class HashMatch(object):
self.lib = ctypes.cdll.LoadLibrary(ctypes.util.find_library(self.LIBRARY_NAME))
if self.cutoff is None:
self.cutoff = self.DEFAULT_CUTOFF
for k in get_keys(self.types):
for i in range(0, len(self.types[k])):
self.types[k][i] = re.compile(self.types[k][i])
......@@ -96,14 +111,12 @@ class HashMatch(object):
return ''.join(list(binwalk.common.strings(fname, minimum=10)))
def _print(self, match, fname):
if self.pretty_print:
if self.abspath:
fname = os.path.abspath(fname)
self.pretty_print._pprint('%4d\t\t\t\t%s\n' % (match, self.pretty_print._format(fname)))
if self.abspath:
fname = os.path.abspath(fname)
self.config.display.result(match, fname)
def _print_footer(self):
if self.pretty_print:
self.pretty_print.footer()
self.config.display.footer()
def _compare_files(self, file1, file2):
'''
......@@ -192,7 +205,7 @@ class HashMatch(object):
Returns True if this is a good match.
Returns False if his is not a good match.
'''
return (match is not None and ((match >= self.cutoff and self.show_same) or (match < self.cutoff and not self.show_same)))
return (match is not None and ((match >= self.cutoff and self.same) or (match < self.cutoff and not self.same)))
def _get_file_list(self, directory):
'''
......@@ -249,15 +262,17 @@ class HashMatch(object):
return set(file_list)
def files(self, needle, haystack):
class HashFiles(HashMatch):
def run(self):
'''
Compare one file against a list of other files.
@needle - File to match against.
@haystack - A list of haystack files.
Returns a list of tuple results.
'''
needle = self.config.target_files[0]
haystack = self.config.target_files[1:]
results = []
self.total = 0
......@@ -274,15 +289,17 @@ class HashMatch(object):
self._print_footer()
return results
def file(self, needle, haystack):
class HashFile(HashMatch):
def run(self):
'''
Search for one file inside one or more directories.
@needle - File to search for.
@haystack - List of directories to search in.
Returns a list of tuple results.
'''
needle = self.config.target_files[0]
haystack = self.config.target_files[1:]
matching_files = []
self.total = 0
done = False
......@@ -304,16 +321,18 @@ class HashMatch(object):
self._print_footer()
return matching_files
class HashDirectories(HashMatch):
def directories(self, needle, haystack):
def run(self):
'''
Compare the contents of one directory with the contents of other directories.
@source - Source directory to compare everything to.
@dir_list - Compare files in source to files in these directories.
Returns a list of tuple results.
'''
needle = self.config.target_files[0]
haystack = self.config.target_files[1:]
done = False
results = []
self.total = 0
......@@ -343,13 +362,3 @@ class HashMatch(object):
self._print_footer()
return results
if __name__ == '__main__':
import sys
hmatch = HashMatch(strings=True, name=False, types={True:"^elf"})
print (hmatch.file(sys.argv[1], sys.argv[2:]))
#for (match, fname) in hmatch.directories(sys.argv[1], sys.argv[2]):
#for (match, fname) in hmatch.find_file(sys.argv[1], sys.argv[2:]):
# print match, fname
import io
import sys
import csv as pycsv
from datetime import datetime
from binwalk.compat import *
from binwalk.common import file_md5
class PrettyPrint:
'''
Class for printing binwalk results to screen/log files.
An instance of PrettyPrint is available via the Binwalk.display object.
The PrettyPrint.results() method is of particular interest, as it is suitable for use as a Binwalk.scan() callback function,
and can be used to print Binwalk.scan() results to stdout, a log file, or both.
Useful class objects:
self.fp - The log file's file object.
self.quiet - If set to True, all output to stdout is supressed.
self.verbose - If set to True, verbose output is enabled.
self.csv - If set to True, data will be saved to the log file in CSV format.
self.format_to_screen - If set to True, output data will be formatted to fit into the current screen width.
Example usage:
import binwalk
bw = binwalk.Binwalk()
bw.display.header()
bw.single_scan('firmware.bin', callback=bw.display.results)
bw.display.footer()
'''
HEADER_WIDTH = 115
BUFFER_WIDTH = 32
MAX_LINE_LEN = 0
DEFAULT_DESCRIPTION_HEADER = "DESCRIPTION"
def __init__(self, binwalk=None, log=None, csv=False, quiet=False, verbose=0, format_to_screen=False):
'''
Class constructor.
@binwalk - An instance of the Binwalk class.
@log - Output log file.
@csv - If True, save data to log file in CSV format.
@quiet - If True, results will not be displayed to screen.
@verbose - If set to True, target file information will be displayed when file_info() is called.
@format_to_screen - If set to True, format the output data to fit into the current screen width.
Returns None.
'''
self.binwalk = binwalk
self.fp = None
self.log = log
self.csv = None
self.log_csv = csv
self.quiet = quiet
self.verbose = verbose
self.format_to_screen = format_to_screen
if self.format_to_screen:
self.enable_formatting(True)
if self.log is not None:
self.fp = open(log, "w")
if self.log_csv:
self.enable_csv()
def __del__(self):
'''
Class deconstructor.
'''
self.cleanup()
def __exit__(self, t, v, traceback):
self.cleanup()
def cleanup(self):
'''
Clean up any open file descriptors.
'''
try:
self.fp.close()
except:
pass
self.fp = None
def _csv_writerow(self, rows):
'''
Write data to csv file and flush.
'''
self.csv.writerow(rows)
self.fp.flush()
def _log(self, data, raw=False):
'''
Log data to the log file.
'''
if self.fp is not None:
if self.log_csv and self.csv and not raw:
data = data.replace('\n', ' ')
while ' ' in data:
data = data.replace(' ', ' ')
data_parts = data.split(None, 2)
if len(data_parts) in [2,3]:
for i in range(0, len(data_parts)):
data_parts[i] = data_parts[i].strip()
self._csv_writerow(data_parts)
else:
self.fp.write(data)
def _pprint(self, data, nolog=False, noprint=False):
'''
Print data to stdout and the log file.
'''
if not self.quiet and not noprint:
sys.stdout.write(data)
if not nolog:
self._log(data)
def _append_to_data_parts(self, data, start, end):
'''
Intelligently appends data to self.string_parts.
For use by self._format.
'''
try:
while data[start] == ' ':
start += 1
if start == end:
end = len(data[start:])
self.string_parts.append(data[start:end])
except:
try:
self.string_parts.append(data[start:])
except:
pass
return start
def _format(self, data):
'''
Formats a line of text to fit in the terminal window.
For Tim.
'''
offset = 0
space_offset = 0
self.string_parts = []
delim = '\n' + ' ' * self.BUFFER_WIDTH
if self.format_to_screen:
while len(data[offset:]) > self.MAX_LINE_LEN:
space_offset = data[offset:offset+self.MAX_LINE_LEN].rfind(' ')
if space_offset == -1 or space_offset == 0:
space_offset = self.MAX_LINE_LEN
self._append_to_data_parts(data, offset, offset+space_offset)
offset += space_offset
self._append_to_data_parts(data, offset, offset+len(data[offset:]))
return delim.join(self.string_parts)
def enable_csv(self):
'''
Enables CSV formatting to log file.
'''
self.log_csv = True
self.csv = pycsv.writer(self.fp)
def enable_formatting(self, tf):
'''
Enables output formatting, which fits output to the current terminal width.
@tf - If True, enable formatting. If False, disable formatting.
Returns None.
'''
self.format_to_screen = tf
if self.format_to_screen:
try:
import fcntl
import struct
import termios
# Get the terminal window width
hw = struct.unpack('hh', fcntl.ioctl(1, termios.TIOCGWINSZ, '1234'))
self.HEADER_WIDTH = hw[1]
except Exception as e:
pass
self.MAX_LINE_LEN = self.HEADER_WIDTH - self.BUFFER_WIDTH
def file_info(self, file_name):
'''
Prints detailed info about the specified file, including file name, scan time and the file's MD5 sum.
Called internally by self.header if self.verbose is not 0.
@file_name - The path to the target file.
@binwalk - Binwalk class instance.
Returns None.
'''
nolog = False
md5sum = file_md5(file_name)
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if self.csv:
nolog = True
self._csv_writerow(["FILE", "MD5SUM", "TIMESTAMP"])
self._csv_writerow([file_name, md5sum, timestamp])
self._pprint("\n")
self._pprint("Scan Time: %s\n" % timestamp, nolog=nolog)
if self.binwalk:
self._pprint("Signatures: %d\n" % self.binwalk.parser.signature_count, nolog=nolog)
self._pprint("Target File: %s\n" % file_name, nolog=nolog)
self._pprint("MD5 Checksum: %s\n" % md5sum, nolog=nolog)
def header(self, file_name=None, header=None, description=DEFAULT_DESCRIPTION_HEADER, csv=True):
'''
Prints the binwalk header, typically used just before starting a scan.
@file_name - If specified, and if self.verbose > 0, then detailed file info will be included in the header.
@header - If specified, this is a custom header to display at the top of the output.
@description - The description header text to display (default: "DESCRIPTION")
@csv - Set to True to print the header verbatim to the CSV file.
Returns None.
'''
nolog1 = False
nolog2 = False
if self.verbose and file_name is not None:
self.file_info(file_name)
if self.log_csv:
if csv:
nolog1 = False
else:
nolog1 = True
nolog2 = True
self._pprint("\n")
if not header:
self._pprint("DECIMAL \tHEX \t%s\n" % description, nolog=nolog1)
else:
self._pprint(header + "\n", nolog=nolog1)
self._pprint("-" * self.HEADER_WIDTH + "\n", nolog=nolog2)
def footer(self, bwalk=None, file_name=None):
'''
Prints the binwalk footer, typically used just after completing a scan.
Returns None.
'''
self._pprint("\n")
def results(self, offset, results, formatted=False):
'''
Prints the results of a scan. Suitable for use as a callback function for Binwalk.scan().
@offset - The offset at which the results were found.
@results - A list of libmagic result strings.
@formatted - Set to True if the result description has already been formatted properly.
Returns None.
'''
offset_printed = False
for info in results:
# Check for any grep filters before printing
if not self.binwalk or self.binwalk.filter.grep(info['description']):
if not formatted:
# Only display the offset once per list of results
if not offset_printed:
self._pprint("%-10d\t0x%-8X\t%s\n" % (offset, offset, self._format(info['description'])))
offset_printed = True
else:
self._pprint("%s\t %s\t%s\n" % (' '*10, ' '*8, self._format(info['description'])))
else:
self._pprint(self._format(info['description']))
def easy_results(self, offset, description):
'''
Simpler wrapper around prettyprint.results.
@offset - The offset at which the result was found.
@description - Description string to display.
Returns None.
'''
results = {
'offset' : offset,
'description' : description,
}
return self.results(offset, [results])
......@@ -105,7 +105,7 @@ for magic in magic_files:
fd.close()
# The data files to install along with the binwalk module
install_data_files = ["magic/*", "config/*", "plugins/*"]
install_data_files = ["magic/*", "config/*", "plugins/*", "modules/*"]
# Install the binwalk module, script and support files
setup( name = "binwalk",
......
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