Commit 6747bc62 by devttys0

Updated extractor return code to distinguish between non-existent extrators and…

Updated extractor return code to distinguish between non-existent extrators and failed extration attempts.
parent 31402726
...@@ -373,7 +373,7 @@ class Extractor(Module): ...@@ -373,7 +373,7 @@ class Extractor(Module):
extract_ok = True extract_ok = True
# Only clean up files if remove_after_execute was specified # Only clean up files if remove_after_execute was specified
if extract_ok and self.remove_after_execute: if extract_ok == True and self.remove_after_execute:
# Remove the original file that we extracted # Remove the original file that we extracted
try: try:
...@@ -394,7 +394,7 @@ class Extractor(Module): ...@@ -394,7 +394,7 @@ class Extractor(Module):
pass pass
# If the command executed OK, don't try any more rules # If the command executed OK, don't try any more rules
if extract_ok: if extract_ok == True:
break break
# Else, remove the extracted file if this isn't the last rule in the list. # Else, remove the extracted file if this isn't the last rule in the list.
# If it is the last rule, leave the file on disk for the user to examine. # If it is the last rule, leave the file on disk for the user to examine.
...@@ -527,7 +527,7 @@ class Extractor(Module): ...@@ -527,7 +527,7 @@ class Extractor(Module):
@cmd - Command to execute. @cmd - Command to execute.
@fname - File to run command against. @fname - File to run command against.
Returns True on success, False on failure. Returns True on success, False on failure, or None if the external extraction utility could not be found.
''' '''
tmp = None tmp = None
retval = True retval = True
...@@ -549,7 +549,9 @@ class Extractor(Module): ...@@ -549,7 +549,9 @@ class Extractor(Module):
cmd = cmd.replace(self.FILE_NAME_PLACEHOLDER, fname) cmd = cmd.replace(self.FILE_NAME_PLACEHOLDER, fname)
# Execute. # Execute.
if subprocess.call(shlex.split(cmd), stdout=tmp, stderr=tmp) != 0: if subprocess.call(shlex.split(cmd), stdout=tmp, stderr=tmp) == 0:
retval = True
else:
retval = False retval = False
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
...@@ -559,7 +561,7 @@ class Extractor(Module): ...@@ -559,7 +561,7 @@ class Extractor(Module):
# annoying to see this spammed out to the console every time. # annoying to see this spammed out to the console every time.
if not hasattr(e, 'errno') or e.errno != 2: if not hasattr(e, 'errno') or e.errno != 2:
sys.stderr.write("WARNING: Extractor.execute failed to run external extrator '%s': %s\n" % (str(cmd), str(e))) sys.stderr.write("WARNING: Extractor.execute failed to run external extrator '%s': %s\n" % (str(cmd), str(e)))
retval = False retval = None
if tmp is not None: if tmp is not None:
tmp.close() tmp.close()
......
...@@ -18,7 +18,7 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin): ...@@ -18,7 +18,7 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
self.original_cmd = '' self.original_cmd = ''
# Replace the existing LZMA extraction command with our own # Replace the existing LZMA extraction command with our own
# Note that this assumes that there is *one* LZMA extraction command... # Note that this assumes that there is *one* LZMA extraction command...
rules = self.module.extractor.get_rules() rules = self.module.extractor.get_rules()
for i in range(0, len(rules)): for i in range(0, len(rules)):
if rules[i]['regex'].match(self.SIGNATURE) and rules[i]['cmd']: if rules[i]['regex'].match(self.SIGNATURE) and rules[i]['cmd']:
...@@ -28,7 +28,10 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin): ...@@ -28,7 +28,10 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
def lzma_cable_extractor(self, fname): def lzma_cable_extractor(self, fname):
# Try extracting the LZMA file without modification first # Try extracting the LZMA file without modification first
if not self.module.extractor.execute(self.original_cmd, fname): result = self.module.extractor.execute(self.original_cmd, fname)
# If the external extractor was successul (True) or didn't exist (None), don't do anything.
if result not in [True, None]:
out_name = os.path.splitext(fname)[0] + '-patched' + os.path.splitext(fname)[1] out_name = os.path.splitext(fname)[0] + '-patched' + os.path.splitext(fname)[1]
fp_out = BlockFile(out_name, 'w') fp_out = BlockFile(out_name, 'w')
# Use self.module.config.open_file here to ensure that other config settings (such as byte-swapping) are honored # Use self.module.config.open_file here to ensure that other config settings (such as byte-swapping) are honored
......
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