Initial imlementation of a mapping from volatility config trees to Argparse arguments.

This commit is contained in:
Mike Auty
2015-09-28 00:57:06 +01:00
parent 813750c81e
commit 897d8bd574
8 changed files with 78 additions and 36 deletions
+1 -1
View File
@@ -7,4 +7,4 @@ Created on 12 Apr 2013
# Import the submodules we want people to be able to use without importing them themselves
# This will also avoid namespace issues, because people can use interfaces.layers to
# avoid clashing with the layers package
from volatility.framework.interfaces import layers, symbols, context, objects, plugins, renderers
from volatility.framework.interfaces import config, context, layers, objects, plugins, renderers, symbols
+14 -15
View File
@@ -15,7 +15,7 @@ def namespace_join(pathlist):
class ConfigurationItem(validity.ValidityRoutines):
"""Class to distinguish configuration elements from everything else"""
def __init__(self, name, optional = False):
def __init__(self, name, optional):
validity.ValidityRoutines.__init__(self)
self._type_check(name, str)
if NAMESPACE_DIVIDER in name:
@@ -28,18 +28,18 @@ class ConfigurationItem(validity.ValidityRoutines):
"""The name of the Option."""
return self._name
@property
def optional(self):
"""Whether the option is required for or not"""
return self._optional
@abstractmethod
def validate(self, context):
"""Validates the currently set value"""
pass
@property
def optional(self):
"""Whether the option is required for or not"""
return self._optional
class ConfigGroup(ConfigurationItem, collections.abc.Mapping):
class ConfigurationGroup(ConfigurationItem, collections.abc.Mapping):
"""Class to hold and provide a namespace for plugins and core options"""
def __init__(self, name):
@@ -48,11 +48,11 @@ class ConfigGroup(ConfigurationItem, collections.abc.Mapping):
def add_item(self, item, namespace = None):
if not isinstance(item, ConfigurationItem):
raise TypeError("Only ConfigurationItem objects can be added to a ConfigGroup")
raise TypeError("Only ConfigurationItem objects can be added to a ConfigurationGroup")
if namespace:
ns_split = namespace.split(NAMESPACE_DIVIDER)
if ns_split[0] not in self:
self._namespace[ns_split[0]] = ConfigGroup(ns_split[0])
self._namespace[ns_split[0]] = ConfigurationGroup(ns_split[0])
return self._namespace[ns_split[0]].add_item(item, namespace_join(ns_split[1:]))
self._namespace[item.name] = item
@@ -91,13 +91,12 @@ class ConfigGroup(ConfigurationItem, collections.abc.Mapping):
class GenericRequirement(ConfigurationItem, metaclass = ABCMeta):
"""Class to handle a single specific configuration option"""
def __init__(self, name, description = None, default = None, optional = False):
def __init__(self, name, description = None, default = None, optional = None):
"""Creates a new option"""
ConfigurationItem.__init__(self, name)
ConfigurationItem.__init__(self, name, optional)
self._default = default
self._description = description
self._value = None
self._optional = optional
@property
def value(self):
@@ -112,9 +111,9 @@ class GenericRequirement(ConfigurationItem, metaclass = ABCMeta):
self._value = data
@property
def optional(self):
"""Whether the option is required for or not"""
return self._optional
def default(self):
"""Returns the default value if one is set"""
return self._default
@property
def description(self):
+2 -3
View File
@@ -5,9 +5,10 @@ Created on 6 May 2013
"""
from abc import abstractmethod, ABCMeta
from volatility.framework import validity, config
from volatility.framework import validity
from volatility.framework.interfaces import context as interfaces_context
#
# Plugins
# - Take in relevant number of TranslationLayers (of specified type)
@@ -48,7 +49,6 @@ class PluginInterface(validity.ValidityRoutines, metaclass = ABCMeta):
def validate_inputs(self):
for option in self.requirements():
if not option.optional:
print("Validate", option.name)
option.validate_input(self.config.get_value(option.name), self.context)
@abstractmethod
@@ -61,7 +61,6 @@ class PluginInterface(validity.ValidityRoutines, metaclass = ABCMeta):
:rtype: TreeGrid
"""
# TODO: Needs to say what it can/can't handle (validate context)
# TODO: Needs to offer available options'
# TODO: Figure out how to handle global config options