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
99b8048f
Commit
99b8048f
authored
Nov 17, 2013
by
heffnercj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic scan runs in python3, but no signatures are loaded
parent
60b3873b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
15 deletions
+44
-15
__init__.py
src/binwalk/__init__.py
+4
-4
compat.py
src/binwalk/compat.py
+31
-3
entropy.py
src/binwalk/entropy.py
+1
-1
parser.py
src/binwalk/parser.py
+5
-4
smartsignature.py
src/binwalk/smartsignature.py
+1
-1
smartstrings.py
src/binwalk/smartstrings.py
+2
-2
No files found.
src/binwalk/__init__.py
View file @
99b8048f
...
@@ -183,7 +183,7 @@ class Binwalk(object):
...
@@ -183,7 +183,7 @@ class Binwalk(object):
# Parse the magic file(s) and initialize libmagic
# Parse the magic file(s) and initialize libmagic
self
.
mfile
=
self
.
parser
.
parse
(
self
.
magic_files
)
self
.
mfile
=
self
.
parser
.
parse
(
self
.
magic_files
)
self
.
magic
=
magic
.
open
(
self
.
flags
)
self
.
magic
=
magic
.
open
(
self
.
flags
)
self
.
magic
.
load
(
s
elf
.
mfile
)
self
.
magic
.
load
(
s
tr2bytes
(
self
.
mfile
)
)
# Once the temporary magic file is loaded into libmagic, we don't need it anymore; delete the temp file
# Once the temporary magic file is loaded into libmagic, we don't need it anymore; delete the temp file
self
.
parser
.
rm_magic_file
()
self
.
parser
.
rm_magic_file
()
...
@@ -610,7 +610,7 @@ class Binwalk(object):
...
@@ -610,7 +610,7 @@ class Binwalk(object):
callback
(
results_offset
,
results
)
callback
(
results_offset
,
results
)
# If a relative jump offset was specified, update the absolute jump_offset variable
# If a relative jump offset was specified, update the absolute jump_offset variable
if
smart
.
has_key
(
'jump'
)
and
smart
[
'jump'
]
>
0
:
if
has_key
(
smart
,
'jump'
)
and
smart
[
'jump'
]
>
0
:
jump_offset
=
results_offset
+
smart
[
'jump'
]
jump_offset
=
results_offset
+
smart
[
'jump'
]
# Track the total number of bytes scanned
# Track the total number of bytes scanned
...
@@ -621,7 +621,7 @@ class Binwalk(object):
...
@@ -621,7 +621,7 @@ class Binwalk(object):
offset
=
0
offset
=
0
# Sort the results before returning them
# Sort the results before returning them
scan_items
=
scan_results
.
items
(
)
scan_items
=
list
(
scan_results
.
items
()
)
scan_items
.
sort
()
scan_items
.
sort
()
# Do delayed extraction, if specified.
# Do delayed extraction, if specified.
...
@@ -654,7 +654,7 @@ class Binwalk(object):
...
@@ -654,7 +654,7 @@ class Binwalk(object):
Returns None.
Returns None.
'''
'''
for
(
new_file_name
,
new_data
)
in
iterator
(
new
):
for
(
new_file_name
,
new_data
)
in
iterator
(
new
):
if
not
results
.
has_key
(
new_file_name
):
if
not
has_key
(
results
,
new_file_name
):
results
[
new_file_name
]
=
new_data
results
[
new_file_name
]
=
new_data
else
:
else
:
for
i
in
range
(
0
,
len
(
new_data
)):
for
i
in
range
(
0
,
len
(
new_data
)):
...
...
src/binwalk/compat.py
View file @
99b8048f
...
@@ -10,11 +10,39 @@ if sys.version_info.major > 2:
...
@@ -10,11 +10,39 @@ if sys.version_info.major > 2:
else
:
else
:
import
urllib2
import
urllib2
def
iterator
(
obj
):
def
iterator
(
dictionary
):
'''
'''
For cross compatibility between Python 2 and Python 3 dictionaries.
For cross compatibility between Python 2 and Python 3 dictionaries.
'''
'''
if
sys
.
version_info
.
major
>
2
:
if
sys
.
version_info
.
major
>
2
:
return
obj
.
items
()
return
dictionary
.
items
()
else
:
else
:
return
obj
.
iteritems
()
return
dictionary
.
iteritems
()
def
has_key
(
dictionary
,
key
):
'''
For cross compatibility between Python 2 and Python 3 dictionaries.
'''
if
sys
.
version_info
.
major
>
2
:
return
key
in
dictionary
else
:
return
dictionary
.
has_key
(
key
)
def
str2bytes
(
string
):
'''
For cross compatibility between Python 2 and Python 3 strings.
'''
if
sys
.
version_info
.
major
>
2
:
return
bytes
(
string
,
'utf-8'
)
else
:
return
string
def
string_decode
(
string
):
'''
For cross compatibility between Python 2 and Python 3 strings.
'''
if
sys
.
version_info
.
major
>
2
:
return
bytes
(
string
,
'utf-8'
)
.
decode
(
'unicode_escape'
)
else
:
return
string
.
decode
(
'string_escape'
)
src/binwalk/entropy.py
View file @
99b8048f
...
@@ -52,7 +52,7 @@ class PlotEntropy(object):
...
@@ -52,7 +52,7 @@ class PlotEntropy(object):
label
=
None
label
=
None
description
=
results
[
0
][
'description'
]
.
split
(
','
)[
0
]
description
=
results
[
0
][
'description'
]
.
split
(
','
)[
0
]
if
not
color_mappings
.
has_key
(
description
):
if
not
has_key
(
color_mappings
,
description
):
if
show_legend
:
if
show_legend
:
label
=
description
label
=
description
...
...
src/binwalk/parser.py
View file @
99b8048f
import
io
import
re
import
re
import
os.path
import
os.path
import
tempfile
import
tempfile
...
@@ -139,7 +140,7 @@ class MagicParser:
...
@@ -139,7 +140,7 @@ class MagicParser:
line_count
=
0
line_count
=
0
try
:
try
:
for
line
in
open
(
file_name
)
.
readlines
():
for
line
in
io
.
FileIO
(
file_name
)
.
readlines
():
line_count
+=
1
line_count
+=
1
# Check if this is the first line of a signature entry
# Check if this is the first line of a signature entry
...
@@ -152,7 +153,7 @@ class MagicParser:
...
@@ -152,7 +153,7 @@ class MagicParser:
include
=
True
include
=
True
self
.
signature_count
+=
1
self
.
signature_count
+=
1
if
not
self
.
signatures
.
has_key
(
entry
[
'offset'
]):
if
not
has_key
(
self
.
signatures
,
entry
[
'offset'
]):
self
.
signatures
[
entry
[
'offset'
]]
=
[]
self
.
signatures
[
entry
[
'offset'
]]
=
[]
if
entry
[
'condition'
]
not
in
self
.
signatures
[
entry
[
'offset'
]]:
if
entry
[
'condition'
]
not
in
self
.
signatures
[
entry
[
'offset'
]]:
...
@@ -190,7 +191,7 @@ class MagicParser:
...
@@ -190,7 +191,7 @@ class MagicParser:
# Quick and dirty pre-filter. We are only concerned with the first line of a
# Quick and dirty pre-filter. We are only concerned with the first line of a
# signature, which will always start with a number. Make sure the first byte of
# signature, which will always start with a number. Make sure the first byte of
# the line is a number; if not, don't process.
# the line is a number; if not, don't process.
if
line
[:
1
]
<
'0'
or
line
[:
1
]
>
'9'
:
if
str
(
line
[:
1
])
<
'0'
or
str
(
line
[:
1
])
>
'9'
:
return
None
return
None
try
:
try
:
...
@@ -201,7 +202,7 @@ class MagicParser:
...
@@ -201,7 +202,7 @@ class MagicParser:
entry
[
'offset'
]
=
line_parts
[
0
]
entry
[
'offset'
]
=
line_parts
[
0
]
entry
[
'type'
]
=
line_parts
[
1
]
entry
[
'type'
]
=
line_parts
[
1
]
# The condition line may contain escaped sequences, so be sure to decode it properly.
# The condition line may contain escaped sequences, so be sure to decode it properly.
entry
[
'condition'
]
=
line_parts
[
2
]
.
decode
(
'string_escape'
)
entry
[
'condition'
]
=
string_decode
(
line_parts
[
2
]
)
entry
[
'description'
]
=
' '
.
join
(
line_parts
[
3
:])
entry
[
'description'
]
=
' '
.
join
(
line_parts
[
3
:])
except
Exception
as
e
:
except
Exception
as
e
:
raise
Exception
(
"
%
s ::
%
s"
,
(
str
(
e
),
line
))
raise
Exception
(
"
%
s ::
%
s"
,
(
str
(
e
),
line
))
...
...
src/binwalk/smartsignature.py
View file @
99b8048f
...
@@ -170,7 +170,7 @@ class SmartSignature:
...
@@ -170,7 +170,7 @@ class SmartSignature:
'''
'''
arg
=
''
arg
=
''
if
self
.
KEYWORDS
.
has_key
(
keyword
)
and
self
.
KEYWORDS
[
keyword
]
in
data
:
if
has_key
(
self
.
KEYWORDS
,
keyword
)
and
self
.
KEYWORDS
[
keyword
]
in
data
:
arg
=
data
.
split
(
self
.
KEYWORDS
[
keyword
])[
1
]
.
split
(
self
.
KEYWORD_DELIM_END
)[
0
]
arg
=
data
.
split
(
self
.
KEYWORDS
[
keyword
])[
1
]
.
split
(
self
.
KEYWORD_DELIM_END
)[
0
]
return
arg
return
arg
...
...
src/binwalk/smartstrings.py
View file @
99b8048f
...
@@ -109,7 +109,7 @@ class FileStrings(object):
...
@@ -109,7 +109,7 @@ class FileStrings(object):
offset
=
self
.
total_read
+
self
.
start
offset
=
self
.
total_read
+
self
.
start
# Ignore blocks which have a higher than average or higher than MAX_ENTROPY entropy
# Ignore blocks which have a higher than average or higher than MAX_ENTROPY entropy
while
self
.
entropy
.
has_key
(
offset
):
while
has_key
(
self
.
entropy
,
offset
):
# Don't ignore blocks that border on an entropy rising/falling edge
# Don't ignore blocks that border on an entropy rising/falling edge
try
:
try
:
if
self
.
entropy
[
offset
-
self
.
block
]
<=
self
.
MAX_ENTROPY
:
if
self
.
entropy
[
offset
-
self
.
block
]
<=
self
.
MAX_ENTROPY
:
...
@@ -179,7 +179,7 @@ class FileStrings(object):
...
@@ -179,7 +179,7 @@ class FileStrings(object):
Returns True if bracketed, False if not.
Returns True if bracketed, False if not.
'''
'''
return
self
.
BRACKETED
.
has_key
(
data
[
0
])
and
data
.
endswith
(
self
.
BRACKETED
[
data
[
0
]])
return
has_key
(
self
.
BRACKETED
,
data
[
0
])
and
data
.
endswith
(
self
.
BRACKETED
[
data
[
0
]])
def
_non_alpha_count
(
self
,
data
):
def
_non_alpha_count
(
self
,
data
):
'''
'''
...
...
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