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-depend
binwalk
Commits
858eaab5
Commit
858eaab5
authored
Aug 28, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed hexdiff bug introduced by previous patch.
parent
0c62122f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
37 deletions
+44
-37
module.py
src/binwalk/core/module.py
+31
-30
hexdiff.py
src/binwalk/modules/hexdiff.py
+13
-7
No files found.
src/binwalk/core/module.py
View file @
858eaab5
...
@@ -72,7 +72,7 @@ class Kwarg(object):
...
@@ -72,7 +72,7 @@ class Kwarg(object):
def
__init__
(
self
,
name
=
""
,
default
=
None
,
description
=
""
):
def
__init__
(
self
,
name
=
""
,
default
=
None
,
description
=
""
):
'''
'''
Class constructor.
Class constructor.
@name - Kwarg name.
@name - Kwarg name.
@default - Default kwarg value.
@default - Default kwarg value.
@description - Description string.
@description - Description string.
...
@@ -135,7 +135,7 @@ class Error(Result):
...
@@ -135,7 +135,7 @@ class Error(Result):
'''
'''
A subclass of binwalk.core.module.Result.
A subclass of binwalk.core.module.Result.
'''
'''
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
'''
'''
Accepts all the same kwargs as binwalk.core.module.Result, but the following are also added:
Accepts all the same kwargs as binwalk.core.module.Result, but the following are also added:
...
@@ -168,7 +168,7 @@ class Module(object):
...
@@ -168,7 +168,7 @@ class Module(object):
Dependency
(
name
=
'Extractor'
,
Dependency
(
name
=
'Extractor'
,
attribute
=
'extractor'
),
attribute
=
'extractor'
),
]
]
# A list of binwalk.core.module.Dependency instances that can be filled in as needed by each individual module.
# A list of binwalk.core.module.Dependency instances that can be filled in as needed by each individual module.
DEPENDS
=
[]
DEPENDS
=
[]
...
@@ -176,7 +176,7 @@ class Module(object):
...
@@ -176,7 +176,7 @@ class Module(object):
# Must be set prior to calling self.header.
# Must be set prior to calling self.header.
HEADER_FORMAT
=
"
%-12
s
%-12
s
%
s
\n
"
HEADER_FORMAT
=
"
%-12
s
%-12
s
%
s
\n
"
# Format string for printing each result during a scan.
# Format string for printing each result during a scan.
# Must be set prior to calling self.result.
# Must be set prior to calling self.result.
RESULT_FORMAT
=
"
%-12
d 0x
%-12
X
%
s
\n
"
RESULT_FORMAT
=
"
%-12
d 0x
%-12
X
%
s
\n
"
...
@@ -228,9 +228,9 @@ class Module(object):
...
@@ -228,9 +228,9 @@ class Module(object):
self
.
dependencies
=
self
.
DEFAULT_DEPENDS
+
self
.
DEPENDS
self
.
dependencies
=
self
.
DEFAULT_DEPENDS
+
self
.
DEPENDS
process_kwargs
(
self
,
kwargs
)
process_kwargs
(
self
,
kwargs
)
self
.
plugins
.
load_plugins
()
self
.
plugins
.
load_plugins
()
try
:
try
:
self
.
load
()
self
.
load
()
except
KeyboardInterrupt
as
e
:
except
KeyboardInterrupt
as
e
:
...
@@ -322,13 +322,13 @@ class Module(object):
...
@@ -322,13 +322,13 @@ class Module(object):
result
=
[
self
.
RESULT
]
result
=
[
self
.
RESULT
]
else
:
else
:
result
=
self
.
RESULT
result
=
self
.
RESULT
for
name
in
result
:
for
name
in
result
:
args
.
append
(
getattr
(
r
,
name
))
args
.
append
(
getattr
(
r
,
name
))
return
args
return
args
def
next_file
(
self
):
def
next_file
(
self
,
close_previous
=
True
):
'''
'''
Gets the next file to be scanned (including pending extracted files, if applicable).
Gets the next file to be scanned (including pending extracted files, if applicable).
Also re/initializes self.status.
Also re/initializes self.status.
...
@@ -337,20 +337,21 @@ class Module(object):
...
@@ -337,20 +337,21 @@ class Module(object):
fp
=
None
fp
=
None
# Ensure files are close to prevent IOError (too many open files)
# Ensure files are close to prevent IOError (too many open files)
try
:
if
close_previous
:
self
.
previous_next_file_fp
.
close
()
try
:
except
KeyboardInterrupt
as
e
:
self
.
previous_next_file_fp
.
close
()
raise
e
except
KeyboardInterrupt
as
e
:
except
Exception
:
raise
e
pass
except
Exception
:
pass
# Add any pending extracted files to the target_files list and reset the extractor's pending file list
# Add any pending extracted files to the target_files list and reset the extractor's pending file list
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
:
if
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
# to files that need to be opened for scanning.
# to files that need to be opened for scanning.
if
isinstance
(
next_target_file
,
binwalk
.
core
.
common
.
BlockFile
):
if
isinstance
(
next_target_file
,
binwalk
.
core
.
common
.
BlockFile
):
...
@@ -362,7 +363,7 @@ class Module(object):
...
@@ -362,7 +363,7 @@ class Module(object):
self
.
status
.
total
=
fp
.
length
self
.
status
.
total
=
fp
.
length
if
fp
is
not
None
:
if
fp
is
not
None
:
self
.
current_target_file_name
=
fp
.
name
self
.
current_target_file_name
=
fp
.
name
else
:
else
:
self
.
current_target_file_name
=
None
self
.
current_target_file_name
=
None
...
@@ -435,7 +436,7 @@ class Module(object):
...
@@ -435,7 +436,7 @@ class Module(object):
e
.
module
=
self
.
__class__
.
__name__
e
.
module
=
self
.
__class__
.
__name__
self
.
errors
.
append
(
e
)
self
.
errors
.
append
(
e
)
if
e
.
exception
:
if
e
.
exception
:
sys
.
stderr
.
write
(
"
\n
"
+
e
.
module
+
" Exception: "
+
str
(
e
.
exception
)
+
"
\n
"
)
sys
.
stderr
.
write
(
"
\n
"
+
e
.
module
+
" Exception: "
+
str
(
e
.
exception
)
+
"
\n
"
)
sys
.
stderr
.
write
(
"-"
*
exception_header_width
+
"
\n
"
)
sys
.
stderr
.
write
(
"-"
*
exception_header_width
+
"
\n
"
)
...
@@ -457,7 +458,7 @@ class Module(object):
...
@@ -457,7 +458,7 @@ class Module(object):
self
.
config
.
display
.
header
(
*
self
.
HEADER
,
file_name
=
self
.
current_target_file_name
)
self
.
config
.
display
.
header
(
*
self
.
HEADER
,
file_name
=
self
.
current_target_file_name
)
elif
self
.
HEADER
:
elif
self
.
HEADER
:
self
.
config
.
display
.
header
(
self
.
HEADER
,
file_name
=
self
.
current_target_file_name
)
self
.
config
.
display
.
header
(
self
.
HEADER
,
file_name
=
self
.
current_target_file_name
)
def
footer
(
self
):
def
footer
(
self
):
'''
'''
Displays the scan footer.
Displays the scan footer.
...
@@ -465,7 +466,7 @@ class Module(object):
...
@@ -465,7 +466,7 @@ class Module(object):
Returns None.
Returns None.
'''
'''
self
.
config
.
display
.
footer
()
self
.
config
.
display
.
footer
()
def
main
(
self
,
parent
):
def
main
(
self
,
parent
):
'''
'''
Responsible for calling self.init, initializing self.config.display, and calling self.run.
Responsible for calling self.init, initializing self.config.display, and calling self.run.
...
@@ -504,7 +505,7 @@ class Module(object):
...
@@ -504,7 +505,7 @@ class Module(object):
except
Exception
as
e
:
except
Exception
as
e
:
self
.
error
(
exception
=
e
)
self
.
error
(
exception
=
e
)
return
False
return
False
self
.
_plugins_pre_scan
()
self
.
_plugins_pre_scan
()
try
:
try
:
...
@@ -628,7 +629,7 @@ class Modules(object):
...
@@ -628,7 +629,7 @@ class Modules(object):
for
module_option
in
module
.
CLI
:
for
module_option
in
module
.
CLI
:
if
module_option
.
long
:
if
module_option
.
long
:
long_opt
=
'--'
+
module_option
.
long
long_opt
=
'--'
+
module_option
.
long
if
module_option
.
dtype
:
if
module_option
.
dtype
:
optargs
=
"=<
%
s>"
%
module_option
.
dtype
optargs
=
"=<
%
s>"
%
module_option
.
dtype
else
:
else
:
...
@@ -685,13 +686,13 @@ class Modules(object):
...
@@ -685,13 +686,13 @@ class Modules(object):
self
.
loaded_modules
[
module
]
=
obj
self
.
loaded_modules
[
module
]
=
obj
return
obj
return
obj
def
load
(
self
,
module
,
kwargs
=
{}):
def
load
(
self
,
module
,
kwargs
=
{}):
argv
=
self
.
argv
(
module
,
argv
=
self
.
arguments
)
argv
=
self
.
argv
(
module
,
argv
=
self
.
arguments
)
argv
.
update
(
kwargs
)
argv
.
update
(
kwargs
)
argv
.
update
(
self
.
dependencies
(
module
,
argv
[
'enabled'
]))
argv
.
update
(
self
.
dependencies
(
module
,
argv
[
'enabled'
]))
return
module
(
**
argv
)
return
module
(
**
argv
)
def
dependencies
(
self
,
module
,
module_enabled
):
def
dependencies
(
self
,
module
,
module_enabled
):
import
binwalk.modules
import
binwalk.modules
attributes
=
{}
attributes
=
{}
...
@@ -703,7 +704,7 @@ class Modules(object):
...
@@ -703,7 +704,7 @@ class Modules(object):
dependency
.
module
=
getattr
(
binwalk
.
modules
,
dependency
.
name
)
dependency
.
module
=
getattr
(
binwalk
.
modules
,
dependency
.
name
)
else
:
else
:
raise
ModuleException
(
"
%
s depends on
%
s which was not found in binwalk.modules.__init__.py
\n
"
%
(
str
(
module
),
dependency
.
name
))
raise
ModuleException
(
"
%
s depends on
%
s which was not found in binwalk.modules.__init__.py
\n
"
%
(
str
(
module
),
dependency
.
name
))
# No recursive dependencies, thanks
# No recursive dependencies, thanks
if
dependency
.
module
==
module
:
if
dependency
.
module
==
module
:
continue
continue
...
@@ -716,7 +717,7 @@ class Modules(object):
...
@@ -716,7 +717,7 @@ class Modules(object):
# set any custom kwargs for those dependencies.
# set any custom kwargs for those dependencies.
if
module_enabled
or
not
dependency
.
kwargs
:
if
module_enabled
or
not
dependency
.
kwargs
:
depobj
=
self
.
run
(
dependency
.
module
,
dependency
=
True
,
kwargs
=
dependency
.
kwargs
)
depobj
=
self
.
run
(
dependency
.
module
,
dependency
=
True
,
kwargs
=
dependency
.
kwargs
)
# If a dependency failed, consider this a non-recoverable error and raise an exception
# If a dependency failed, consider this a non-recoverable error and raise an exception
if
depobj
.
errors
:
if
depobj
.
errors
:
raise
ModuleException
(
"Failed to load "
+
dependency
.
name
+
" module"
)
raise
ModuleException
(
"Failed to load "
+
dependency
.
name
+
" module"
)
...
@@ -728,7 +729,7 @@ class Modules(object):
...
@@ -728,7 +729,7 @@ class Modules(object):
def
argv
(
self
,
module
,
argv
=
sys
.
argv
[
1
:]):
def
argv
(
self
,
module
,
argv
=
sys
.
argv
[
1
:]):
'''
'''
Processes argv for any options specific to the specified module.
Processes argv for any options specific to the specified module.
@module - The module to process argv for.
@module - The module to process argv for.
@argv - A list of command line arguments (excluding argv[0]).
@argv - A list of command line arguments (excluding argv[0]).
...
@@ -787,7 +788,7 @@ class Modules(object):
...
@@ -787,7 +788,7 @@ class Modules(object):
# Loop through all the kwargs for this command line option
# Loop through all the kwargs for this command line option
for
(
name
,
default_value
)
in
iterator
(
module_option
.
kwargs
):
for
(
name
,
default_value
)
in
iterator
(
module_option
.
kwargs
):
# If this kwarg has not been previously processed, or if its priority is equal to or
# If this kwarg has not been previously processed, or if its priority is equal to or
# greater than the previously processed kwarg's priority, then let's process it.
# greater than the previously processed kwarg's priority, then let's process it.
if
not
has_key
(
last_priority
,
name
)
or
last_priority
[
name
]
<=
module_option
.
priority
:
if
not
has_key
(
last_priority
,
name
)
or
last_priority
[
name
]
<=
module_option
.
priority
:
...
@@ -804,7 +805,7 @@ class Modules(object):
...
@@ -804,7 +805,7 @@ class Modules(object):
binwalk
.
core
.
common
.
debug
(
"
%
s ::
%
s =>
%
s"
%
(
module
.
TITLE
,
str
(
argv
),
str
(
kwargs
)))
binwalk
.
core
.
common
.
debug
(
"
%
s ::
%
s =>
%
s"
%
(
module
.
TITLE
,
str
(
argv
),
str
(
kwargs
)))
return
kwargs
return
kwargs
def
kwargs
(
self
,
obj
,
kwargs
):
def
kwargs
(
self
,
obj
,
kwargs
):
'''
'''
Processes a module's kwargs. All modules should use this for kwarg processing.
Processes a module's kwargs. All modules should use this for kwarg processing.
...
...
src/binwalk/modules/hexdiff.py
View file @
858eaab5
...
@@ -46,7 +46,7 @@ class HexDiff(Module):
...
@@ -46,7 +46,7 @@ class HexDiff(Module):
kwargs
=
{
'terse'
:
True
},
kwargs
=
{
'terse'
:
True
},
description
=
'Diff all files, but only display a hex dump of the first file'
),
description
=
'Diff all files, but only display a hex dump of the first file'
),
]
]
KWARGS
=
[
KWARGS
=
[
Kwarg
(
name
=
'show_red'
,
default
=
True
),
Kwarg
(
name
=
'show_red'
,
default
=
True
),
Kwarg
(
name
=
'show_blue'
,
default
=
True
),
Kwarg
(
name
=
'show_blue'
,
default
=
True
),
...
@@ -57,7 +57,7 @@ class HexDiff(Module):
...
@@ -57,7 +57,7 @@ class HexDiff(Module):
RESULT_FORMAT
=
"
%
s
\n
"
RESULT_FORMAT
=
"
%
s
\n
"
RESULT
=
[
'display'
]
RESULT
=
[
'display'
]
def
_no_colorize
(
self
,
c
,
color
=
"red"
,
bold
=
True
):
def
_no_colorize
(
self
,
c
,
color
=
"red"
,
bold
=
True
):
return
c
return
c
...
@@ -107,10 +107,10 @@ class HexDiff(Module):
...
@@ -107,10 +107,10 @@ class HexDiff(Module):
break
break
hexbyte
=
self
.
colorize
(
"
%.2
X"
%
ord
(
byte
),
color
)
hexbyte
=
self
.
colorize
(
"
%.2
X"
%
ord
(
byte
),
color
)
if
byte
not
in
string
.
printable
or
byte
in
string
.
whitespace
:
if
byte
not
in
string
.
printable
or
byte
in
string
.
whitespace
:
byte
=
"."
byte
=
"."
asciibyte
=
self
.
colorize
(
byte
,
color
)
asciibyte
=
self
.
colorize
(
byte
,
color
)
return
(
hexbyte
,
asciibyte
)
return
(
hexbyte
,
asciibyte
)
...
@@ -164,13 +164,13 @@ class HexDiff(Module):
...
@@ -164,13 +164,13 @@ class HexDiff(Module):
else
:
else
:
display
=
self
.
CUSTOM_DISPLAY_FORMAT
%
(
offset
,
line
)
display
=
self
.
CUSTOM_DISPLAY_FORMAT
%
(
offset
,
line
)
sep_count
+=
1
sep_count
+=
1
if
line
!=
self
.
SKIPPED_LINE
or
last_line
!=
line
:
if
line
!=
self
.
SKIPPED_LINE
or
last_line
!=
line
:
self
.
result
(
offset
=
offset
,
description
=
line
,
display
=
display
)
self
.
result
(
offset
=
offset
,
description
=
line
,
display
=
display
)
last_line
=
line
last_line
=
line
loop_count
+=
1
loop_count
+=
1
def
init
(
self
):
def
init
(
self
):
# Disable the invalid description auto-filtering feature.
# Disable the invalid description auto-filtering feature.
# This will not affect our own validation.
# This will not affect our own validation.
...
@@ -185,7 +185,13 @@ class HexDiff(Module):
...
@@ -185,7 +185,13 @@ class HexDiff(Module):
self
.
block
=
self
.
DEFAULT_BLOCK_SIZE
self
.
block
=
self
.
DEFAULT_BLOCK_SIZE
# Build a list of files to hexdiff
# Build a list of files to hexdiff
self
.
hex_target_files
=
[
x
for
x
in
iter
(
self
.
next_file
,
None
)]
self
.
hex_target_files
=
[]
while
True
:
f
=
self
.
next_file
(
close_previous
=
False
)
if
not
f
:
break
else
:
self
.
hex_target_files
.
append
(
f
)
# Build the header format string
# Build the header format string
header_width
=
(
self
.
block
*
4
)
+
2
header_width
=
(
self
.
block
*
4
)
+
2
...
...
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