Commit cfedd0ff by devttys0

Initial port of extract.py to a module. Currently extraction is broken.

parent 5ab25d16
...@@ -8,10 +8,6 @@ import binwalk.config ...@@ -8,10 +8,6 @@ import binwalk.config
import binwalk.plugin import binwalk.plugin
from binwalk.compat import * from binwalk.compat import *
class Type(object):
Primary = 1
Support = 2
class ModuleOption(object): class ModuleOption(object):
''' '''
A container class that allows modules to declare command line options. A container class that allows modules to declare command line options.
...@@ -118,9 +114,6 @@ class Module(object): ...@@ -118,9 +114,6 @@ class Module(object):
# The module title, as displayed in help output # The module title, as displayed in help output
TITLE = "" TITLE = ""
# Default type is primary
TYPE = Types.Primary
# A list of binwalk.module.ModuleOption command line options # A list of binwalk.module.ModuleOption command line options
CLI = [] CLI = []
...@@ -128,7 +121,7 @@ class Module(object): ...@@ -128,7 +121,7 @@ class Module(object):
KWARGS = [] KWARGS = []
# A dictionary of module dependencies; all modules depend on binwalk.modules.configuration.Configuration # A dictionary of module dependencies; all modules depend on binwalk.modules.configuration.Configuration
DEPENDS = {'config' : 'Configuration'} DEPENDS = {'config' : 'Configuration', 'extractor' : 'Extractor'}
# Format string for printing the header during a scan # Format string for printing the header during a scan
HEADER_FORMAT = "%s\n" HEADER_FORMAT = "%s\n"
...@@ -194,6 +187,16 @@ class Module(object): ...@@ -194,6 +187,16 @@ class Module(object):
''' '''
return False return False
def process_result(self, r):
'''
Processes the result. Passed to all dependency modules when a valid result is found.
@r - The result, an instance of binwalk.module.Result.
Returns None.
'''
return None
def validate(self, r): def validate(self, r):
''' '''
Validates the result. Validates the result.
...@@ -245,6 +248,10 @@ class Module(object): ...@@ -245,6 +248,10 @@ class Module(object):
self._plugins_result(r) self._plugins_result(r)
if r.valid: if r.valid:
for (attribute, module) in iterator(self.DEPENDS):
dependency = getattr(self, attribute)
dependency.process_result(r)
self.results.append(r) self.results.append(r)
# Update the progress status automatically if it is not being done manually by the module # Update the progress status automatically if it is not being done manually by the module
...@@ -421,13 +428,22 @@ class Modules(object): ...@@ -421,13 +428,22 @@ class Modules(object):
def execute(self, *args, **kwargs): def execute(self, *args, **kwargs):
run_modules = [] run_modules = []
self._set_arguments(list(args), kwargs) orig_arguments = self.arguments
if args or kwargs:
self._set_arguments(list(args), kwargs)
# Run all modules
for module in self.list(): for module in self.list():
if module.TYPE == Type.Primary: obj = self.run(module)
obj = self.run(module)
if obj.enabled: # Add all loaded modules that marked themselves as enabled to the run_modules list
run_modules.append(obj) for (module, obj) in iterator(self.loaded_modules):
if obj.enabled:
run_modules.append(obj)
self.arguments = orig_arguments
return run_modules return run_modules
def run(self, module): def run(self, module):
...@@ -446,12 +462,14 @@ class Modules(object): ...@@ -446,12 +462,14 @@ class Modules(object):
def load(self, module): def load(self, module):
kwargs = self.argv(module, argv=self.arguments) kwargs = self.argv(module, argv=self.arguments)
kwargs.update(self.dependencies(module)) kwargs.update(self.dependencies(module))
print "Loading", module
return module(**kwargs) return module(**kwargs)
def dependencies(self, module): def dependencies(self, module):
import binwalk.modules import binwalk.modules
kwargs = {} kwargs = {}
print "Loading dependency:", module
if hasattr(module, "DEPENDS"): if hasattr(module, "DEPENDS"):
for (kwarg, dependency) in iterator(module.DEPENDS): for (kwarg, dependency) in iterator(module.DEPENDS):
......
...@@ -3,3 +3,4 @@ from binvis import Plotter ...@@ -3,3 +3,4 @@ from binvis import Plotter
from hexdiff import HexDiff from hexdiff import HexDiff
from hashmatch import HashMatch from hashmatch import HashMatch
from configuration import Configuration from configuration import Configuration
from extractor import Extractor
...@@ -11,7 +11,9 @@ from binwalk.compat import * ...@@ -11,7 +11,9 @@ from binwalk.compat import *
class Configuration(binwalk.module.Module): class Configuration(binwalk.module.Module):
TITLE = "General" TITLE = "General"
DEPENDS = {}
CLI = [ CLI = [
binwalk.module.ModuleOption(long='length', binwalk.module.ModuleOption(long='length',
short='l', short='l',
......
...@@ -106,7 +106,7 @@ class HexDiff(binwalk.module.Module): ...@@ -106,7 +106,7 @@ class HexDiff(binwalk.module.Module):
self.block_hex += c self.block_hex += c
def _build_header(self, files, block_size): def _build_header(self, files, block_size):
header = "OFFSET" + (" " * 4) + files[0].name header = "OFFSET" + (" " * 6) + files[0].name
for i in range(1, len(files)): for i in range(1, len(files)):
header += " " * ((block_size * 3) + 2 + block_size + 8 - len(files[i-1].name)) header += " " * ((block_size * 3) + 2 + block_size + 8 - len(files[i-1].name))
...@@ -178,9 +178,9 @@ class HexDiff(binwalk.module.Module): ...@@ -178,9 +178,9 @@ class HexDiff(binwalk.module.Module):
while i < read_block_size and (total+i) < size: while i < read_block_size and (total+i) < size:
diff_same = {} diff_same = {}
alt_text = "*" + " " * 6 alt_text = "*" + " " * 8
self._build_block("%.08X " % (total + i + offset)) self._build_block("%.08X " % (total + i + offset))
# For each byte in this block, is the byte the same in all files, the same in some files, or different in all files? # For each byte in this block, is the byte the same in all files, the same in some files, or different in all files?
for j in range(0, block): for j in range(0, block):
......
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