Commit 1288135d by devttys0

Change output directory to CWD; fixed entropy BLOCK_SIZE bug.

parent 94a70ba8
...@@ -171,6 +171,10 @@ class Entropy(Module): ...@@ -171,6 +171,10 @@ class Entropy(Module):
else: else:
block_size = self.block_size block_size = self.block_size
# Make sure block size is greater than 0
if block_size <= 0:
block_size = self.DEFAULT_BLOCK_SIZE
binwalk.core.common.debug("Entropy block size (%d data points): %d" % (self.DEFAULT_DATA_POINTS, block_size)) binwalk.core.common.debug("Entropy block size (%d data points): %d" % (self.DEFAULT_DATA_POINTS, block_size))
while True: while True:
...@@ -301,13 +305,16 @@ class Entropy(Module): ...@@ -301,13 +305,16 @@ class Entropy(Module):
# TODO: legend is not displayed properly when saving plots to disk # TODO: legend is not displayed properly when saving plots to disk
if self.save_plot: if self.save_plot:
# Save graph to CWD
out_file = os.path.join(os.getcwd(), os.path.basename(fname))
# exporters.ImageExporter is different in different versions of pyqtgraph # exporters.ImageExporter is different in different versions of pyqtgraph
try: try:
exporter = exporters.ImageExporter(plt.plotItem) exporter = exporters.ImageExporter(plt.plotItem)
except TypeError: except TypeError:
exporter = exporters.ImageExporter.ImageExporter(plt.plotItem) exporter = exporters.ImageExporter.ImageExporter(plt.plotItem)
exporter.parameters()['width'] = self.FILE_WIDTH exporter.parameters()['width'] = self.FILE_WIDTH
exporter.export(binwalk.core.common.unique_file_name(fname, self.FILE_FORMAT)) exporter.export(binwalk.core.common.unique_file_name(out_file, self.FILE_FORMAT))
else: else:
plt.setLabel('left', self.YLABEL, units=self.YUNITS) plt.setLabel('left', self.YLABEL, units=self.YUNITS)
plt.setLabel('bottom', self.XLABEL, units=self.XUNITS) plt.setLabel('bottom', self.XLABEL, units=self.XUNITS)
......
...@@ -122,8 +122,6 @@ class Extractor(Module): ...@@ -122,8 +122,6 @@ class Extractor(Module):
# Holds a dictionary of the last directory listing for a given directory; used for identifying # Holds a dictionary of the last directory listing for a given directory; used for identifying
# newly created/extracted files that need to be appended to self.pending. # newly created/extracted files that need to be appended to self.pending.
self.last_directory_listing = {} self.last_directory_listing = {}
# Set to the directory path of the first extracted directory; this allows us to track recursion depth.
self.base_recursion_dir = ""
def callback(self, r): def callback(self, r):
# Make sure the file attribute is set to a compatible instance of binwalk.core.common.BlockFile # Make sure the file attribute is set to a compatible instance of binwalk.core.common.BlockFile
...@@ -171,7 +169,7 @@ class Extractor(Module): ...@@ -171,7 +169,7 @@ class Extractor(Module):
# If recursion was specified, and the file is not the same one we just dd'd # If recursion was specified, and the file is not the same one we just dd'd
if self.matryoshka and file_path != dd_file_path and scan_extracted_files: if self.matryoshka and file_path != dd_file_path and scan_extracted_files:
# If the recursion level of this file is less than or equal to our desired recursion level # If the recursion level of this file is less than or equal to our desired recursion level
if len(real_file_path.split(self.base_recursion_dir)[1].split(os.path.sep)) <= self.matryoshka: if len(real_file_path.split(self.directory)[1].split(os.path.sep)) <= self.matryoshka:
# If this is a directory and we are supposed to process directories for this extractor, # If this is a directory and we are supposed to process directories for this extractor,
# then add all files under that directory to the list of pending files. # then add all files under that directory to the list of pending files.
if os.path.isdir(file_path): if os.path.isdir(file_path):
...@@ -335,6 +333,11 @@ class Extractor(Module): ...@@ -335,6 +333,11 @@ class Extractor(Module):
if not has_key(self.extraction_directories, path): if not has_key(self.extraction_directories, path):
basedir = os.path.dirname(path) basedir = os.path.dirname(path)
basename = os.path.basename(path) basename = os.path.basename(path)
# Make sure we put the initial extracted file in the CWD
if self.directory is None:
basedir = os.getcwd()
outdir = os.path.join(basedir, '_' + basename) outdir = os.path.join(basedir, '_' + basename)
output_directory = unique_file_name(outdir, extension='extracted') output_directory = unique_file_name(outdir, extension='extracted')
...@@ -347,9 +350,9 @@ class Extractor(Module): ...@@ -347,9 +350,9 @@ class Extractor(Module):
output_directory = self.extraction_directories[path] output_directory = self.extraction_directories[path]
# Set the initial base extraction directory for later determining the level of recusion # Set the initial base extraction directory for later determining the level of recusion
# TODO: This is no longer needed since self.directory has the same information. Update code accordingly. if self.directory is None:
if not self.base_recursion_dir: self.directory = os.path.realpath(output_directory) + os.path.sep
self.base_recursion_dir = os.path.realpath(output_directory) + os.path.sep
return output_directory return output_directory
...@@ -398,10 +401,6 @@ class Extractor(Module): ...@@ -398,10 +401,6 @@ class Extractor(Module):
output_directory = self.build_output_directory(file_name) output_directory = self.build_output_directory(file_name)
# Update self.directory with the first output_directory path
if self.directory is None:
self.directory = output_directory
# Extract to end of file if no size was specified # Extract to end of file if no size was specified
if not size: if not size:
size = file_size(file_path) - offset size = file_size(file_path) - offset
......
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