mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-29 13:04:58 +02:00
Start building a dependency resolver for translation layers.
This commit is contained in:
@@ -4,15 +4,13 @@ Created on 7 May 2013
|
||||
@author: mike
|
||||
"""
|
||||
|
||||
from volatility.framework.interfaces.configuration import ConfigurationSchemaNode, Configurable
|
||||
from volatility.framework.interfaces.configuration import ConfigurationSchemaNode
|
||||
|
||||
|
||||
class InstanceRequirement(ConfigurationSchemaNode):
|
||||
instance_type = bool
|
||||
|
||||
def validate(self, value, _context, valid_children = None):
|
||||
# Child_results can be ignored because no instance class should have children
|
||||
# We don't ban child_results in case someone wants to extend this in some meaningful way
|
||||
def validate(self, value, _context):
|
||||
if not isinstance(value, self.instance_type):
|
||||
raise TypeError(self.name + " input only accepts " + self.instance_type.__name__ + " type")
|
||||
|
||||
@@ -26,7 +24,7 @@ class StringRequirement(InstanceRequirement):
|
||||
instance_type = str
|
||||
|
||||
|
||||
class TranslationLayerRequirement(ConfigurationSchemaNode, Configurable):
|
||||
class TranslationLayerRequirement(ConfigurationSchemaNode):
|
||||
"""Class maintaining the limitations on what sort of address spaces are acceptable"""
|
||||
|
||||
def __init__(self, name, description = None, default = None,
|
||||
@@ -40,19 +38,12 @@ class TranslationLayerRequirement(ConfigurationSchemaNode, Configurable):
|
||||
:return:
|
||||
"""
|
||||
ConfigurationSchemaNode.__init__(name, description, default, optional)
|
||||
Configurable.__init__(self)
|
||||
self._layer_name = layer_name
|
||||
|
||||
@classmethod
|
||||
def get_schema(cls):
|
||||
# Runs through each of the available translation layers, determining what they're capable of,
|
||||
# and adding their requirements (tagged with their class) to a Disjunction config schema node
|
||||
pass
|
||||
|
||||
# TODO: Add requirements: acceptable OSes from the address_space information
|
||||
# TODO: Add requirements: acceptable arches from the available layers
|
||||
|
||||
def validate(self, value, context, valid_children = None):
|
||||
def validate(self, value, context):
|
||||
"""Validate that the value is a valid layer name and that the layer adheres to the requirements"""
|
||||
if not isinstance(value, str):
|
||||
raise TypeError("TranslationLayerRequirements only accepts string labels")
|
||||
@@ -61,8 +52,7 @@ class TranslationLayerRequirement(ConfigurationSchemaNode, Configurable):
|
||||
|
||||
|
||||
class ChoiceRequirement(ConfigurationSchemaNode):
|
||||
"""Allows one from a choice of strings
|
||||
"""
|
||||
"""Allows one from a choice of strings"""
|
||||
|
||||
def __init__(self, choices, *args, **kwargs):
|
||||
ConfigurationSchemaNode.__init__(self, *args, **kwargs)
|
||||
@@ -70,7 +60,7 @@ class ChoiceRequirement(ConfigurationSchemaNode):
|
||||
raise TypeError("ChoiceRequirement takes a list of strings as choices")
|
||||
self._choices = choices
|
||||
|
||||
def validate(self, value, context, valid_children = None):
|
||||
def validate(self, value, context):
|
||||
"""Validates the provided value to ensure it is one of the available choices"""
|
||||
if value not in self._choices:
|
||||
raise ValueError("Value is not within the set of available choices")
|
||||
@@ -85,7 +75,7 @@ class ListRequirement(ConfigurationSchemaNode):
|
||||
self.min_elements = min_elements
|
||||
self.max_elements = max_elements
|
||||
|
||||
def validate(self, value, context, valid_children = None):
|
||||
def validate(self, value, context):
|
||||
"""Check the types on each of the returned values and then call the element type's check for each one"""
|
||||
self._type_check(value, list)
|
||||
if not all([self._type_check(element, self.element_type) for element in value]):
|
||||
@@ -94,35 +84,3 @@ class ListRequirement(ConfigurationSchemaNode):
|
||||
raise TypeError("List option provided more or less elements than allowed.")
|
||||
for element in value:
|
||||
self.element_type.validate(element, context)
|
||||
|
||||
|
||||
class DisjunctionRequirement(ConfigurationSchemaNode):
|
||||
"""Class allowing any of multiple requirements"""
|
||||
|
||||
def __init__(self, requirements, *args, **kwargs):
|
||||
# TODO: Type check requirements to ensure it's a dictionary of requirements
|
||||
ConfigurationSchemaNode.__init__(self, *args, **kwargs)
|
||||
for requirement in requirements:
|
||||
self.add_item(requirement)
|
||||
|
||||
def validate(self, value, context, valid_children = None):
|
||||
if valid_children is None:
|
||||
raise ValueError("A Disjunction requirement cannot exist without children")
|
||||
if not any(valid_children):
|
||||
raise ValueError("No valid children to support the Disjunction Requirement")
|
||||
|
||||
|
||||
class ConjunctionRequirement(ConfigurationSchemaNode):
|
||||
"""Class requiring all of multiple requirements"""
|
||||
|
||||
def __init__(self, requirements, *args, **kwargs):
|
||||
# TODO: Type check requirements to ensure it's a dictionary of requirements
|
||||
ConfigurationSchemaNode.__init__(self, *args, **kwargs)
|
||||
for requirement in requirements:
|
||||
self.add_item(requirement)
|
||||
|
||||
def validate(self, value, context, valid_children = None):
|
||||
if valid_children is None:
|
||||
raise ValueError("A Conjunction requirement cannot exist without children")
|
||||
if not all(valid_children):
|
||||
raise ValueError("An invalid child prevents the Conjunction Requirement")
|
||||
|
||||
Reference in New Issue
Block a user