Commit 55075e57 by devttys0

Fixed handling of module errors and invalid integer options

parent bab7c0c3
...@@ -74,9 +74,8 @@ Most distros don't have pyqtgraph in their default repositories, so it's best to ...@@ -74,9 +74,8 @@ Most distros don't have pyqtgraph in their default repositories, so it's best to
MANUALLY INSTALLING EXTRACTION UTILITIES MANUALLY INSTALLING EXTRACTION UTILITIES
------------------------------------------- -------------------------------------------
Binwalk can automatically invoke external extraction utilities to extract various types of files that it Binwalk can automatically invoke external extraction utilities to extract various types of files that it may find during
may find during a scan. These utilities are optional, but recommended if you plan on using binwalk's a scan. These utilities are optional, but recommended if you plan on using binwalk's extraction features.
extraction features.
Most utilities can be installed from your distro's repositories (package names may vary slightly based Most utilities can be installed from your distro's repositories (package names may vary slightly based
on your particular distro): on your particular distro):
......
# Common functions. # Common functions used throughout various parts of binwalk code.
import io import io
import os import os
import re import re
......
...@@ -5,7 +5,10 @@ import binwalk.core.common ...@@ -5,7 +5,10 @@ import binwalk.core.common
from binwalk.core.compat import * from binwalk.core.compat import *
class Display(object): class Display(object):
'''
Class to handle display of output and writing to log files.
This class is instantiated for all modules implicitly and should not need to be invoked directly by most modules.
'''
SCREEN_WIDTH = 0 SCREEN_WIDTH = 0
HEADER_WIDTH = 150 HEADER_WIDTH = 150
DEFAULT_FORMAT = "%s\n" DEFAULT_FORMAT = "%s\n"
......
...@@ -149,7 +149,7 @@ class Module(object): ...@@ -149,7 +149,7 @@ class Module(object):
attribute='extractor'), attribute='extractor'),
] ]
# A list of dependencies that can be filled in as needed by each individual module. # A list of binwalk.core.module.Dependency instances that can be filled in as needed by each individual module.
DEPENDS = [] DEPENDS = []
# Format string for printing the header during a scan. # Format string for printing the header during a scan.
...@@ -407,6 +407,11 @@ class Module(object): ...@@ -407,6 +407,11 @@ class Module(object):
sys.stderr.write("\n" + e.module + " Error: " + e.description + "\n\n") sys.stderr.write("\n" + e.module + " Error: " + e.description + "\n\n")
def header(self): def header(self):
'''
Displays the scan header, as defined by self.HEADER and self.HEADER_FORMAT.
Returns None.
'''
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_FORMAT, self.VERBOSE) self.config.display.add_custom_header(self.VERBOSE_FORMAT, self.VERBOSE)
...@@ -416,6 +421,11 @@ class Module(object): ...@@ -416,6 +421,11 @@ class Module(object):
self.config.display.header(self.HEADER, file_name=self.current_target_file_name) self.config.display.header(self.HEADER, file_name=self.current_target_file_name)
def footer(self): def footer(self):
'''
Displays the scan footer.
Returns None.
'''
self.config.display.footer() self.config.display.footer()
def main(self, parent): def main(self, parent):
...@@ -720,6 +730,7 @@ class Modules(object): ...@@ -720,6 +730,7 @@ class Modules(object):
last_priority[name] = module_option.priority last_priority[name] = module_option.priority
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values # Do this manually as argparse doesn't seem to be able to handle hexadecimal values
try:
if module_option.type == int: if module_option.type == int:
kwargs[name] = int(value, 0) kwargs[name] = int(value, 0)
elif module_option.type == float: elif module_option.type == float:
...@@ -734,6 +745,10 @@ class Modules(object): ...@@ -734,6 +745,10 @@ class Modules(object):
kwargs[name].append(value) kwargs[name].append(value)
else: else:
kwargs[name] = value kwargs[name] = value
except KeyboardInterrupt as e:
raise e
except Exception as e:
raise ModuleException("Invalid usage: %s" % str(e))
return kwargs return kwargs
......
...@@ -34,6 +34,7 @@ def main(): ...@@ -34,6 +34,7 @@ def main():
elif not modules.execute(): elif not modules.execute():
modules.execute(*sys.argv[1:], signature=True) modules.execute(*sys.argv[1:], signature=True)
except binwalk.ModuleException as e: except binwalk.ModuleException as e:
sys.stderr.write(str(e) + '\n')
sys.exit(1) sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
......
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