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
b8d6b8d9
Commit
b8d6b8d9
authored
Nov 07, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for complex operators in type fields
parent
5a6a8ad0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
23 deletions
+34
-23
magic.py
src/binwalk/core/magic.py
+34
-23
No files found.
src/binwalk/core/magic.py
View file @
b8d6b8d9
...
@@ -60,7 +60,10 @@ class SignatureLine(object):
...
@@ -60,7 +60,10 @@ class SignatureLine(object):
if
operator
in
parts
[
1
]:
if
operator
in
parts
[
1
]:
(
self
.
type
,
self
.
opvalue
)
=
parts
[
1
]
.
split
(
operator
,
1
)
(
self
.
type
,
self
.
opvalue
)
=
parts
[
1
]
.
split
(
operator
,
1
)
self
.
operator
=
operator
self
.
operator
=
operator
try
:
self
.
opvalue
=
int
(
self
.
opvalue
,
0
)
self
.
opvalue
=
int
(
self
.
opvalue
,
0
)
except
ValueError
as
e
:
pass
break
break
if
parts
[
2
][
0
]
in
[
'='
,
'!'
,
'>'
,
'<'
,
'&'
,
'|'
]:
if
parts
[
2
][
0
]
in
[
'='
,
'!'
,
'>'
,
'<'
,
'&'
,
'|'
]:
...
@@ -241,20 +244,10 @@ class Magic(object):
...
@@ -241,20 +244,10 @@ class Magic(object):
return
filtered
return
filtered
def
parse
(
self
,
signature
,
offset
):
def
do_math
(
self
,
offset
,
expression
):
description
=
[]
tag_strlen
=
None
max_line_level
=
0
tags
=
{
'id'
:
signature
.
id
,
'offset'
:
offset
,
'invalid'
:
False
}
for
line
in
signature
.
lines
:
if
line
.
level
<=
max_line_level
:
if
isinstance
(
line
.
offset
,
int
):
line_offset
=
line
.
offset
else
:
# (4.l+12)
# (4.l+12)
if
'.'
in
line
.
offset
:
if
'.'
in
expression
:
(
o
,
t
)
=
line
.
offset
.
split
(
'.'
,
1
)
(
o
,
t
)
=
expression
.
split
(
'.'
,
1
)
o
=
offset
+
int
(
o
.
split
(
'('
,
1
)[
1
],
0
)
o
=
offset
+
int
(
o
.
split
(
'('
,
1
)[
1
],
0
)
t
=
t
[
0
]
t
=
t
[
0
]
...
@@ -272,13 +265,26 @@ class Magic(object):
...
@@ -272,13 +265,26 @@ class Magic(object):
except
struct
.
error
as
e
:
except
struct
.
error
as
e
:
v
=
0
v
=
0
v
=
"(
%
d
%
s"
%
(
v
,
line
.
offset
.
split
(
t
,
1
)[
1
])
v
=
"(
%
d
%
s"
%
(
v
,
expression
.
split
(
t
,
1
)[
1
])
# (32+0x20)
# (32+0x20)
else
:
else
:
v
=
line
.
offset
v
=
expression
#print ("Converted offset '%s' to '%s'" % (line.offset, v))
#print ("Converted offset '%s' to '%s'" % (expression, v))
line_offset
=
binwalk
.
core
.
common
.
MathExpression
(
v
)
.
value
return
binwalk
.
core
.
common
.
MathExpression
(
v
)
.
value
def
parse
(
self
,
signature
,
offset
):
description
=
[]
tag_strlen
=
None
max_line_level
=
0
tags
=
{
'id'
:
signature
.
id
,
'offset'
:
offset
,
'invalid'
:
False
}
for
line
in
signature
.
lines
:
if
line
.
level
<=
max_line_level
:
if
isinstance
(
line
.
offset
,
int
):
line_offset
=
line
.
offset
else
:
line_offset
=
self
.
do_math
(
offset
,
line
.
offset
)
start
=
offset
+
line_offset
start
=
offset
+
line_offset
end
=
start
+
line
.
size
end
=
start
+
line
.
size
...
@@ -299,18 +305,23 @@ class Magic(object):
...
@@ -299,18 +305,23 @@ class Magic(object):
dvalue
=
self
.
data
[
start
:
end
]
dvalue
=
self
.
data
[
start
:
end
]
if
isinstance
(
dvalue
,
int
)
and
line
.
operator
:
if
isinstance
(
dvalue
,
int
)
and
line
.
operator
:
if
isinstance
(
line
.
opvalue
,
int
):
opval
=
line
.
opvalue
else
:
opval
=
self
.
do_math
(
offset
,
line
.
opvalue
)
if
line
.
operator
==
'&'
:
if
line
.
operator
==
'&'
:
dvalue
&=
line
.
opvalue
dvalue
&=
opval
elif
line
.
operator
==
'|'
:
elif
line
.
operator
==
'|'
:
dvalue
|=
line
.
opvalue
dvalue
|=
opval
elif
line
.
operator
==
'*'
:
elif
line
.
operator
==
'*'
:
dvalue
*=
line
.
opvalue
dvalue
*=
opval
elif
line
.
operator
==
'+'
:
elif
line
.
operator
==
'+'
:
dvalue
+=
line
.
opvalue
dvalue
+=
opval
elif
line
.
operator
==
'-'
:
elif
line
.
operator
==
'-'
:
dvalue
-=
line
.
opvalue
dvalue
-=
opval
elif
line
.
operator
==
'/'
:
elif
line
.
operator
==
'/'
:
dvalue
/=
line
.
opvalue
dvalue
/=
opval
if
((
line
.
value
is
None
)
or
if
((
line
.
value
is
None
)
or
(
line
.
condition
==
'='
and
dvalue
==
line
.
value
)
or
(
line
.
condition
==
'='
and
dvalue
==
line
.
value
)
or
...
...
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