Add in more interfaces (and fix additional errors now that type information is available).

This commit is contained in:
Mike Auty
2017-12-13 20:48:52 +00:00
parent 5536412a5e
commit 50b60c0df6
8 changed files with 169 additions and 102 deletions
+32 -11
View File
@@ -7,7 +7,7 @@ notably the object constructor function, `object`, which will construct a symbol
import copy
from abc import ABCMeta, abstractmethod
from volatility.framework import validity
from volatility.framework import validity, interfaces
class ContextInterface(object, metaclass = ABCMeta):
@@ -16,19 +16,19 @@ class ContextInterface(object, metaclass = ABCMeta):
This interface is present to avoid import dependency cycles.
"""
def __init__(self):
def __init__(self) -> None:
"""Initializes the context with a symbol_space"""
# ## Symbol Space Functions
@property
@abstractmethod
def config(self):
def config(self) -> 'interfaces.configuration.HierarchicalDict':
"""Returns the configuration object for this context"""
@property
@abstractmethod
def symbol_space(self):
def symbol_space(self) -> 'interfaces.symbols.SymbolSpaceInterface':
"""Returns the symbol_space for the context
This object must support the :class:`~volatility.framework.interfaces.symbols.SymbolSpaceInterface`
@@ -38,11 +38,11 @@ class ContextInterface(object, metaclass = ABCMeta):
@property
@abstractmethod
def memory(self):
def memory(self) -> 'interfaces.layers.Memory':
"""Returns the memory object for the context"""
raise NotImplementedError("Memory has not been implemented.")
def add_layer(self, layer):
def add_layer(self, layer: 'interfaces.layers.DataLayerInterface'):
"""Adds a named translation layer to the context memory
:param layer: Layer object to be added to the context memory
@@ -53,7 +53,11 @@ class ContextInterface(object, metaclass = ABCMeta):
# ## Object Factory Functions
@abstractmethod
def object(self, symbol, layer_name, offset):
def object(self,
symbol: 'interfaces.objects.Template',
layer_name: str,
offset: int,
**arguments):
"""Object factory, takes a context, symbol, offset and optional layer_name
Looks up the layer_name in the context, finds the object template based on the symbol,
@@ -62,14 +66,17 @@ class ContextInterface(object, metaclass = ABCMeta):
Returns a fully constructed object
"""
def clone(self):
def clone(self) -> 'ContextInterface':
"""Produce a clone of the context (and configuration), allowing modifications to be made without affecting
any mutable objects in the original.
Memory constraints may become an issue for this function depending on how much is actually stored in the context"""
return copy.deepcopy(self)
def module(self, module_name, layer_name, offset):
def module(self,
module_name: str,
layer_name: str,
offset: int) -> 'Module':
"""Create a module object """
@@ -79,7 +86,11 @@ class Module(validity.ValidityRoutines, metaclass = ABCMeta):
This object is OS-independent.
"""
def __init__(self, context, module_name, layer_name, offset):
def __init__(self,
context: ContextInterface,
module_name: str,
layer_name: str,
offset: int) -> None:
self._context = self._check_type(context, ContextInterface)
self._module_name = self._check_type(module_name, str)
self._layer_name = self._check_type(layer_name, str)
@@ -87,5 +98,15 @@ class Module(validity.ValidityRoutines, metaclass = ABCMeta):
super().__init__()
@abstractmethod
def object(self, symbol_name = None, type_name = None, offset = None):
def object(self,
symbol_name: str = None,
type_name: str = None,
offset: int = None,
**kwargs) -> 'interfaces.objects.ObjectInterface':
"""Returns an object created using the symbol_table and layer_name of the Module"""
def get_type(self, name: str) -> 'interfaces.objects.Template':
"""Returns a type from the module"""
def get_symbol(self, name: str) -> 'interfaces.symbols.Symbol':
"""Returns a symbol from the module"""