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
b5a97bff
Commit
b5a97bff
authored
Nov 30, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added validity check for specified file-size keywords; non-zero magic offsets are now supported.
parent
95eadc29
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
14 deletions
+31
-14
binwalk
src/bin/binwalk
+3
-3
__init__.py
src/binwalk/__init__.py
+12
-5
cmdopts.py
src/binwalk/cmdopts.py
+1
-0
binwalk
src/binwalk/magic/binwalk
+5
-0
parser.py
src/binwalk/parser.py
+5
-6
firmware
src/magic/firmware
+3
-0
images
src/magic/images
+2
-0
No files found.
src/bin/binwalk
View file @
b5a97bff
...
@@ -147,7 +147,7 @@ def main():
...
@@ -147,7 +147,7 @@ def main():
save_plot
=
True
save_plot
=
True
elif
opt
in
(
"-N"
,
"--no-plot"
):
elif
opt
in
(
"-N"
,
"--no-plot"
):
show_plot
=
False
show_plot
=
False
elif
opt
in
(
"-3"
,
"--3D"
):
elif
opt
in
(
"-3"
,
"--3D"
,
"--3d"
):
requested_scans
.
append
(
binwalk
.
Binwalk
.
BINVIS
)
requested_scans
.
append
(
binwalk
.
Binwalk
.
BINVIS
)
elif
opt
in
(
"-E"
,
"--entropy"
):
elif
opt
in
(
"-E"
,
"--entropy"
):
requested_scans
.
append
(
binwalk
.
Binwalk
.
ENTROPY
)
requested_scans
.
append
(
binwalk
.
Binwalk
.
ENTROPY
)
...
@@ -469,8 +469,8 @@ def main():
...
@@ -469,8 +469,8 @@ def main():
pass
pass
except
IOError
:
except
IOError
:
pass
pass
except
Exception
as
e
:
#
except Exception as e:
print
(
"Unexpected error:
%
s"
%
str
(
e
))
#
print("Unexpected error: %s" % str(e))
bwalk
.
cleanup
()
bwalk
.
cleanup
()
...
...
src/binwalk/__init__.py
View file @
b5a97bff
...
@@ -533,7 +533,7 @@ class Binwalk(object):
...
@@ -533,7 +533,7 @@ class Binwalk(object):
# start after the end of dlen.
# start after the end of dlen.
for
candidate
in
self
.
parser
.
find_signature_candidates
(
data
[
i
:
dlen
+
self
.
MAX_SIGNATURE_SIZE
],
(
dlen
-
i
)):
for
candidate
in
self
.
parser
.
find_signature_candidates
(
data
[
i
:
dlen
+
self
.
MAX_SIGNATURE_SIZE
],
(
dlen
-
i
)):
# If a signature specified a jump offset beyond this candidate signature offset, ignore it
# If a
previous
signature specified a jump offset beyond this candidate signature offset, ignore it
if
(
i
+
candidate
+
self
.
total_scanned
)
<
jump_offset
:
if
(
i
+
candidate
+
self
.
total_scanned
)
<
jump_offset
:
continue
continue
...
@@ -570,7 +570,7 @@ class Binwalk(object):
...
@@ -570,7 +570,7 @@ class Binwalk(object):
smart
=
self
.
smart
.
parse
(
magic_result
)
smart
=
self
.
smart
.
parse
(
magic_result
)
# Validate the jump value and check if the response description should be displayed
# Validate the jump value and check if the response description should be displayed
if
s
mart
[
'jump'
]
>
-
1
and
self
.
_should_display
(
smart
):
if
s
elf
.
_is_valid
(
smart
,
candidate
+
i
,
fsize
):
# If multiple results are returned and one of them has smart['jump'] set to a non-zero value,
# If multiple results are returned and one of them has smart['jump'] set to a non-zero value,
# the calculated results offset will be wrong since i will have been incremented. Only set the
# the calculated results offset will be wrong since i will have been incremented. Only set the
# results_offset value when the first match is encountered.
# results_offset value when the first match is encountered.
...
@@ -678,16 +678,23 @@ class Binwalk(object):
...
@@ -678,16 +678,23 @@ class Binwalk(object):
if
not
found_offset
:
if
not
found_offset
:
results
[
new_file_name
]
+=
new_data
results
[
new_file_name
]
+=
new_data
def
_
should_display
(
self
,
result
):
def
_
is_valid
(
self
,
result
,
location
,
file_size
):
'''
'''
Determines if a result string should be displayed to the user or not.
Determines if a result string
is valid and
should be displayed to the user or not.
@result - Result dictionary, as returned by self.smart.parse.
@result - Result dictionary, as returned by self.smart.parse.
@location - The file offset of the result.
@file_size - The total size of the file.
Returns True if the string should be displayed.
Returns True if the string should be displayed.
Returns False if the string should not be displayed.
Returns False if the string should not be displayed.
'''
'''
if
result
[
'invalid'
]
==
True
or
(
self
.
year
and
result
[
'year'
]
>
self
.
year
)
or
(
self
.
epoch
and
result
[
'epoch'
]
>
self
.
epoch
):
if
self
.
filter
.
show_invalid_results
:
return
True
if
result
[
'jump'
]
<
0
or
result
[
'invalid'
]:
return
False
if
((
location
+
result
[
'size'
])
>
file_size
)
or
(
self
.
year
and
result
[
'year'
]
>
self
.
year
)
or
(
self
.
epoch
and
result
[
'epoch'
]
>
self
.
epoch
):
return
False
return
False
desc
=
result
[
'description'
]
desc
=
result
[
'description'
]
...
...
src/binwalk/cmdopts.py
View file @
b5a97bff
...
@@ -8,6 +8,7 @@ import binwalk.config
...
@@ -8,6 +8,7 @@ import binwalk.config
short_options
=
"3AaBbCcdEeGHhIiJkLMNnOPpQqrSTtUuvWwz?D:F:f:g:j:K:o:l:m:R:s:X:x:Y:y:Z:"
short_options
=
"3AaBbCcdEeGHhIiJkLMNnOPpQqrSTtUuvWwz?D:F:f:g:j:K:o:l:m:R:s:X:x:Y:y:Z:"
long_options
=
[
long_options
=
[
"3D"
,
"3D"
,
"3d"
,
"rm"
,
"rm"
,
"help"
,
"help"
,
"green"
,
"green"
,
...
...
src/binwalk/magic/binwalk
View file @
b5a97bff
...
@@ -2072,6 +2072,9 @@
...
@@ -2072,6 +2072,9 @@
>19 string none\n \b, unencrypted
>19 string none\n \b, unencrypted
>19 string AES-256\n \b, encrypted AES-256
>19 string AES-256\n \b, encrypted AES-256
# http://forum.xda-developers.com/showthread.php?p=47818657
0 string imgARMcC Roku aimage SB{offset-adjust:-8}
# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)
# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)
# The second word of TIFF files is the TIFF version number, 42, which has
# The second word of TIFF files is the TIFF version number, 42, which has
# never changed. The TIFF specification recommends testing for it.
# never changed. The TIFF specification recommends testing for it.
...
@@ -2085,6 +2088,8 @@
...
@@ -2085,6 +2088,8 @@
# 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
# 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
#
#
0 string \x89PNG\x0d\x0a\x1a\x0a PNG image
0 string \x89PNG\x0d\x0a\x1a\x0a PNG image
>16 belong 0 invalid
>20 belong 0 invalid
>16 belong x \b, %ld x
>16 belong x \b, %ld x
>20 belong x %ld,
>20 belong x %ld,
>24 byte x %d-bit
>24 byte x %d-bit
...
...
src/binwalk/parser.py
View file @
b5a97bff
...
@@ -255,18 +255,17 @@ class MagicParser:
...
@@ -255,18 +255,17 @@ class MagicParser:
Returns a list of tuples in the format: [(<signature offset>, [signature regex])].
Returns a list of tuples in the format: [(<signature offset>, [signature regex])].
'''
'''
s
ignature_set
=
[]
s
elf
.
signature_set
=
set
()
for
(
offset
,
sigs
)
in
iterator
(
self
.
signatures
):
for
(
offset
,
sigs
)
in
iterator
(
self
.
signatures
):
for
sig
in
sigs
:
for
sig
in
sigs
:
if
sig
==
self
.
WILDCARD
:
if
sig
==
self
.
WILDCARD
:
sig
=
re
.
compile
(
'.'
)
sig
=
re
.
compile
(
'.'
)
else
:
else
:
sig
=
re
.
compile
(
re
.
escape
(
sig
))
sig
=
re
.
compile
(
re
.
escape
(
sig
))
signature_set
.
append
(
sig
)
self
.
signature_set
.
add
((
offset
,
sig
))
self
.
signature_set
=
set
(
signature_set
)
return
self
.
signature_set
return
self
.
signature_set
...
@@ -282,8 +281,8 @@ class MagicParser:
...
@@ -282,8 +281,8 @@ class MagicParser:
'''
'''
candidate_offsets
=
[]
candidate_offsets
=
[]
for
regex
in
self
.
signature_set
:
for
(
offset
,
regex
)
in
self
.
signature_set
:
candidate_offsets
+=
[
match
.
start
()
for
match
in
regex
.
finditer
(
data
)
if
match
.
start
()
<
end
]
candidate_offsets
+=
[
(
match
.
start
()
-
offset
)
for
match
in
regex
.
finditer
(
data
)
if
match
.
start
()
<
end
and
(
match
.
start
()
-
offset
)
>=
0
]
candidate_offsets
=
list
(
set
(
candidate_offsets
))
candidate_offsets
=
list
(
set
(
candidate_offsets
))
candidate_offsets
.
sort
()
candidate_offsets
.
sort
()
...
...
src/magic/firmware
View file @
b5a97bff
...
@@ -445,3 +445,6 @@
...
@@ -445,3 +445,6 @@
>19 string none\n \b, unencrypted
>19 string none\n \b, unencrypted
>19 string AES-256\n \b, encrypted AES-256
>19 string AES-256\n \b, encrypted AES-256
# http://forum.xda-developers.com/showthread.php?p=47818657
0 string imgARMcC Roku aimage SB{offset-adjust:-8}
src/magic/images
View file @
b5a97bff
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
# 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
# 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
#
#
0 string \x89PNG\x0d\x0a\x1a\x0a PNG image
0 string \x89PNG\x0d\x0a\x1a\x0a PNG image
>16 belong 0 invalid
>20 belong 0 invalid
>16 belong x \b, %ld x
>16 belong x \b, %ld x
>20 belong x %ld,
>20 belong x %ld,
>24 byte x %d-bit
>24 byte x %d-bit
...
...
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