Commit 01bee124 by devttys0

Added options to include/exclude files by name via regex

parent f9269cf4
...@@ -354,7 +354,7 @@ class Module(object): ...@@ -354,7 +354,7 @@ class Module(object):
self.target_file_list += self.extractor.pending self.target_file_list += self.extractor.pending
self.extractor.pending = [] self.extractor.pending = []
if self.target_file_list: while self.target_file_list:
next_target_file = self.target_file_list.pop(0) next_target_file = self.target_file_list.pop(0)
# Values in self.target_file_list are either already open files (BlockFile instances), or paths # Values in self.target_file_list are either already open files (BlockFile instances), or paths
...@@ -364,8 +364,17 @@ class Module(object): ...@@ -364,8 +364,17 @@ class Module(object):
else: else:
fp = next_target_file fp = next_target_file
self.status.clear() if not fp:
self.status.total = fp.length break
else:
if self.config.file_name_filter(fp) == False:
fp.close()
fp = None
continue
else:
self.status.clear()
self.status.total = fp.length
break
if fp is not None: if fp is not None:
self.current_target_file_name = fp.path self.current_target_file_name = fp.path
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import io import io
import os import os
import re
import sys import sys
import argparse import argparse
import binwalk.core.idb import binwalk.core.idb
...@@ -69,6 +70,16 @@ class General(Module): ...@@ -69,6 +70,16 @@ class General(Module):
long='help', long='help',
kwargs={'show_help' : True}, kwargs={'show_help' : True},
description='Show help output'), description='Show help output'),
Option(short='a',
long='finclude',
type=str,
kwargs={'file_name_include_regex' : ""},
description='Only scan files whose names match this regex'),
Option(short='p',
long='fexclude',
type=str,
kwargs={'file_name_exclude_regex' : ""},
description='Do not scan files whose names match this regex'),
Option(long=None, Option(long=None,
short=None, short=None,
type=binwalk.core.common.BlockFile, type=binwalk.core.common.BlockFile,
...@@ -95,6 +106,8 @@ class General(Module): ...@@ -95,6 +106,8 @@ class General(Module):
Kwarg(name='show_help', default=False), Kwarg(name='show_help', default=False),
Kwarg(name='keep_going', default=False), Kwarg(name='keep_going', default=False),
Kwarg(name='subclass', default=io.FileIO), Kwarg(name='subclass', default=io.FileIO),
Kwarg(name='file_name_include_regex', default=None),
Kwarg(name='file_name_exclude_regex', default=None),
] ]
PRIMARY = False PRIMARY = False
...@@ -110,6 +123,12 @@ class General(Module): ...@@ -110,6 +123,12 @@ class General(Module):
self._open_target_files() self._open_target_files()
self._set_verbosity() self._set_verbosity()
# Build file name filter regex rules
if self.file_name_include_regex:
self.file_name_include_regex = re.compile(self.file_name_include_regex)
if self.file_name_exclude_regex:
self.file_name_exclude_regex = re.compile(self.file_name_exclude_regex)
self.settings = binwalk.core.settings.Settings() self.settings = binwalk.core.settings.Settings()
self.display = binwalk.core.display.Display(log=self.log_file, self.display = binwalk.core.display.Display(log=self.log_file,
csv=self.csv, csv=self.csv,
...@@ -135,6 +154,22 @@ class General(Module): ...@@ -135,6 +154,22 @@ class General(Module):
if len(self.target_files) > 1 and not self.verbose: if len(self.target_files) > 1 and not self.verbose:
self.verbose = True self.verbose = True
def file_name_filter(self, fp):
'''
Checks to see if a file should be scanned based on file name include/exclude filters.
Most useful for matryoshka scans where only certian files are desired.
@fp - An instances of binwalk.common.BlockFile
Returns True if the file should be scanned, False if not.
'''
if self.file_name_include_regex and not self.file_name_include_regex.search(fp.name):
return False
if self.file_name_exclude_regex and self.file_name_exclude_regex.search(fp.name):
return False
return True
def open_file(self, fname, length=None, offset=None, swap=None, block=None, peek=None): def open_file(self, fname, length=None, offset=None, swap=None, block=None, peek=None):
''' '''
Opens the specified file with all pertinent configuration settings. Opens the specified file with all pertinent configuration settings.
......
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