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
aba30b02
Commit
aba30b02
authored
Dec 13, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added dependency feature to modules.
parent
6106d337
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
9 deletions
+72
-9
module.py
src/binwalk/module.py
+70
-9
__init__.py
src/binwalk/modules/__init__.py
+2
-0
No files found.
src/binwalk/module.py
View file @
aba30b02
import
io
import
sys
import
inspect
import
argparse
import
binwalk.common
from
binwalk.compat
import
*
...
...
@@ -42,15 +43,69 @@ class ModuleKwarg(object):
self
.
default
=
default
self
.
description
=
description
def
list_modules
():
def
process_kwargs
(
module
,
kwargs
):
return
Modules
(
dummy
=
True
)
.
kwargs
(
module
,
kwargs
)
class
Modules
(
object
):
def
__init__
(
self
,
dummy
=
False
):
self
.
config
=
None
if
not
dummy
:
from
binwalk.modules.configuration
import
Configuration
self
.
config
=
self
.
load
(
Configuration
)
def
list
(
self
):
import
binwalk.modules
objects
=
[]
for
(
name
,
obj
)
in
inspect
.
getmembers
(
binwalk
.
modules
):
if
inspect
.
isclass
(
obj
)
and
hasattr
(
obj
,
"run"
):
objects
.
append
(
obj
)
return
objects
def
run
(
self
,
module
):
results
=
None
obj
=
self
.
load
()
if
obj
.
enabled
:
try
:
obj
.
run
()
except
AttributeError
:
pass
def
process_argv
(
module
,
config
=
None
,
argv
=
sys
.
argv
[
1
:]):
return
results
def
load
(
self
,
module
):
kwargs
=
self
.
argv
(
module
)
kwargs
.
update
(
self
.
dependencies
(
module
))
return
module
(
**
kwargs
)
def
dependencies
(
self
,
module
):
kwargs
=
{}
if
hasattr
(
module
,
"DEPENDS"
):
# Disable output when modules are loaded as dependencies
orig_log
=
self
.
config
.
display
.
log
orig_quiet
=
self
.
config
.
display
.
quiet
self
.
config
.
display
.
log
=
False
self
.
config
.
display
.
quiet
=
True
for
(
kwarg
,
mod
)
in
module
.
DEPENDS
:
kwargs
[
kwarg
]
=
self
.
run
(
mod
)
self
.
config
.
display
.
log
=
orig_log
self
.
config
.
display
.
quiet
=
orig_quiet
return
kwargs
def
argv
(
self
,
module
,
argv
=
sys
.
argv
[
1
:]):
'''
Processes argv for any options specific to the specified module.
@module - The module to process argv for.
@config - An instance of the binwalk.modules.configuration.Configuration class.
@argv - A list of command line arguments (excluding argv[0]).
Returns a dictionary of kwargs for the specified module.
...
...
@@ -117,15 +172,21 @@ def process_argv(module, config=None, argv=sys.argv[1:]):
else
:
kwargs
[
name
]
=
value
else
:
raise
Exception
(
"binwalk.module.process_
argv:
%
s has no attribute 'CLI'"
%
str
(
module
))
raise
Exception
(
"binwalk.module.
argv:
%
s has no attribute 'CLI'"
%
str
(
module
))
if
config
is
not
None
and
not
has_key
(
kwargs
,
'config'
):
kwargs
[
'config'
]
=
config
if
self
.
config
is
not
None
and
not
has_key
(
kwargs
,
'config'
):
kwargs
[
'config'
]
=
self
.
config
return
kwargs
# If some command line arguments for this module were parsed, then set it to enabled.
# Else, disable it by default.
if
kwargs
:
kwargs
[
'enabled'
]
=
True
else
:
kwargs
[
'enabled'
]
=
False
return
kwargs
def
process_kwargs
(
module
,
kwargs
):
def
kwargs
(
self
,
module
,
kwargs
):
'''
Processes a module's kwargs. All modules should use this for kwarg processing.
...
...
@@ -146,5 +207,5 @@ def process_kwargs(module, kwargs):
if
has_key
(
kwargs
,
'config'
):
setattr
(
module
,
'config'
,
kwargs
[
'config'
])
else
:
raise
Exception
(
"binwalk.module.parse_module
_kwargs:
%
s has no attribute 'KWARGS'"
%
str
(
module
))
raise
Exception
(
"binwalk.module.process
_kwargs:
%
s has no attribute 'KWARGS'"
%
str
(
module
))
src/binwalk/modules/__init__.py
View file @
aba30b02
from
configuration
import
Configuration
from
hashmatch
import
HashFile
,
HashFiles
,
HashDirectories
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