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
6cf71c2d
Commit
6cf71c2d
authored
Nov 17, 2013
by
heffnercj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Signatures now loaded, but filters / validators are broken (bytes decoding issues)
parent
99b8048f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
compat.py
src/binwalk/compat.py
+11
-2
parser.py
src/binwalk/parser.py
+3
-2
No files found.
src/binwalk/compat.py
View file @
6cf71c2d
...
@@ -32,11 +32,20 @@ def str2bytes(string):
...
@@ -32,11 +32,20 @@ def str2bytes(string):
'''
'''
For cross compatibility between Python 2 and Python 3 strings.
For cross compatibility between Python 2 and Python 3 strings.
'''
'''
if
sys
.
version_info
.
major
>
2
:
if
isinstance
(
string
,
type
(
''
))
and
sys
.
version_info
.
major
>
2
:
return
bytes
(
string
,
'
utf-8
'
)
return
bytes
(
string
,
'
ascii
'
)
else
:
else
:
return
string
return
string
def
bytes2str
(
bs
):
'''
For cross compatibility between Python 2 and Python 3 strings.
'''
if
isinstance
(
bs
,
type
(
b
''
))
and
sys
.
version_info
.
major
>
2
:
return
bs
.
decode
(
'ascii'
)
else
:
return
bs
def
string_decode
(
string
):
def
string_decode
(
string
):
'''
'''
For cross compatibility between Python 2 and Python 3 strings.
For cross compatibility between Python 2 and Python 3 strings.
...
...
src/binwalk/parser.py
View file @
6cf71c2d
...
@@ -191,14 +191,14 @@ class MagicParser:
...
@@ -191,14 +191,14 @@ 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
str
(
line
[:
1
])
<
'0'
or
str
(
line
[:
1
])
>
'9'
:
if
bytes2str
(
line
[:
1
])
<
'0'
or
bytes2
str
(
line
[:
1
])
>
'9'
:
return
None
return
None
try
:
try
:
# Split the line into white-space separated parts.
# Split the line into white-space separated parts.
# For this to work properly, replace escaped spaces ('\ ') with '\x20'.
# For this to work properly, replace escaped spaces ('\ ') with '\x20'.
# This means the same thing, but doesn't confuse split().
# This means the same thing, but doesn't confuse split().
line_parts
=
line
.
replace
(
'
\\
'
,
'
\\
x20'
)
.
split
()
line_parts
=
bytes2str
(
line
)
.
replace
(
'
\\
'
,
'
\\
x20'
)
.
split
()
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.
...
@@ -281,6 +281,7 @@ class MagicParser:
...
@@ -281,6 +281,7 @@ class MagicParser:
Returns an ordered list of offsets inside of data at which candidate offsets were found.
Returns an ordered list of offsets inside of data at which candidate offsets were found.
'''
'''
candidate_offsets
=
[]
candidate_offsets
=
[]
data
=
bytes2str
(
data
)
for
regex
in
self
.
signature_set
:
for
regex
in
self
.
signature_set
:
candidate_offsets
+=
[
match
.
start
()
for
match
in
regex
.
finditer
(
data
)
if
match
.
start
()
<
end
]
candidate_offsets
+=
[
match
.
start
()
for
match
in
regex
.
finditer
(
data
)
if
match
.
start
()
<
end
]
...
...
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