Commit b8d6b8d9 by devttys0

Added support for complex operators in type fields

parent 5a6a8ad0
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment