Commit a7e4b1ca by devttys0

Fixed cpio extraction bug; added extra extraction debugging statements

parent f024a2e5
...@@ -38,7 +38,7 @@ class Entropy(Module): ...@@ -38,7 +38,7 @@ class Entropy(Module):
kwargs={'do_plot' : False}, kwargs={'do_plot' : False},
description='Do not generate an entropy plot graph'), description='Do not generate an entropy plot graph'),
Option(short='Q', Option(short='Q',
long='legend', long='nlegend',
kwargs={'show_legend' : False}, kwargs={'show_legend' : False},
description='Omit the legend from the entropy plot graph'), description='Omit the legend from the entropy plot graph'),
] ]
......
...@@ -114,9 +114,15 @@ class Extractor(Module): ...@@ -114,9 +114,15 @@ class Extractor(Module):
else: else:
size = r.size size = r.size
if r.valid:
binwalk.core.common.debug("Extractor callback for %s:%d [%s & %s & %s]" % (r.file.name, r.offset, str(r.valid), str(r.display), str(r.extract)))
# Only extract valid results displayed to the user and marked for extraction # Only extract valid results displayed to the user and marked for extraction
# TODO: Results excluded via -x/-y options should be marked as invalid; filtering on r.display means that
# with -q specified, nothing gets extracted!
if r.valid and r.display and r.extract: if r.valid and r.display and r.extract:
# Do the extraction # Do the extraction
binwalk.core.common.debug("Attempting extraction...")
(extraction_directory, dd_file) = self.extract(r.offset, r.description, r.file.name, size, r.name) (extraction_directory, dd_file) = self.extract(r.offset, r.description, r.file.name, size, r.name)
# If the extraction was successful, self.extract will have returned the output directory and name of the dd'd file # If the extraction was successful, self.extract will have returned the output directory and name of the dd'd file
...@@ -541,6 +547,8 @@ class Extractor(Module): ...@@ -541,6 +547,8 @@ class Extractor(Module):
tmp = None tmp = None
retval = True retval = True
binwalk.core.common.debug("Running extractor '%s'" % str(cmd))
try: try:
if callable(cmd): if callable(cmd):
try: try:
......
...@@ -10,6 +10,7 @@ class CPIOPlugin(binwalk.core.plugin.Plugin): ...@@ -10,6 +10,7 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
def pre_scan(self): def pre_scan(self):
# Be sure to re-set this at the beginning of every scan # Be sure to re-set this at the beginning of every scan
self.found_archive = False self.found_archive = False
self.found_archive_in_file = None
def scan(self, result): def scan(self, result):
if result.valid: if result.valid:
...@@ -17,8 +18,9 @@ class CPIOPlugin(binwalk.core.plugin.Plugin): ...@@ -17,8 +18,9 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
# Displaying each entry is useful, as it shows what files are contained in the archive, # Displaying each entry is useful, as it shows what files are contained in the archive,
# but we only want to extract the archive when the first entry is found. # but we only want to extract the archive when the first entry is found.
if result.description.startswith('ASCII cpio archive'): if result.description.startswith('ASCII cpio archive'):
if not self.found_archive: if not self.found_archive or self.found_archive_in_file != result.file.name:
# This is the first entry. Set found_archive and allow the scan to continue normally. # This is the first entry. Set found_archive and allow the scan to continue normally.
self.found_archive_in_file = result.file.name
self.found_archive = True self.found_archive = True
result.extract = True result.extract = True
elif 'TRAILER!!!' in result.description: elif 'TRAILER!!!' in result.description:
...@@ -29,3 +31,9 @@ class CPIOPlugin(binwalk.core.plugin.Plugin): ...@@ -29,3 +31,9 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
# The first entry has already been found and this is not the last entry, or the last entry # The first entry has already been found and this is not the last entry, or the last entry
# has not yet been found. Don't extract. # has not yet been found. Don't extract.
result.extract = False result.extract = False
else:
# If this was a valid non-CPIO archive result, reset these values; else, a previous
# false positive CPIO result could leave these set, causing a subsequent valid CPIO
# result to not be extracted.
self.found_archive = False
self.found_archive_in_file = None
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