mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-09 11:17:38 +02:00
Initial imlementation of a mapping from volatility config trees to Argparse arguments.
This commit is contained in:
@@ -5,7 +5,7 @@ Created on 7 May 2013
|
||||
"""
|
||||
import re
|
||||
|
||||
from volatility.framework.interfaces.config import GenericRequirement, ConfigGroup
|
||||
from volatility.framework.interfaces.config import GenericRequirement, ConfigurationGroup
|
||||
|
||||
# Intentionally reimport namespace_join so it's accessible from the main config module
|
||||
from volatility.framework.interfaces.config import namespace_join
|
||||
|
||||
@@ -39,7 +39,7 @@ class LayerFactory(validity.ValidityRoutines, list):
|
||||
groups = []
|
||||
for index in range(len(self)):
|
||||
modifier = self[index]
|
||||
group = config.ConfigGroup(modifier.__name__ + str(index))
|
||||
group = config.ConfigurationGroup(modifier.__name__ + str(index))
|
||||
for req in modifier.requirements():
|
||||
group.add_item(req)
|
||||
groups.append(group)
|
||||
@@ -76,7 +76,7 @@ class Context(interfaces.context.ContextInterface):
|
||||
interfaces.context.ContextInterface.__init__(self)
|
||||
self._symbol_space = symbols.SymbolSpace(natives)
|
||||
self._memory = layers.Memory()
|
||||
self._config = config.ConfigGroup(name = 'volatility')
|
||||
self._config = config.ConfigurationGroup(name = 'volatility')
|
||||
|
||||
# ## Symbol Space Functions
|
||||
|
||||
@@ -87,8 +87,8 @@ class Context(interfaces.context.ContextInterface):
|
||||
|
||||
@config.setter
|
||||
def config(self, value):
|
||||
if not isinstance(value, config.ConfigGroup):
|
||||
raise TypeError("Configuration must of type ConfigGroup")
|
||||
if not isinstance(value, config.ConfigurationGroup):
|
||||
raise TypeError("Configuration must of type ConfigurationGroup")
|
||||
self._config = value
|
||||
|
||||
@property
|
||||
@@ -129,4 +129,4 @@ class Context(interfaces.context.ContextInterface):
|
||||
object_template.update_vol(**arguments)
|
||||
return object_template(context = self,
|
||||
object_info = interfaces.objects.ObjectInformation(layer_name = layer_name,
|
||||
offset = offset))
|
||||
offset = offset))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user