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
9fc088e0
Commit
9fc088e0
authored
Nov 05, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixes and code cleanup in magic.py
parent
9557e518
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
14 deletions
+32
-14
magic.py
src/binwalk/core/magic.py
+32
-14
No files found.
src/binwalk/core/magic.py
View file @
9fc088e0
import
re
import
re
import
time
import
struct
import
struct
import
datetime
import
datetime
import
binwalk.core.compat
import
binwalk.core.compat
...
@@ -7,14 +6,10 @@ import binwalk.core.compat
...
@@ -7,14 +6,10 @@ import binwalk.core.compat
class
ParserException
(
Exception
):
class
ParserException
(
Exception
):
pass
pass
class
GenericContainer
(
object
):
class
SignatureTag
(
object
):
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
for
(
k
,
v
)
in
binwalk
.
core
.
compat
.
iterator
(
kwargs
):
for
(
k
,
v
)
in
binwalk
.
core
.
compat
.
iterator
(
kwargs
):
setattr
(
self
,
k
,
v
)
setattr
(
self
,
k
,
v
)
class
DataType
(
GenericContainer
):
pass
class
SignatureTag
(
GenericContainer
):
pass
class
SignatureLine
(
object
):
class
SignatureLine
(
object
):
...
@@ -204,10 +199,35 @@ class Magic(object):
...
@@ -204,10 +199,35 @@ class Magic(object):
'''
'''
self
.
data
=
""
self
.
data
=
""
self
.
signatures
=
[]
self
.
signatures
=
[]
self
.
show_invalid
=
invalid
self
.
show_invalid
=
invalid
self
.
includes
=
[
re
.
compile
(
x
)
for
x
in
include
]
self
.
excludes
=
[
re
.
compile
(
x
)
for
x
in
exclude
]
self
.
bspace
=
re
.
compile
(
".
\\\\
b"
)
self
.
bspace
=
re
.
compile
(
".
\\\\
b"
)
self
.
printable
=
re
.
compile
(
"[ -~]*"
)
self
.
printable
=
re
.
compile
(
"[ -~]*"
)
def
filtered
(
self
,
text
):
filtered
=
None
for
include
in
self
.
includes
:
if
include
.
match
(
text
):
filtered
=
False
break
if
self
.
includes
and
filtered
==
None
:
return
True
for
exclude
in
self
.
excludes
:
if
exclude
.
match
(
text
):
filtered
=
True
break
if
filtered
==
None
:
filtered
=
False
return
filtered
def
parse
(
self
,
signature
,
offset
):
def
parse
(
self
,
signature
,
offset
):
description
=
[]
description
=
[]
max_line_level
=
0
max_line_level
=
0
...
@@ -309,7 +329,6 @@ class Magic(object):
...
@@ -309,7 +329,6 @@ class Magic(object):
return
tags
return
tags
def
scan
(
self
,
data
,
dlen
=
None
):
def
scan
(
self
,
data
,
dlen
=
None
):
sigs
=
{}
results
=
[]
results
=
[]
self
.
data
=
data
self
.
data
=
data
...
@@ -318,17 +337,14 @@ class Magic(object):
...
@@ -318,17 +337,14 @@ class Magic(object):
dlen
=
len
(
self
.
data
)
dlen
=
len
(
self
.
data
)
for
signature
in
self
.
signatures
:
for
signature
in
self
.
signatures
:
offset
=
set
([(
match
.
start
()
-
signature
.
offset
)
for
match
in
signature
.
regex
.
finditer
(
self
.
data
)
if
(
match
.
start
()
-
signature
.
offset
)
>=
0
and
(
match
.
start
()
-
signature
.
offset
)
<=
dlen
])
for
match
in
signature
.
regex
.
finditer
(
self
.
data
):
sigs
[
signature
]
=
offset
offset
=
match
.
start
()
-
signature
.
offset
if
offset
>=
0
and
offset
<=
dlen
:
for
(
signature
,
offsets
)
in
binwalk
.
core
.
compat
.
iterator
(
sigs
):
for
offset
in
offsets
:
tags
=
self
.
parse
(
signature
,
offset
)
tags
=
self
.
parse
(
signature
,
offset
)
if
not
tags
[
'invalid'
]
or
self
.
show_invalid
:
if
not
tags
[
'invalid'
]
or
self
.
show_invalid
:
results
.
append
(
SignatureResult
(
**
tags
))
results
.
append
(
SignatureResult
(
**
tags
))
if
not
self
.
show_invalid
:
break
results
.
sort
(
key
=
lambda
x
:
x
.
offset
,
reverse
=
False
)
return
results
return
results
def
load
(
self
,
fname
):
def
load
(
self
,
fname
):
...
@@ -349,6 +365,7 @@ class Magic(object):
...
@@ -349,6 +365,7 @@ class Magic(object):
sigline
=
SignatureLine
(
line
)
sigline
=
SignatureLine
(
line
)
if
sigline
.
level
==
0
:
if
sigline
.
level
==
0
:
if
signature
:
if
signature
:
if
not
self
.
filtered
(
signature
.
lines
[
0
]
.
format
):
self
.
signatures
.
append
(
signature
)
self
.
signatures
.
append
(
signature
)
signature
=
Signature
(
sigline
)
signature
=
Signature
(
sigline
)
elif
signature
:
elif
signature
:
...
@@ -357,6 +374,7 @@ class Magic(object):
...
@@ -357,6 +374,7 @@ class Magic(object):
raise
ParserException
(
"Invalid signature line: '
%
s'"
%
line
)
raise
ParserException
(
"Invalid signature line: '
%
s'"
%
line
)
if
signature
:
if
signature
:
if
not
self
.
filtered
(
signature
.
lines
[
0
]
.
format
):
self
.
signatures
.
append
(
signature
)
self
.
signatures
.
append
(
signature
)
fp
.
close
()
fp
.
close
()
...
...
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