diff --git a/volatility/cli/__init__.py b/volatility/cli/__init__.py index 03e54165a..359e015e3 100644 --- a/volatility/cli/__init__.py +++ b/volatility/cli/__init__.py @@ -4,8 +4,7 @@ import sys import volatility.framework import volatility.plugins -from volatility.framework import automagic, contexts -from volatility.framework.interfaces import configuration as config_interface +from volatility.framework import automagic, contexts, interfaces from volatility.framework.renderers.text import TextRenderer __author__ = 'mike' @@ -44,7 +43,7 @@ class CommandLine(object): # Run the argparser parser.parse_args() - config_path = config_interface.path_join("plugins", plugin.__name__.lower()) + config_path = interfaces.configuration.path_join("plugins", plugin.__name__.lower()) ### # PASS TO UI diff --git a/volatility/framework/automagic/__init__.py b/volatility/framework/automagic/__init__.py index e8e33c725..163fb02ac 100644 --- a/volatility/framework/automagic/__init__.py +++ b/volatility/framework/automagic/__init__.py @@ -1,15 +1,13 @@ import sys -from volatility.framework import class_subclasses, import_files +from volatility.framework import class_subclasses, import_files, interfaces from volatility.framework.configuration import MultiRequirement -from volatility.framework.interfaces import automagic as automagic_interface -from volatility.framework.interfaces.configuration import ConfigurableInterface def available(): """Determine all the available automagic classes""" import_files(sys.modules[__name__]) - return sorted([clazz() for clazz in class_subclasses(automagic_interface.AutomagicInterface)], + return sorted([clazz() for clazz in class_subclasses(interfaces.automagic.AutomagicInterface)], key = lambda x: x.priority) @@ -19,16 +17,17 @@ def run(automagics, context, configurable, config_path = ""): This is where any automagic is allowed to run, and alter the context in order to satisfy/improve all requirements """ for automagic in automagics: - if not isinstance(automagic, automagic_interface.AutomagicInterface): + if not isinstance(automagic, interfaces.automagic.AutomagicInterface): raise TypeError("Automagics must only contain AutomagicInterface subclasses") - if not isinstance(configurable, ConfigurableInterface) and not issubclass(configurable, ConfigurableInterface): + if (not isinstance(configurable, interfaces.configuration.ConfigurableInterface) + and not issubclass(configurable, interfaces.configuration.ConfigurableInterface)): raise TypeError("Automagic operates on configurables only") # TODO: Fix need for top level config element just because we're using a MultiRequirement to group the # configurable's config requirements configurable_class = configurable - if isinstance(configurable, ConfigurableInterface): + if isinstance(configurable, interfaces.configuration.ConfigurableInterface): configurable_class = configurable.__class__ requirement = MultiRequirement(name = configurable_class.__name__.lower()) for req in configurable.get_requirements(): diff --git a/volatility/framework/automagic/construct_layers.py b/volatility/framework/automagic/construct_layers.py index ceff21e62..be7b06f27 100644 --- a/volatility/framework/automagic/construct_layers.py +++ b/volatility/framework/automagic/construct_layers.py @@ -1,11 +1,11 @@ import logging -from volatility.framework.interfaces import automagic as automagic_interface, configuration as config_interface +from volatility.framework import interfaces vollog = logging.getLogger(__name__) -class ConstructionMagic(automagic_interface.AutomagicInterface): +class ConstructionMagic(interfaces.automagic.AutomagicInterface): """Runs through the requirement tree and from the bottom up attempts to construct all TranslationLayerRequirements""" priority = 10 @@ -15,7 +15,7 @@ class ConstructionMagic(automagic_interface.AutomagicInterface): # but also ensures that TranslationLayerRequirements have got the correct subrequirements if their class is populated success = True - subreq_config_path = config_interface.path_join(config_path, requirement.name) + subreq_config_path = interfaces.configuration.path_join(config_path, requirement.name) for subreq in requirement.requirements.values(): self(context, subreq, subreq_config_path) valid = subreq.validate(context, subreq_config_path) @@ -25,7 +25,7 @@ class ConstructionMagic(automagic_interface.AutomagicInterface): success = False if not success: return False - elif isinstance(requirement, config_interface.ConstructableRequirementInterface): + elif isinstance(requirement, interfaces.configuration.ConstructableRequirementInterface): # We know all the subrequirements are filled, so let's populate requirement.construct(context, config_path) return True diff --git a/volatility/framework/automagic/windows.py b/volatility/framework/automagic/windows.py index 05f8110f9..6039c1cd2 100644 --- a/volatility/framework/automagic/windows.py +++ b/volatility/framework/automagic/windows.py @@ -8,7 +8,6 @@ import struct from volatility.framework import automagic, interfaces, layers, validity from volatility.framework.configuration import requirements -from volatility.framework.interfaces import automagic as automagic_interface, configuration as config_interface PAGE_SIZE = 0x1000 @@ -112,7 +111,7 @@ class PageMapScanner(interfaces.layers.ScannerInterface): yield (test, result) -class PageMapOffsetHelper(automagic_interface.AutomagicInterface): +class PageMapOffsetHelper(interfaces.automagic.AutomagicInterface): priority = 20 def __init__(self): @@ -126,14 +125,14 @@ class PageMapOffsetHelper(automagic_interface.AutomagicInterface): def __call__(self, context, requirement, config_path): useful = [] - sub_config_path = config_interface.path_join(config_path, requirement.name) + sub_config_path = interfaces.configuration.path_join(config_path, requirement.name) if isinstance(requirement, requirements.TranslationLayerRequirement): class_req = requirement.requirements["class"] if not class_req.validate(context, sub_config_path): # All the intel spaces require the same kind of parameters, so pick one for the requirements context.config.branch(config_path) automagic.run(context, layers.intel.Intel, - config_interface.path_join(config_path, requirement.name)) + interfaces.configuration.path_join(config_path, requirement.name)) # If a class hasn't been chosen, look through the underlying config for appropriate parameters # If possible run scan and choose an appropriate class @@ -152,7 +151,7 @@ class PageMapOffsetHelper(automagic_interface.AutomagicInterface): # TODO: Convert to scanner framework hits = context.memory[physical_layer].scan(context, PageMapScanner(useful)) for test, dtb in hits: - context.config[config_interface.path_join(sub_config_path, "page_map_offset")] = dtb + context.config[interfaces.configuration.path_join(sub_config_path, "page_map_offset")] = dtb requirement.construct(context, config_path) break else: diff --git a/volatility/framework/configuration/requirements.py b/volatility/framework/configuration/requirements.py index 7e13906b2..dd207a2f8 100644 --- a/volatility/framework/configuration/requirements.py +++ b/volatility/framework/configuration/requirements.py @@ -1,11 +1,11 @@ import logging -from volatility.framework.interfaces import configuration as config_interface +from volatility.framework import interfaces vollog = logging.getLogger(__name__) -class MultiRequirement(config_interface.RequirementInterface): +class MultiRequirement(interfaces.configuration.RequirementInterface): """Class to hold multiple requirements Technically the Interface could handle this, but it's an interface, so this is a concrete implementation @@ -15,7 +15,7 @@ class MultiRequirement(config_interface.RequirementInterface): return self.validate_children(context, config_path) -class InstanceRequirement(config_interface.RequirementInterface): +class InstanceRequirement(interfaces.configuration.RequirementInterface): instance_type = bool def add_requirement(self, requirement): @@ -45,7 +45,7 @@ class BytesRequirement(InstanceRequirement): instance_type = bytes -class TranslationLayerRequirement(config_interface.ConstructableRequirementInterface): +class TranslationLayerRequirement(interfaces.configuration.ConstructableRequirementInterface): """Class maintaining the limitations on what sort of address spaces are acceptable""" def __init__(self, name, description = None, default = None, optional = False): @@ -96,7 +96,7 @@ class TranslationLayerRequirement(config_interface.ConstructableRequirementInter "config_path": config_path, "name": name} - config_path = config_interface.path_join(config_path, self.name) + config_path = interfaces.configuration.path_join(config_path, self.name) if not all([subreq.validate(context, config_path) for subreq in self.requirements.values() if not subreq.optional]): return False @@ -108,7 +108,7 @@ class TranslationLayerRequirement(config_interface.ConstructableRequirementInter return True -class SymbolRequirement(config_interface.ConstructableRequirementInterface): +class SymbolRequirement(interfaces.configuration.ConstructableRequirementInterface): """Class maintaining the limitations on what sort of symbol spaces are acceptable""" def validate(self, context, config_path): @@ -134,7 +134,7 @@ class SymbolRequirement(config_interface.ConstructableRequirementInterface): "config_path": config_path, "name": name} - config_path = config_interface.path_join(config_path, self.name) + config_path = interfaces.configuration.path_join(config_path, self.name) if not all([subreq.validate(context, config_path) for subreq in self.requirements.values() if not subreq.optional]): return False @@ -146,7 +146,7 @@ class SymbolRequirement(config_interface.ConstructableRequirementInterface): return True -class ChoiceRequirement(config_interface.RequirementInterface): +class ChoiceRequirement(interfaces.configuration.RequirementInterface): """Allows one from a choice of strings""" def __init__(self, choices, *args, **kwargs): @@ -164,12 +164,12 @@ class ChoiceRequirement(config_interface.RequirementInterface): return True -class ListRequirement(config_interface.RequirementInterface): +class ListRequirement(interfaces.configuration.RequirementInterface): def __init__(self, element_type, max_elements, min_elements, *args, **kwargs): super().__init__(*args, **kwargs) if isinstance(element_type, ListRequirement): raise TypeError("ListRequirements cannot contain ListRequirements") - self.element_type = self._check_type(element_type, config_interface.RequirementInterface) + self.element_type = self._check_type(element_type, interfaces.configuration.RequirementInterface) self.min_elements = min_elements self.max_elements = max_elements diff --git a/volatility/framework/interfaces/__init__.py b/volatility/framework/interfaces/__init__.py index 0d9c436c8..13a57ffcb 100644 --- a/volatility/framework/interfaces/__init__.py +++ b/volatility/framework/interfaces/__init__.py @@ -7,4 +7,5 @@ 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 configuration, context, layers, objects, plugins, renderers, symbols +from volatility.framework.interfaces import configuration, context, layers, objects, \ + plugins, renderers, symbols, automagic diff --git a/volatility/framework/interfaces/plugins.py b/volatility/framework/interfaces/plugins.py index 401ab04ac..ed3bcc1ae 100644 --- a/volatility/framework/interfaces/plugins.py +++ b/volatility/framework/interfaces/plugins.py @@ -3,10 +3,12 @@ Created on 6 May 2013 @author: mike """ + +# Configuration interfaces must be imported separately, since we're part of interfaces and can't import ourselves from abc import ABCMeta, abstractmethod from volatility.framework import validity -from volatility.framework.interfaces import configuration as configuration_interface, context as context_interface +from volatility.framework.interfaces import configuration as interfaces_configuration # @@ -22,7 +24,7 @@ from volatility.framework.interfaces import configuration as configuration_inter # The plugin accepts the context and modifies as necessary # The plugin runs and produces a TreeGrid output -class PluginInterface(configuration_interface.ConfigurableInterface, validity.ValidityRoutines, metaclass = ABCMeta): +class PluginInterface(interfaces_configuration.ConfigurableInterface, validity.ValidityRoutines, metaclass = ABCMeta): """Class that defines the interface all Plugins must maintain""" def __init__(self, context, config_path):