mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-11 20:27:38 +02:00
Rework config system yet again, and start filling in some of the requirements.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import collections.abc
|
||||
|
||||
from volatility.framework import validity
|
||||
|
||||
@@ -6,15 +7,69 @@ from volatility.framework import validity
|
||||
__author__ = 'mike'
|
||||
|
||||
|
||||
class GenericRequirement(validity.ValidityRoutines, metaclass = ABCMeta):
|
||||
class ConfigurationItem(validity.ValidityRoutines):
|
||||
"""Class to distinguish configuration elements from everything else"""
|
||||
namespace_divider = "."
|
||||
|
||||
def __init__(self, name):
|
||||
validity.ValidityRoutines.__init__(self)
|
||||
self._type_check(name, str)
|
||||
if self.namespace_divider in name:
|
||||
raise ValueError("Name cannot contain the namespace divider (" + self.namespace_divider + ")")
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""The name of the Option."""
|
||||
return self._name
|
||||
|
||||
|
||||
class ConfigGroup(ConfigurationItem, collections.abc.Mapping):
|
||||
"""Class to hold and provide a namespace for plugins and core options"""
|
||||
def __init__(self, name):
|
||||
ConfigurationItem.__init__(self, name)
|
||||
self._namespace = {}
|
||||
|
||||
def add_item(self, item, namespace = None):
|
||||
if not isinstance(item, ConfigurationItem):
|
||||
raise TypeError("Only ConfigurationItem objects can be added to a ConfigGroup")
|
||||
if namespace:
|
||||
ns_split = namespace.split(self.namespace_divider)
|
||||
if ns_split[0] not in self:
|
||||
self._namespace[ns_split[0]] == ConfigGroup(ns_split[0])
|
||||
return self._namespace[ns_split[0]].add_item(self, item, self.namespace_divider.join(ns_split[1:]))
|
||||
self._namespace[item.name] = item
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._namespace)
|
||||
|
||||
def __getitem__(self, item):
|
||||
self._type_check(item, str)
|
||||
item_split = item.split(self.namespace_divider)
|
||||
if len(item_split) > 1:
|
||||
return self._namespace[item_split[0]][self.namespace_divider.join(item_split[1:])]
|
||||
# Let namespace produce the index error if necessary
|
||||
return self._namespace[item_split[0]]
|
||||
|
||||
def __contains__(self, item):
|
||||
item_split = item.split(self.namespace_divider)
|
||||
if len(item_split) > 1:
|
||||
if item_split[0] in self._namespace:
|
||||
return self.namespace_divider.join(item_split[1:]) in self._namespace[item_split[0]]
|
||||
else:
|
||||
return False
|
||||
return item in self._namespace
|
||||
|
||||
def __len__(self):
|
||||
return len(self._namespace)
|
||||
|
||||
class GenericRequirement(ConfigurationItem, metaclass = ABCMeta):
|
||||
"""Class to handle a single specific configuration option"""
|
||||
|
||||
def __init__(self, name, description = None, default = None, optional = False):
|
||||
"""Creates a new option"""
|
||||
validity.ValidityRoutines.__init__(self)
|
||||
ConfigurationItem.__init__(self, name)
|
||||
self._default = default
|
||||
self._type_check(name, str)
|
||||
self._name = name
|
||||
self._description = description
|
||||
self._value = None
|
||||
self._optional = optional
|
||||
@@ -36,11 +91,6 @@ class GenericRequirement(validity.ValidityRoutines, metaclass = ABCMeta):
|
||||
"""Whether the option is required for or not"""
|
||||
return self._optional
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""The name of the Option."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
"""A short description of what the Option is designed to affect or achieve."""
|
||||
@@ -55,18 +105,4 @@ class GenericRequirement(validity.ValidityRoutines, metaclass = ABCMeta):
|
||||
|
||||
def validate(self, context):
|
||||
"""Validates the currently set value"""
|
||||
return self.validate_input(self.value, context)
|
||||
|
||||
class ConfigInterface(validity.ValidityRoutines):
|
||||
"""Class to hold and provide a namespace for plugins and core options"""
|
||||
@abstractmethod
|
||||
def add_item(self, namespace, item):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __contains__(self, item):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __len__(self):
|
||||
pass
|
||||
return self.validate_input(self.value, context)
|
||||
@@ -17,6 +17,10 @@ class ContextInterface(object, metaclass = ABCMeta):
|
||||
|
||||
# ## Symbol Space Functions
|
||||
|
||||
@abstractproperty
|
||||
def config(self):
|
||||
"""Returns the configuration object for this context"""
|
||||
|
||||
@abstractproperty
|
||||
def symbol_space(self):
|
||||
"""Returns the symbol_space for the context"""
|
||||
@@ -46,6 +50,12 @@ class ContextInterface(object, metaclass = ABCMeta):
|
||||
|
||||
|
||||
class ContextModifierInterface(object, metaclass = ABCMeta):
|
||||
def __init__(self, namespace):
|
||||
self.namespace = namespace
|
||||
|
||||
def config_get(self, context):
|
||||
return context.config[self.namespace]
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def requirements(cls):
|
||||
|
||||
Reference in New Issue
Block a user