Commit 338d94a4 by devttys0

Updated usage, removed --update

parent 778ee6f5
...@@ -24,7 +24,6 @@ class ModuleOption(object): ...@@ -24,7 +24,6 @@ class ModuleOption(object):
@short - The short option to use (optional). @short - The short option to use (optional).
@long - The long option to use (if None, this option will not be displayed in help output). @long - The long option to use (if None, this option will not be displayed in help output).
@type - The accepted data type (one of: io.FileIO/argparse.FileType/binwalk.common.BlockFile, list, str, int, float). @type - The accepted data type (one of: io.FileIO/argparse.FileType/binwalk.common.BlockFile, list, str, int, float).
@dtype - The accepted data type, as displayed in the help output.
Returns None. Returns None.
''' '''
...@@ -37,8 +36,13 @@ class ModuleOption(object): ...@@ -37,8 +36,13 @@ class ModuleOption(object):
self.type = type self.type = type
self.dtype = str(dtype) self.dtype = str(dtype)
if not self.dtype and self.type: if not self.dtype:
self.dtype = str(self.type) if self.type in [io.FileIO, argparse.FileType, binwalk.common.BlockFile]:
self.dtype = 'file'
elif self.type in [int, float, str]:
self.dtype = self.type.__name__
else:
self.dtype = str.__name__
class ModuleKwarg(object): class ModuleKwarg(object):
''' '''
...@@ -394,7 +398,7 @@ class Modules(object): ...@@ -394,7 +398,7 @@ class Modules(object):
long_opt = '--' + module_option.long long_opt = '--' + module_option.long
if module_option.nargs > 0: if module_option.nargs > 0:
optargs = "=%s" % module_option.dtype optargs = "=<%s>" % module_option.dtype
else: else:
optargs = "" optargs = ""
......
import os import os
import sys import sys
import argparse
import binwalk.common import binwalk.common
import binwalk.module import binwalk.module
import binwalk.config import binwalk.config
...@@ -33,6 +34,7 @@ class Configuration(binwalk.module.Module): ...@@ -33,6 +34,7 @@ class Configuration(binwalk.module.Module):
binwalk.module.ModuleOption(long='log', binwalk.module.ModuleOption(long='log',
short='f', short='f',
nargs=1, nargs=1,
type=argparse.FileType,
kwargs={'log_file' : None}, kwargs={'log_file' : None},
description='Log results to file'), description='Log results to file'),
binwalk.module.ModuleOption(long='csv', binwalk.module.ModuleOption(long='csv',
...@@ -64,10 +66,6 @@ class Configuration(binwalk.module.Module): ...@@ -64,10 +66,6 @@ class Configuration(binwalk.module.Module):
short=None, short=None,
type=binwalk.common.BlockFile, type=binwalk.common.BlockFile,
kwargs={'files' : []}), kwargs={'files' : []}),
binwalk.module.ModuleOption(short='u',
long='update',
kwargs={'do_update' : True},
description='Update magic signature files'),
] ]
KWARGS = [ KWARGS = [
...@@ -82,7 +80,6 @@ class Configuration(binwalk.module.Module): ...@@ -82,7 +80,6 @@ class Configuration(binwalk.module.Module):
binwalk.module.ModuleKwarg(name='skip_unopened', default=False), binwalk.module.ModuleKwarg(name='skip_unopened', default=False),
binwalk.module.ModuleKwarg(name='files', default=[]), binwalk.module.ModuleKwarg(name='files', default=[]),
binwalk.module.ModuleKwarg(name='show_help', default=False), binwalk.module.ModuleKwarg(name='show_help', default=False),
binwalk.module.ModuleKwarg(name='do_update', default=False),
] ]
def load(self): def load(self):
...@@ -99,10 +96,6 @@ class Configuration(binwalk.module.Module): ...@@ -99,10 +96,6 @@ class Configuration(binwalk.module.Module):
binwalk.module.show_help() binwalk.module.show_help()
sys.exit(0) sys.exit(0)
if self.do_update:
Update(self.verbose).update()
sys.exit(0)
self._open_target_files() self._open_target_files()
self._set_verbosity() self._set_verbosity()
...@@ -157,120 +150,3 @@ class Configuration(binwalk.module.Module): ...@@ -157,120 +150,3 @@ class Configuration(binwalk.module.Module):
plural = '' plural = ''
raise Exception("Failed to open %d file%s for scanning" % (failed_open_count, plural)) raise Exception("Failed to open %d file%s for scanning" % (failed_open_count, plural))
class Update(object):
'''
Class for updating binwalk configuration and signatures files from the subversion trunk.
Example usage:
from binwalk import Update
Update().update()
'''
BASE_URL = "https://raw.github.com/devttys0/binwalk/master/src/binwalk/"
MAGIC_PREFIX = "magic/"
CONFIG_PREFIX = "config/"
def __init__(self, verbose):
'''
Class constructor.
@verbose - Verbose flag.
Returns None.
'''
self.verbose = verbose
self.config = Config()
def update(self):
'''
Updates all system wide signatures and config files.
Returns None.
'''
self.update_binwalk()
self.update_bincast()
self.update_binarch()
self.update_extract()
self.update_zlib()
self.update_compressd()
def _do_update_from_git(self, prefix, fname):
'''
Updates the specified file to the latest version of that file in SVN.
@prefix - The URL subdirectory where the file is located.
@fname - The name of the file to update.
Returns None.
'''
# Get the local http proxy, if any
# csoban.kesmarki
proxy_url = os.getenv('HTTP_PROXY')
if proxy_url:
proxy_support = urllib2.ProxyHandler({'http' : proxy_url})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
url = self.BASE_URL + prefix + fname
try:
if self.verbose:
print("Fetching %s..." % url)
data = urllib2.urlopen(url).read()
open(self.config.paths['system'][fname], "wb").write(data)
except KeyboardInterrupt as e:
raise e
except Exception as e:
raise Exception("Update._do_update_from_git failed to update file '%s': %s" % (url, str(e)))
def update_binwalk(self):
'''
Updates the binwalk signature file.
Returns None.
'''
self._do_update_from_git(self.MAGIC_PREFIX, self.config.BINWALK_MAGIC_FILE)
def update_bincast(self):
'''
Updates the bincast signature file.
Returns None.
'''
self._do_update_from_git(self.MAGIC_PREFIX, self.config.BINCAST_MAGIC_FILE)
def update_binarch(self):
'''
Updates the binarch signature file.
Returns None.
'''
self._do_update_from_git(self.MAGIC_PREFIX, self.config.BINARCH_MAGIC_FILE)
def update_zlib(self):
'''
Updates the zlib signature file.
Returns None.
'''
self._do_update_from_git(self.MAGIC_PREFIX, self.config.ZLIB_MAGIC_FILE)
def update_compressd(self):
'''
Updates the compress'd signature file.
Returns None.
'''
self._do_update_from_git(self.MAGIC_PREFIX, self.config.COMPRESSD_MAGIC_FILE)
def update_extract(self):
'''
Updates the extract.conf file.
Returns None.
'''
self._do_update_from_git(self.CONFIG_PREFIX, self.config.EXTRACT_FILE)
...@@ -19,7 +19,7 @@ class Signature(binwalk.module.Module): ...@@ -19,7 +19,7 @@ class Signature(binwalk.module.Module):
nargs=1, nargs=1,
kwargs={'magic_files' : []}, kwargs={'magic_files' : []},
type=[], type=[],
dtype=str, 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