Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
binwalk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
binwalk
Commits
01bee124
Commit
01bee124
authored
Apr 17, 2015
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added options to include/exclude files by name via regex
parent
f9269cf4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletions
+45
-1
module.py
src/binwalk/core/module.py
+10
-1
general.py
src/binwalk/modules/general.py
+35
-0
No files found.
src/binwalk/core/module.py
View file @
01bee124
...
...
@@ -354,7 +354,7 @@ class Module(object):
self
.
target_file_list
+=
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
)
# Values in self.target_file_list are either already open files (BlockFile instances), or paths
...
...
@@ -364,8 +364,17 @@ class Module(object):
else
:
fp
=
next_target_file
if
not
fp
:
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
:
self
.
current_target_file_name
=
fp
.
path
...
...
src/binwalk/modules/general.py
View file @
01bee124
...
...
@@ -2,6 +2,7 @@
import
io
import
os
import
re
import
sys
import
argparse
import
binwalk.core.idb
...
...
@@ -69,6 +70,16 @@ class General(Module):
long
=
'help'
,
kwargs
=
{
'show_help'
:
True
},
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
,
short
=
None
,
type
=
binwalk
.
core
.
common
.
BlockFile
,
...
...
@@ -95,6 +106,8 @@ class General(Module):
Kwarg
(
name
=
'show_help'
,
default
=
False
),
Kwarg
(
name
=
'keep_going'
,
default
=
False
),
Kwarg
(
name
=
'subclass'
,
default
=
io
.
FileIO
),
Kwarg
(
name
=
'file_name_include_regex'
,
default
=
None
),
Kwarg
(
name
=
'file_name_exclude_regex'
,
default
=
None
),
]
PRIMARY
=
False
...
...
@@ -110,6 +123,12 @@ class General(Module):
self
.
_open_target_files
()
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
.
display
=
binwalk
.
core
.
display
.
Display
(
log
=
self
.
log_file
,
csv
=
self
.
csv
,
...
...
@@ -135,6 +154,22 @@ class General(Module):
if
len
(
self
.
target_files
)
>
1
and
not
self
.
verbose
:
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
):
'''
Opens the specified file with all pertinent configuration settings.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment