Commit 5c4291ec by devttys0

Fixed heursitc module bug; fixed fundamental issue with specifying module-level dependencies.

parent 9258050b
......@@ -140,16 +140,18 @@ class Module(object):
# A list of binwalk.core.module.Kwargs accepted by __init__
KWARGS = []
# A dictionary of module dependencies; all modules depend on the General and Extractor modules.
# Note that if overriding these default DEPENDS for a module, you MUST include these default
# dependencies, with the same attribute values.
DEPENDS = [
# A list of default dependencies for all modules; do not override this unless you
# understand the consequences of doing so.
DEFAULT_DEPENDS = [
Dependency(name='General',
attribute='config'),
Dependency(name='Extractor',
attribute='extractor'),
]
# A list of dependencies that can be filled in as needed by each individual module.
DEPENDS = []
# Format string for printing the header during a scan.
# Must be set prior to calling self.header.
HEADER_FORMAT = "%-12s %-12s %s\n"
......@@ -195,12 +197,14 @@ class Module(object):
def __init__(self, **kwargs):
self.errors = []
self.results = []
self.target_file_list = []
self.status = None
self.enabled = False
self.current_target_file_name = None
self.name = self.__class__.__name__
self.plugins = binwalk.core.plugin.Plugins(self)
self.dependencies = self.DEFAULT_DEPENDS + self.DEPENDS
process_kwargs(self, kwargs)
......@@ -357,7 +361,7 @@ class Module(object):
self.validate(r)
self._plugins_result(r)
for dependency in self.DEPENDS:
for dependency in self.dependencies:
try:
getattr(self, dependency.attribute).callback(r)
except AttributeError:
......@@ -424,7 +428,7 @@ class Module(object):
self.modules = parent.loaded_modules
# Reset all dependency modules
for dependency in self.DEPENDS:
for dependency in self.dependencies:
if hasattr(self, dependency.attribute):
getattr(self, dependency.attribute).reset()
......@@ -628,9 +632,7 @@ class Modules(object):
import binwalk.modules
attributes = {}
if hasattr(module, "DEPENDS"):
for dependency in module.DEPENDS:
for dependency in module.DEFAULT_DEPENDS+module.DEPENDS:
# The dependency module must be imported by binwalk.modules.__init__.py
if hasattr(binwalk.modules, dependency.name):
......
......@@ -13,7 +13,7 @@ class General(Module):
TITLE = "General"
ORDER = 0
DEPENDS = []
DEFAULT_DEPENDS = []
CLI = [
Option(long='length',
......
......@@ -88,8 +88,6 @@ class HeuristicCompressionAnalyzer(Module):
TITLE = "Heuristic Compression"
DEPENDS = [
Dependency(name='General',
attribute='config'),
Dependency(name='Entropy',
attribute='entropy',
kwargs={'enabled' : True, 'do_plot' : False, 'display_results' : False, 'block_size' : ENTROPY_BLOCK_SIZE}),
......
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