Commit 15b1806e by devttys0

Updates to config file parsing

parent 0b023660
####################################################################################################################################### #######################################################################################################################################
# Default extraction rules, loaded when --extract is specified. # Default extraction rules, loaded when --extract is specified.
# #
# <lower-case unique string from binwalk output text>:<desired file extension>:<command to execute>:<successful command return codes>:<False if directories should not be recursively scanned> # <lower-case unique string from binwalk output text>:<desired file extension>:<command to execute>:<successful command return codes>:<False to not scan extracted files/directories>
# #
# Note that %e is a place holder for the extracted file name. # Note that %e is a place holder for the extracted file name.
# #
...@@ -65,6 +65,6 @@ ...@@ -65,6 +65,6 @@
^elf,:elf ^elf,:elf
private key:key private key:key
certificate:crt certificate:crt
html document header:html html document header
xml document:xml xml document:xml
...@@ -127,7 +127,7 @@ class Extractor(Module): ...@@ -127,7 +127,7 @@ class Extractor(Module):
# Attempt extraction # Attempt extraction
binwalk.core.common.debug("Extractor callback for %s @%d [%s]" % (r.file.name, r.offset, r.description)) binwalk.core.common.debug("Extractor callback for %s @%d [%s]" % (r.file.name, r.offset, r.description))
(extraction_directory, dd_file, recurse_into_directories) = self.extract(r.offset, r.description, r.file.path, size, r.name) (extraction_directory, dd_file, scan_extracted_files) = self.extract(r.offset, r.description, r.file.path, 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
if extraction_directory and dd_file: if extraction_directory and dd_file:
...@@ -150,18 +150,16 @@ class Extractor(Module): ...@@ -150,18 +150,16 @@ class Extractor(Module):
self.result(description=file_path, display=False) self.result(description=file_path, display=False)
# If recursion was specified, and the file is not the same one we just dd'd, and if it is not a directory # If recursion was specified, and the file is not the same one we just dd'd, and if it is not a directory
if self.matryoshka and file_path != dd_file_path: 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.base_recursion_dir)[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):
if recurse_into_directories: for root, dirs, files in os.walk(file_path):
for root, dirs, files in os.walk(file_path): for f in files:
for f in files: full_path = os.path.join(root, f)
full_path = os.path.join(root, f) self.pending.append(full_path)
print ("Adding '%s' to the list of pending shit." % full_path)
self.pending.append(full_path)
# If it's just a file, it to eh list of pending files # If it's just a file, it to eh list of pending files
else: else:
self.pending.append(file_path) self.pending.append(file_path)
...@@ -370,7 +368,7 @@ class Extractor(Module): ...@@ -370,7 +368,7 @@ class Extractor(Module):
original_dir = os.getcwd() original_dir = os.getcwd()
rules = self.match(description) rules = self.match(description)
file_path = os.path.realpath(file_name) file_path = os.path.realpath(file_name)
recurse_into_directories = False recurse = True
# No extraction rules for this file # No extraction rules for this file
if not rules: if not rules:
...@@ -441,7 +439,7 @@ class Extractor(Module): ...@@ -441,7 +439,7 @@ class Extractor(Module):
# 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 == True: if extract_ok == True:
# Make sure we recurse into any extracted directories if instructed to # Make sure we recurse into any extracted directories if instructed to
recurse_into_directories = rule['recurse'] recurse = rule['recurse']
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.
...@@ -459,7 +457,7 @@ class Extractor(Module): ...@@ -459,7 +457,7 @@ class Extractor(Module):
os.chdir(original_dir) os.chdir(original_dir)
return (output_directory, fname, recurse_into_directories) return (output_directory, fname, recurse)
def _entry_offset(self, index, entries, description): def _entry_offset(self, index, entries, description):
''' '''
......
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