From 26d6fab4c9b05d8c767714712b49568f9065e21b Mon Sep 17 00:00:00 2001
From: devttys0 <heffnercj@gmail.com>
Date: Sun, 22 Dec 2013 18:46:19 -0500
Subject: [PATCH] Renamed modules/configuration to modules/general

---
 src/binwalk/core/module.py           |   9 ++-------
 src/binwalk/modules/__init__.py      |   2 +-
 src/binwalk/modules/configuration.py | 190 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 src/binwalk/modules/general.py       | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/binwalk/modules/heuristics.py    |   2 +-
 5 files changed, 194 insertions(+), 199 deletions(-)
 delete mode 100644 src/binwalk/modules/configuration.py
 create mode 100644 src/binwalk/modules/general.py

diff --git a/src/binwalk/core/module.py b/src/binwalk/core/module.py
index bed8c51..3dc198a 100644
--- a/src/binwalk/core/module.py
+++ b/src/binwalk/core/module.py
@@ -136,33 +136,28 @@ class Module(object):
 	# A list of binwalk.core.module.ModuleKwargs accepted by __init__
 	KWARGS = []
 
-	# A dictionary of module dependencies; all modules depend on binwalk.modules.configuration.Configuration
-	#DEPENDS = {'config' : 'Configuration', 'extractor' : 'Extractor'}
+	# A dictionary of module dependencies; all modules depend on binwalk.modules.general.General
 	DEPENDS = [
-			Dependency(name='Configuration',
+			Dependency(name='General',
 					   attribute='config'),
 			Dependency(name='Extractor',
 					   attribute='extractor'),
 	]
 
 	# Format string for printing the header during a scan
-	#HEADER_FORMAT = "%s\n"
 	HEADER_FORMAT = "%-12s  %-12s    %s\n"
 
 	# Format string for printing each result during a scan 
-	#RESULT_FORMAT = "%.8d      %s\n"
 	RESULT_FORMAT = "%-12d  0x%-12X  %s\n"
 
 	# The header to print during a scan.
 	# Set to None to not print a header.
 	# Note that this will be formatted per the HEADER_FORMAT format string.
-	#HEADER = ["OFFSET      DESCRIPTION"]
 	HEADER = ["DECIMAL", "HEX", "DESCRIPTION"]
 
 	# The attribute names to print during a scan, as provided to the self.results method.
 	# Set to None to not print any results.
 	# Note that these will be formatted per the RESULT_FORMAT format string.
-	#RESULT = ['offset', 'description']
 	RESULT = ["offset", "offset", "description"]
 
 	VERBOSE_HEADER_FORMAT = ""
diff --git a/src/binwalk/modules/__init__.py b/src/binwalk/modules/__init__.py
index 40d0fd6..a144833 100644
--- a/src/binwalk/modules/__init__.py
+++ b/src/binwalk/modules/__init__.py
@@ -2,7 +2,7 @@ from binwalk.modules.signature import Signature
 from binwalk.modules.binvis import Plotter
 from binwalk.modules.hexdiff import HexDiff
 from binwalk.modules.hashmatch import HashMatch
-from binwalk.modules.configuration import Configuration
+from binwalk.modules.general import General
 from binwalk.modules.extractor import Extractor
 from binwalk.modules.entropy import Entropy
 from binwalk.modules.heuristics import HeuristicCompressionAnalyzer
diff --git a/src/binwalk/modules/configuration.py b/src/binwalk/modules/configuration.py
deleted file mode 100644
index 42d081c..0000000
--- a/src/binwalk/modules/configuration.py
+++ /dev/null
@@ -1,190 +0,0 @@
-import os
-import sys
-import argparse
-import binwalk.core.filter
-import binwalk.core.common
-import binwalk.core.display
-import binwalk.core.settings
-from binwalk.core.compat import *
-from binwalk.core.module import Module, Option, Kwarg, show_help
-
-class Configuration(Module):
-
-	TITLE = "General"
-	ORDER = 0
-
-	DEPENDS = []
-		
-	CLI = [
-		Option(long='length',
-			   short='l',
-			   type=int,
-			   kwargs={'length' : 0},
-			   description='Number of bytes to scan'),
-		Option(long='offset',
-			   short='o',
-			   type=int,
-			   kwargs={'offset' : 0},
-			   description='Start scan at this file offset'),
-		Option(long='block',
-			   short='K',
-			   type=int,
-			   kwargs={'block' : 0},
-			   description='Set file block size'),
-		Option(long='swap',
-			   short='g',
-			   type=int,
-			   kwargs={'swap_size' : 0},
-			   description='Reverse every n bytes before scanning'),
-		Option(short='I',
-			   long='show-invalid',
-			   kwargs={'show_invalid' : True},
-			   description='Show results marked as invalid'),
-		Option(short='x',
-			   long='exclude',
-			   kwargs={'exclude_filters' : []},
-			   type=list,
-			   dtype=str.__name__,
-			   description='Exclude results that match <str>'),
-		Option(short='y',
-			   long='include',
-			   kwargs={'include_filters' : []},
-			   type=list,
-			   dtype=str.__name__,
-			   description='Only show results that match <str>'),
-		Option(long='log',
-			   short='f',
-			   type=argparse.FileType,
-			   kwargs={'log_file' : None},
-			   description='Log results to file'),
-		Option(long='csv',
-			   short='c',
-			   kwargs={'csv' : True},
-			   description='Log results to file in CSV format'),
-		Option(long='term',
-			   short='t',
-			   kwargs={'format_to_terminal' : True},
-			   description='Format output to fit the terminal window'),
-		Option(long='quiet',
-			   short='q',
-			   kwargs={'quiet' : True},
-			   description='Supress output to stdout'),
-		Option(long='verbose',
-			   short='v',
-			   kwargs={'verbose' : True},
-			   description='Enable verbose output'),
-		Option(short='h',
-			   long='help',
-			   kwargs={'show_help' : True},
-			   description='Show help output'),
-		Option(long=None,
-			   short=None,
-			   type=binwalk.core.common.BlockFile,
-			   kwargs={'files' : []}),
-	]
-
-	KWARGS = [
-		Kwarg(name='length', default=0),
-		Kwarg(name='offset', default=0),
-		Kwarg(name='block', default=0),
-		Kwarg(name='swap_size', default=0),
-		Kwarg(name='show_invalid', default=False),
-		Kwarg(name='include_filters', default=[]),
-		Kwarg(name='exclude_filters', default=[]),
-		Kwarg(name='log_file', default=None),
-		Kwarg(name='csv', default=False),
-		Kwarg(name='format_to_terminal', default=False),
-		Kwarg(name='quiet', default=False),
-		Kwarg(name='verbose', default=False),
-		Kwarg(name='files', default=[]),
-		Kwarg(name='show_help', default=False),
-	]
-
-	PRIMARY = False
-
-	def load(self):
-		self.target_files = []
-
-		# Order is important with these two methods		
-		self._open_target_files()
-		self._set_verbosity()
-
-		self.filter = binwalk.core.filter.Filter(self.show_invalid)
-		
-		# Set any specified include/exclude filters
-		for regex in self.exclude_filters:
-			self.filter.exclude(regex)
-		for regex in self.include_filters:
-			self.filter.include(regex)
-
-		self.settings = binwalk.core.settings.Settings()
-		self.display = binwalk.core.display.Display(log=self.log_file,
-													csv=self.csv,
-													quiet=self.quiet,
-													verbose=self.verbose,
-													filter=self.filter,
-													fit_to_screen=self.format_to_terminal)
-		
-		if self.show_help:
-			show_help()
-			sys.exit(0)
-
-	def reset(self):
-		for fp in self.target_files:
-			fp.reset()
-
-	def __del__(self):
-		self._cleanup()
-
-	def __exit__(self, a, b, c):
-		self._cleanup()
-
-	def _cleanup(self):
-		if hasattr(self, 'target_files'):
-			for fp in self.target_files:
-				fp.close()
-
-	def _set_verbosity(self):
-		'''
-		Sets the appropriate verbosity.
-		Must be called after self._test_target_files so that self.target_files is properly set.
-		'''
-		# If more than one target file was specified, enable verbose mode; else, there is
-		# nothing in some outputs to indicate which scan corresponds to which file. 
-		if len(self.target_files) > 1 and not self.verbose:
-			self.verbose = True
-
-	def open_file(self, fname, length=None, offset=None, swap=None, block=None, peek=None):
-		'''
-		Opens the specified file with all pertinent configuration settings.
-		'''
-		if length is None:
-			length = self.length
-		if offset is None:
-			offset = self.offset
-		if swap is None:
-			swap = self.swap_size
-
-		return binwalk.core.common.BlockFile(fname, length=length, offset=offset, swap=swap, block=block, peek=peek)
-
-	def _open_target_files(self):
-		'''
-		Checks if the target files can be opened.
-		Any files that cannot be opened are removed from the self.target_files list.
-		'''
-		# Validate the target files listed in target_files
-		for tfile in self.files:
-			# Ignore directories.
-			if not os.path.isdir(tfile):
-				# Make sure we can open the target files
-				try:
-					self.target_files.append(self.open_file(tfile))
-				except KeyboardInterrupt as e:
-					raise e
-				except Exception as e:
-					self.error(description="Cannot open file : %s" % str(e))
-		
-		# If no files could be opened, quit permaturely
-		#if len(self.target_files) == 0:
-		#	raise Exception("Failed to open any files for scanning")
-
diff --git a/src/binwalk/modules/general.py b/src/binwalk/modules/general.py
new file mode 100644
index 0000000..793547e
--- /dev/null
+++ b/src/binwalk/modules/general.py
@@ -0,0 +1,190 @@
+import os
+import sys
+import argparse
+import binwalk.core.filter
+import binwalk.core.common
+import binwalk.core.display
+import binwalk.core.settings
+from binwalk.core.compat import *
+from binwalk.core.module import Module, Option, Kwarg, show_help
+
+class General(Module):
+
+	TITLE = "General"
+	ORDER = 0
+
+	DEPENDS = []
+		
+	CLI = [
+		Option(long='length',
+			   short='l',
+			   type=int,
+			   kwargs={'length' : 0},
+			   description='Number of bytes to scan'),
+		Option(long='offset',
+			   short='o',
+			   type=int,
+			   kwargs={'offset' : 0},
+			   description='Start scan at this file offset'),
+		Option(long='block',
+			   short='K',
+			   type=int,
+			   kwargs={'block' : 0},
+			   description='Set file block size'),
+		Option(long='swap',
+			   short='g',
+			   type=int,
+			   kwargs={'swap_size' : 0},
+			   description='Reverse every n bytes before scanning'),
+		Option(short='I',
+			   long='show-invalid',
+			   kwargs={'show_invalid' : True},
+			   description='Show results marked as invalid'),
+		Option(short='x',
+			   long='exclude',
+			   kwargs={'exclude_filters' : []},
+			   type=list,
+			   dtype=str.__name__,
+			   description='Exclude results that match <str>'),
+		Option(short='y',
+			   long='include',
+			   kwargs={'include_filters' : []},
+			   type=list,
+			   dtype=str.__name__,
+			   description='Only show results that match <str>'),
+		Option(long='log',
+			   short='f',
+			   type=argparse.FileType,
+			   kwargs={'log_file' : None},
+			   description='Log results to file'),
+		Option(long='csv',
+			   short='c',
+			   kwargs={'csv' : True},
+			   description='Log results to file in CSV format'),
+		Option(long='term',
+			   short='t',
+			   kwargs={'format_to_terminal' : True},
+			   description='Format output to fit the terminal window'),
+		Option(long='quiet',
+			   short='q',
+			   kwargs={'quiet' : True},
+			   description='Supress output to stdout'),
+		Option(long='verbose',
+			   short='v',
+			   kwargs={'verbose' : True},
+			   description='Enable verbose output'),
+		Option(short='h',
+			   long='help',
+			   kwargs={'show_help' : True},
+			   description='Show help output'),
+		Option(long=None,
+			   short=None,
+			   type=binwalk.core.common.BlockFile,
+			   kwargs={'files' : []}),
+	]
+
+	KWARGS = [
+		Kwarg(name='length', default=0),
+		Kwarg(name='offset', default=0),
+		Kwarg(name='block', default=0),
+		Kwarg(name='swap_size', default=0),
+		Kwarg(name='show_invalid', default=False),
+		Kwarg(name='include_filters', default=[]),
+		Kwarg(name='exclude_filters', default=[]),
+		Kwarg(name='log_file', default=None),
+		Kwarg(name='csv', default=False),
+		Kwarg(name='format_to_terminal', default=False),
+		Kwarg(name='quiet', default=False),
+		Kwarg(name='verbose', default=False),
+		Kwarg(name='files', default=[]),
+		Kwarg(name='show_help', default=False),
+	]
+
+	PRIMARY = False
+
+	def load(self):
+		self.target_files = []
+
+		# Order is important with these two methods		
+		self._open_target_files()
+		self._set_verbosity()
+
+		self.filter = binwalk.core.filter.Filter(self.show_invalid)
+		
+		# Set any specified include/exclude filters
+		for regex in self.exclude_filters:
+			self.filter.exclude(regex)
+		for regex in self.include_filters:
+			self.filter.include(regex)
+
+		self.settings = binwalk.core.settings.Settings()
+		self.display = binwalk.core.display.Display(log=self.log_file,
+													csv=self.csv,
+													quiet=self.quiet,
+													verbose=self.verbose,
+													filter=self.filter,
+													fit_to_screen=self.format_to_terminal)
+		
+		if self.show_help:
+			show_help()
+			sys.exit(0)
+
+	def reset(self):
+		for fp in self.target_files:
+			fp.reset()
+
+	def __del__(self):
+		self._cleanup()
+
+	def __exit__(self, a, b, c):
+		self._cleanup()
+
+	def _cleanup(self):
+		if hasattr(self, 'target_files'):
+			for fp in self.target_files:
+				fp.close()
+
+	def _set_verbosity(self):
+		'''
+		Sets the appropriate verbosity.
+		Must be called after self._test_target_files so that self.target_files is properly set.
+		'''
+		# If more than one target file was specified, enable verbose mode; else, there is
+		# nothing in some outputs to indicate which scan corresponds to which file. 
+		if len(self.target_files) > 1 and not self.verbose:
+			self.verbose = True
+
+	def open_file(self, fname, length=None, offset=None, swap=None, block=None, peek=None):
+		'''
+		Opens the specified file with all pertinent configuration settings.
+		'''
+		if length is None:
+			length = self.length
+		if offset is None:
+			offset = self.offset
+		if swap is None:
+			swap = self.swap_size
+
+		return binwalk.core.common.BlockFile(fname, length=length, offset=offset, swap=swap, block=block, peek=peek)
+
+	def _open_target_files(self):
+		'''
+		Checks if the target files can be opened.
+		Any files that cannot be opened are removed from the self.target_files list.
+		'''
+		# Validate the target files listed in target_files
+		for tfile in self.files:
+			# Ignore directories.
+			if not os.path.isdir(tfile):
+				# Make sure we can open the target files
+				try:
+					self.target_files.append(self.open_file(tfile))
+				except KeyboardInterrupt as e:
+					raise e
+				except Exception as e:
+					self.error(description="Cannot open file : %s" % str(e))
+		
+		# If no files could be opened, quit permaturely
+		#if len(self.target_files) == 0:
+		#	raise Exception("Failed to open any files for scanning")
+
diff --git a/src/binwalk/modules/heuristics.py b/src/binwalk/modules/heuristics.py
index e58fcb8..087cc95 100644
--- a/src/binwalk/modules/heuristics.py
+++ b/src/binwalk/modules/heuristics.py
@@ -88,7 +88,7 @@ class HeuristicCompressionAnalyzer(Module):
 	TITLE = "Heuristic Compression"
 
 	DEPENDS = [
-			Dependency(name='Configuration',
+			Dependency(name='General',
 					   attribute='config'),
 			Dependency(name='Entropy',
 					   attribute='entropy',
--
libgit2 0.26.0