Commit 45486db3 by devttys0

Merge branch 'master' of https://github.com/devttys0/binwalk

parents 14eda44c 3745d7ea
......@@ -42,8 +42,17 @@ class Option(object):
elif self.type in [int, float, str]:
self.dtype = self.type.__name__
else:
self.type = str
self.dtype = str.__name__
def convert(self, value):
if self.type and (self.type.__name__ == self.dtype):
return self.type(value)
elif self.type == list:
return [value]
else:
return value
class Kwarg(object):
'''
A container class allowing modules to specify their expected __init__ kwarg(s).
......@@ -734,7 +743,7 @@ class Modules(object):
elif module_option.type is list:
parser_kwargs['action'] = ListActionParser
parser.short_to_long[module_option.short] = module_option.long
parser_kwargs['nargs'] = '+'
#parser_kwargs['nargs'] = '+'
parser.add_argument(*parser_args, **parser_kwargs)
......@@ -765,30 +774,36 @@ class Modules(object):
# If the specified type for these kwargs is None, just set the kwarg to its specified default value.
# Else, set it to the value specified from the user.
if module_option.type is not None:
value = args[module_option.long]
else:
value = default_value
# Convert the user-supplied value into the type specified in module_option.type.
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values.
#if module_option.type is not None:
try:
# Only convert the user-supplied value to a specific type if this kwarg's default
# type is the same as the type specified for the module option.
if value != default_value and type(default_value) == module_option.type:
if module_option.type == int:
kwargs[name] = int(value, 0)
elif module_option.type == float:
kwargs[name] = float(value)
else:
kwargs[name] = value
else:
kwargs[name] = value
kwargs[name] = module_option.convert(args[module_option.long])
except KeyboardInterrupt as e:
raise e
except Exception as e:
raise ModuleException("Invalid usage: %s" % str(e))
#else:
#value = default_value
# Convert the user-supplied value into the type specified in module_option.type.
# Do this manually as argparse doesn't seem to be able to handle hexadecimal values.
#try:
# Only convert the user-supplied value to a specific type if this kwarg's default
# type is the same as the type specified for the module option.
# if value != default_value and type(default_value) == module_option.type:
# if module_option.type == int:
# kwargs[name] = int(value, 0)
# elif module_option.type == float:
# kwargs[name] = float(value)
# else:
# kwargs[name] = value
# else:
# kwargs[name] = value
#except KeyboardInterrupt as e:
# raise e
#except Exception as e:
# raise ModuleException("Invalid usage: %s" % str(e))
return kwargs
def kwargs(self, obj, kwargs):
......
......@@ -157,7 +157,7 @@ class Signature(object):
'''
quoted_string = get_quoted_strings(data)
if quoted_string:
data = data.replace(quoted_string, "")
data = data.replace('"' + quoted_string + '"', "")
return data
def one_of_many(self, data, tag):
......@@ -195,7 +195,7 @@ class Signature(object):
if tag.tag in safe_data:
arg = safe_data.split(tag.tag)[1].split(tag.TAG_DELIM_END)[0]
return (data, arg)
def get_math_arg(self, data, tag):
......
......@@ -28,7 +28,7 @@ class Signature(Module):
description='Cast offsets as a given data type (use -y to specify the data type / endianess)'),
Option(short='m',
long='magic',
kwargs={'magic_files' : []},
kwargs={'enabled' : True, 'magic_files' : []},
type=list,
dtype='file',
description='Specify a custom magic file to use'),
......
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