Commit 45486db3 by devttys0

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

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