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
55075e57
Commit
55075e57
authored
Jan 08, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed handling of module errors and invalid integer options
parent
bab7c0c3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
57 deletions
+76
-57
INSTALL
INSTALL
+2
-3
common.py
src/binwalk/core/common.py
+2
-1
display.py
src/binwalk/core/display.py
+4
-1
module.py
src/binwalk/core/module.py
+30
-15
binwalk
src/binwalk/magic/binwalk
+0
-0
binwalk
src/scripts/binwalk
+38
-37
No files found.
INSTALL
View file @
55075e57
...
@@ -74,9 +74,8 @@ Most distros don't have pyqtgraph in their default repositories, so it's best to
...
@@ -74,9 +74,8 @@ Most distros don't have pyqtgraph in their default repositories, so it's best to
MANUALLY INSTALLING EXTRACTION UTILITIES
MANUALLY INSTALLING EXTRACTION UTILITIES
-------------------------------------------
-------------------------------------------
Binwalk can automatically invoke external extraction utilities to extract various types of files that it
Binwalk can automatically invoke external extraction utilities to extract various types of files that it may find during
may find during a scan. These utilities are optional, but recommended if you plan on using binwalk's
a scan. These utilities are optional, but recommended if you plan on using binwalk's extraction features.
extraction features.
Most utilities can be installed from your distro's repositories (package names may vary slightly based
Most utilities can be installed from your distro's repositories (package names may vary slightly based
on your particular distro):
on your particular distro):
...
...
src/binwalk/core/common.py
View file @
55075e57
# Common functions.
# Common functions used throughout various parts of binwalk code.
import
io
import
io
import
os
import
os
import
re
import
re
...
...
src/binwalk/core/display.py
View file @
55075e57
...
@@ -5,7 +5,10 @@ import binwalk.core.common
...
@@ -5,7 +5,10 @@ import binwalk.core.common
from
binwalk.core.compat
import
*
from
binwalk.core.compat
import
*
class
Display
(
object
):
class
Display
(
object
):
'''
Class to handle display of output and writing to log files.
This class is instantiated for all modules implicitly and should not need to be invoked directly by most modules.
'''
SCREEN_WIDTH
=
0
SCREEN_WIDTH
=
0
HEADER_WIDTH
=
150
HEADER_WIDTH
=
150
DEFAULT_FORMAT
=
"
%
s
\n
"
DEFAULT_FORMAT
=
"
%
s
\n
"
...
...
src/binwalk/core/module.py
View file @
55075e57
...
@@ -149,7 +149,7 @@ class Module(object):
...
@@ -149,7 +149,7 @@ class Module(object):
attribute
=
'extractor'
),
attribute
=
'extractor'
),
]
]
# A list of
dependenci
es that can be filled in as needed by each individual module.
# A list of
binwalk.core.module.Dependency instanc
es that can be filled in as needed by each individual module.
DEPENDS
=
[]
DEPENDS
=
[]
# Format string for printing the header during a scan.
# Format string for printing the header during a scan.
...
@@ -407,6 +407,11 @@ class Module(object):
...
@@ -407,6 +407,11 @@ class Module(object):
sys
.
stderr
.
write
(
"
\n
"
+
e
.
module
+
" Error: "
+
e
.
description
+
"
\n\n
"
)
sys
.
stderr
.
write
(
"
\n
"
+
e
.
module
+
" Error: "
+
e
.
description
+
"
\n\n
"
)
def
header
(
self
):
def
header
(
self
):
'''
Displays the scan header, as defined by self.HEADER and self.HEADER_FORMAT.
Returns None.
'''
self
.
config
.
display
.
format_strings
(
self
.
HEADER_FORMAT
,
self
.
RESULT_FORMAT
)
self
.
config
.
display
.
format_strings
(
self
.
HEADER_FORMAT
,
self
.
RESULT_FORMAT
)
self
.
config
.
display
.
add_custom_header
(
self
.
VERBOSE_FORMAT
,
self
.
VERBOSE
)
self
.
config
.
display
.
add_custom_header
(
self
.
VERBOSE_FORMAT
,
self
.
VERBOSE
)
...
@@ -416,6 +421,11 @@ class Module(object):
...
@@ -416,6 +421,11 @@ 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
)
def
footer
(
self
):
def
footer
(
self
):
'''
Displays the scan footer.
Returns None.
'''
self
.
config
.
display
.
footer
()
self
.
config
.
display
.
footer
()
def
main
(
self
,
parent
):
def
main
(
self
,
parent
):
...
@@ -720,20 +730,25 @@ class Modules(object):
...
@@ -720,20 +730,25 @@ class Modules(object):
last_priority
[
name
]
=
module_option
.
priority
last_priority
[
name
]
=
module_option
.
priority
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values
if
module_option
.
type
==
int
:
try
:
kwargs
[
name
]
=
int
(
value
,
0
)
if
module_option
.
type
==
int
:
elif
module_option
.
type
==
float
:
kwargs
[
name
]
=
int
(
value
,
0
)
kwargs
[
name
]
=
float
(
value
)
elif
module_option
.
type
==
float
:
elif
module_option
.
type
==
dict
:
kwargs
[
name
]
=
float
(
value
)
if
not
has_key
(
kwargs
,
name
):
elif
module_option
.
type
==
dict
:
kwargs
[
name
]
=
{}
if
not
has_key
(
kwargs
,
name
):
kwargs
[
name
][
len
(
kwargs
[
name
])]
=
value
kwargs
[
name
]
=
{}
elif
module_option
.
type
==
list
:
kwargs
[
name
][
len
(
kwargs
[
name
])]
=
value
if
not
has_key
(
kwargs
,
name
):
elif
module_option
.
type
==
list
:
kwargs
[
name
]
=
[]
if
not
has_key
(
kwargs
,
name
):
kwargs
[
name
]
.
append
(
value
)
kwargs
[
name
]
=
[]
else
:
kwargs
[
name
]
.
append
(
value
)
kwargs
[
name
]
=
value
else
:
kwargs
[
name
]
=
value
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
as
e
:
raise
ModuleException
(
"Invalid usage:
%
s"
%
str
(
e
))
return
kwargs
return
kwargs
...
...
src/binwalk/magic/binwalk
View file @
55075e57
No preview for this file type
src/scripts/binwalk
View file @
55075e57
...
@@ -6,47 +6,48 @@ from threading import Thread
...
@@ -6,47 +6,48 @@ from threading import Thread
from
binwalk.core.compat
import
user_input
from
binwalk.core.compat
import
user_input
def
display_status
(
m
):
def
display_status
(
m
):
# Display the current scan progress when the enter key is pressed.
# Display the current scan progress when the enter key is pressed.
while
True
:
while
True
:
try
:
try
:
user_input
()
user_input
()
sys
.
stderr
.
write
(
"Progress:
%.2
f
%%
(
%
d /
%
d)
\n\n
"
%
(((
float
(
m
.
status
.
completed
)
/
float
(
m
.
status
.
total
))
*
100
),
m
.
status
.
completed
,
m
.
status
.
total
))
sys
.
stderr
.
write
(
"Progress:
%.2
f
%%
(
%
d /
%
d)
\n\n
"
%
(((
float
(
m
.
status
.
completed
)
/
float
(
m
.
status
.
total
))
*
100
),
m
.
status
.
completed
,
m
.
status
.
total
))
except
KeyboardInterrupt
as
e
:
except
KeyboardInterrupt
as
e
:
raise
e
raise
e
except
Exception
:
except
Exception
:
pass
pass
def
usage
(
modules
):
def
usage
(
modules
):
sys
.
stderr
.
write
(
modules
.
help
())
sys
.
stderr
.
write
(
modules
.
help
())
sys
.
exit
(
1
)
sys
.
exit
(
1
)
def
main
():
def
main
():
modules
=
binwalk
.
Modules
()
modules
=
binwalk
.
Modules
()
# Start the display_status function as a daemon thread.
# Start the display_status function as a daemon thread.
t
=
Thread
(
target
=
display_status
,
args
=
(
modules
,))
t
=
Thread
(
target
=
display_status
,
args
=
(
modules
,))
t
.
setDaemon
(
True
)
t
.
setDaemon
(
True
)
t
.
start
()
t
.
start
()
try
:
try
:
if
len
(
sys
.
argv
)
==
1
:
if
len
(
sys
.
argv
)
==
1
:
usage
(
modules
)
usage
(
modules
)
elif
not
modules
.
execute
():
elif
not
modules
.
execute
():
modules
.
execute
(
*
sys
.
argv
[
1
:],
signature
=
True
)
modules
.
execute
(
*
sys
.
argv
[
1
:],
signature
=
True
)
except
binwalk
.
ModuleException
as
e
:
except
binwalk
.
ModuleException
as
e
:
sys
.
exit
(
1
)
sys
.
stderr
.
write
(
str
(
e
)
+
'
\n
'
)
sys
.
exit
(
1
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
try
:
try
:
# Special options for profiling the code. For debug use only.
# Special options for profiling the code. For debug use only.
if
'--profile'
in
sys
.
argv
:
if
'--profile'
in
sys
.
argv
:
import
cProfile
import
cProfile
sys
.
argv
.
pop
(
sys
.
argv
.
index
(
'--profile'
))
sys
.
argv
.
pop
(
sys
.
argv
.
index
(
'--profile'
))
cProfile
.
run
(
'main()'
)
cProfile
.
run
(
'main()'
)
else
:
else
:
main
()
main
()
except
IOError
:
except
IOError
:
pass
pass
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
sys
.
stdout
.
write
(
"
\n
"
)
sys
.
stdout
.
write
(
"
\n
"
)
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