Commit 464cb3b0 by devttys0

Added binwalk_simple example

parent 39c081fb
......@@ -14,7 +14,7 @@ class Option(object):
A container class that allows modules to declare command line options.
'''
def __init__(self, kwargs={}, priority=0, description="", short="", long="", type=None, dtype=""):
def __init__(self, kwargs={}, priority=0, description="", short="", long="", type=None, dtype=None):
'''
Class constructor.
......@@ -34,9 +34,9 @@ class Option(object):
self.short = short
self.long = long
self.type = type
self.dtype = str(dtype)
self.dtype = dtype
if not self.dtype:
if not self.dtype and self.type:
if self.type in [io.FileIO, argparse.FileType, binwalk.core.common.BlockFile]:
self.dtype = 'file'
elif self.type in [int, float, str]:
......@@ -155,6 +155,9 @@ class Module(object):
# Modules with higher priorities are executed first
PRIORITY = 5
# Modules with a higher order are displayed first in help output
ORDER = 5
def __init__(self, dependency=False, **kwargs):
self.errors = []
self.results = []
......@@ -469,17 +472,23 @@ class Modules(object):
return sorted(modules, key=modules.get, reverse=True)
def help(self):
modules = {}
help_string = "\nBinwalk v%s\nCraig Heffner, http://www.binwalk.org\n" % binwalk.core.settings.Settings.VERSION
for obj in self.list(attribute="CLI"):
if obj.CLI:
help_string += "\n%s Options:\n" % obj.TITLE
# Build a dictionary of modules and their ORDER attributes.
# This makes it easy to sort modules by their ORDER attribute for display.
for module in self.list(attribute="CLI"):
if module.CLI:
modules[module] = module.ORDER
for module in sorted(modules, key=modules.get, reverse=True):
help_string += "\n%s Options:\n" % module.TITLE
for module_option in obj.CLI:
for module_option in module.CLI:
if module_option.long:
long_opt = '--' + module_option.long
if module_option.type is not None:
if module_option.dtype:
optargs = "=<%s>" % module_option.dtype
else:
optargs = ""
......@@ -554,6 +563,7 @@ class Modules(object):
# self.run will automatically add the dependency class instance to self.loaded_modules
self.run(dependency)
# If a dependency failed, consider this a non-recoverable error and raise an exception
if self.loaded_modules[dependency].errors:
raise ModuleException("Failed to load " + str(dependency))
else:
......
......@@ -11,6 +11,7 @@ from binwalk.core.module import Module, Option, Kwarg, show_help
class Configuration(Module):
TITLE = "General"
ORDER = 0
DEPENDS = {}
......
......@@ -18,6 +18,7 @@ class Entropy(Module):
COLORS = ['r', 'g', 'c', 'b', 'm']
TITLE = "Entropy"
ORDER = 8
CLI = [
Option(short='E',
......
......@@ -26,6 +26,7 @@ class Extractor(Module):
MAX_READ_SIZE = 10 * 1024 * 1024
TITLE = 'Extraction'
ORDER = 9
CLI = [
Option(short='e',
......
......@@ -7,6 +7,7 @@ from binwalk.core.module import Module, Option, Kwarg
class Signature(Module):
TITLE = "Signature Scan"
ORDER = 10
CLI = [
Option(short='B',
......
#!/usr/bin/env python
import binwalk
binwalk.Modules().execute()
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