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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
20 deletions
+38
-20
magic.py
src/binwalk/core/magic.py
+38
-20
No files found.
src/binwalk/core/magic.py
View file @
9fc088e0
import
re
import
time
import
struct
import
datetime
import
binwalk.core.compat
...
...
@@ -7,14 +6,10 @@ import binwalk.core.compat
class
ParserException
(
Exception
):
pass
class
GenericContainer
(
object
):
class
SignatureTag
(
object
):
def
__init__
(
self
,
**
kwargs
):
for
(
k
,
v
)
in
binwalk
.
core
.
compat
.
iterator
(
kwargs
):
setattr
(
self
,
k
,
v
)
class
DataType
(
GenericContainer
):
pass
class
SignatureTag
(
GenericContainer
):
pass
class
SignatureLine
(
object
):
...
...
@@ -204,10 +199,35 @@ class Magic(object):
'''
self
.
data
=
""
self
.
signatures
=
[]
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
.
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
):
description
=
[]
max_line_level
=
0
...
...
@@ -309,7 +329,6 @@ class Magic(object):
return
tags
def
scan
(
self
,
data
,
dlen
=
None
):
sigs
=
{}
results
=
[]
self
.
data
=
data
...
...
@@ -318,17 +337,14 @@ class Magic(object):
dlen
=
len
(
self
.
data
)
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
])
sigs
[
signature
]
=
offset
for
(
signature
,
offsets
)
in
binwalk
.
core
.
compat
.
iterator
(
sigs
):
for
offset
in
offsets
:
tags
=
self
.
parse
(
signature
,
offset
)
if
not
tags
[
'invalid'
]
or
self
.
show_invalid
:
results
.
append
(
SignatureResult
(
**
tags
))
if
not
self
.
show_invalid
:
break
for
match
in
signature
.
regex
.
finditer
(
self
.
data
):
offset
=
match
.
start
()
-
signature
.
offset
if
offset
>=
0
and
offset
<=
dlen
:
tags
=
self
.
parse
(
signature
,
offset
)
if
not
tags
[
'invalid'
]
or
self
.
show_invalid
:
results
.
append
(
SignatureResult
(
**
tags
))
results
.
sort
(
key
=
lambda
x
:
x
.
offset
,
reverse
=
False
)
return
results
def
load
(
self
,
fname
):
...
...
@@ -349,7 +365,8 @@ class Magic(object):
sigline
=
SignatureLine
(
line
)
if
sigline
.
level
==
0
:
if
signature
:
self
.
signatures
.
append
(
signature
)
if
not
self
.
filtered
(
signature
.
lines
[
0
]
.
format
):
self
.
signatures
.
append
(
signature
)
signature
=
Signature
(
sigline
)
elif
signature
:
signature
.
append
(
sigline
)
...
...
@@ -357,7 +374,8 @@ class Magic(object):
raise
ParserException
(
"Invalid signature line: '
%
s'"
%
line
)
if
signature
:
self
.
signatures
.
append
(
signature
)
if
not
self
.
filtered
(
signature
.
lines
[
0
]
.
format
):
self
.
signatures
.
append
(
signature
)
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