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-depend
binwalk
Commits
02d96ff3
Commit
02d96ff3
authored
Mar 05, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidated argument type conversion code
parent
9a5a7237
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
20 deletions
+35
-20
module.py
src/binwalk/core/module.py
+34
-19
signature.py
src/binwalk/modules/signature.py
+1
-1
No files found.
src/binwalk/core/module.py
View file @
02d96ff3
...
...
@@ -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
):
...
...
src/binwalk/modules/signature.py
View file @
02d96ff3
...
...
@@ -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'
),
...
...
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