Commit 3b41d46d by devttys0

Fixed module dependency bug

parent 1ed3752f
...@@ -261,9 +261,11 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS): ...@@ -261,9 +261,11 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
if block > 0: if block > 0:
self.READ_BLOCK_SIZE = block self.READ_BLOCK_SIZE = block
self.base_block_size = self.READ_BLOCK_SIZE
if trail > 0: if trail > 0:
self.MAX_TRAILING_SIZE = trail self.MAX_TRAILING_SIZE = trail
self.base_trail_size = self.MAX_TRAILING_SIZE
super(self.__class__, self).__init__(fname, mode) super(self.__class__, self).__init__(fname, mode)
...@@ -297,8 +299,15 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS): ...@@ -297,8 +299,15 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
return data return data
def reset(self): def reset(self):
self.set_block_size(block=self.base_trail_size, trail=self.base_trail_size)
self.seek(self.offset) self.seek(self.offset)
def set_block_size(self, block=0, trail=0):
if block is not None:
self.READ_BLOCK_SIZE = block
if trail is not None:
self.MAX_TRAILING_SIZE = trail
def write(self, data): def write(self, data):
''' '''
Writes data to the opened file. Writes data to the opened file.
......
...@@ -543,8 +543,6 @@ class Modules(object): ...@@ -543,8 +543,6 @@ class Modules(object):
# If the module is not being loaded as a dependency, add it to the loaded modules dictionary # If the module is not being loaded as a dependency, add it to the loaded modules dictionary
if not dependency: if not dependency:
self.loaded_modules[module] = obj self.loaded_modules[module] = obj
if not kwargs and not has_key(self.default_dependency_modules, module):
self.default_dependency_modules[module] = obj
return obj return obj
...@@ -572,18 +570,14 @@ class Modules(object): ...@@ -572,18 +570,14 @@ class Modules(object):
if dependency.module == module: if dependency.module == module:
continue continue
# Only honor custom kwargs from modules that are enabled, else madness ensues. # Only load dependencies with custom kwargs from modules that are enabled, else madness ensues.
# Example: Heursitic module depends on entropy module, and sets entropy kwargs to contain 'enabled' : True. # Example: Heursitic module depends on entropy module, and sets entropy kwargs to contain 'enabled' : True.
# Without this check, an entropy scan would always be run, even if -H or -E weren't specified! # Without this check, an entropy scan would always be run, even if -H or -E weren't specified!
if module_enabled: #
kwargs = dependency.kwargs # Modules that are not enabled (e.g., extraction module) can load any dependency as long as they don't
else: # set any custom kwargs for those dependencies.
kwargs = {} if module_enabled or not dependency.kwargs:
depobj = self.run(dependency.module, dependency=True, kwargs=dependency.kwargs)
if not kwargs and has_key(self.default_dependency_modules, dependency.module):
depobj = self.default_dependency_modules[dependency.module]
else:
depobj = self.run(dependency.module, dependency=True, kwargs=kwargs)
# If a dependency failed, consider this a non-recoverable error and raise an exception # If a dependency failed, consider this a non-recoverable error and raise an exception
if depobj.errors: if depobj.errors:
......
...@@ -152,7 +152,7 @@ class Configuration(Module): ...@@ -152,7 +152,7 @@ class Configuration(Module):
if len(self.target_files) > 1 and not self.verbose: if len(self.target_files) > 1 and not self.verbose:
self.verbose = True self.verbose = True
def open_file(self, fname, length=None, offset=None, swap=None): def open_file(self, fname, length=None, offset=None, swap=None, block=0, trail=0):
''' '''
Opens the specified file with all pertinent configuration settings. Opens the specified file with all pertinent configuration settings.
''' '''
...@@ -163,7 +163,7 @@ class Configuration(Module): ...@@ -163,7 +163,7 @@ class Configuration(Module):
if swap is None: if swap is None:
swap = self.swap_size swap = self.swap_size
return binwalk.core.common.BlockFile(fname, length=length, offset=offset, swap=swap) return binwalk.core.common.BlockFile(fname, length=length, offset=offset, swap=swap, block=block, trail=trail)
def _open_target_files(self): def _open_target_files(self):
''' '''
......
...@@ -98,7 +98,7 @@ class Signature(Module): ...@@ -98,7 +98,7 @@ class Signature(Module):
break break
current_block_offset = 0 current_block_offset = 0
block_start = fp.offset + fp.total_read - dlen block_start = fp.offset + fp.tell() - dlen
self.status.completed = block_start - fp.offset self.status.completed = block_start - fp.offset
for candidate_offset in self.parser.find_signature_candidates(data, dlen): for candidate_offset in self.parser.find_signature_candidates(data, dlen):
......
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