diff --git a/volatility/framework/config.py b/volatility/framework/config.py new file mode 100644 index 000000000..8d8c18612 --- /dev/null +++ b/volatility/framework/config.py @@ -0,0 +1,69 @@ +""" +Created on 7 May 2013 + +@author: mike +""" + +from volatility.framework import validity + +class Option(validity.ValidityRoutines): + """Class to handle a single specific configuration option""" + def __init__(self, name, option_type, definition = None, description = None): + """Creates a new option""" + self._option_type = self.type_check(option_type, type) + self._name = name + self._description = description + self._definition = definition + + @property + def option_type(self): + return self._option_type + + @property + def name(self): + return self._name + + @property + def description(self): + return self._description + + @property + def definition(self): + return self._definition + +class ConfigurationGroup(validity.ValidityRoutines): + """Class to handle configuration groups, contains options""" + + def __init__(self): + self._options = {} + + def __getattr__(self, attr): + """Locates an option within a configurationgroup and returns it""" + if attr in self._options: + return self._options[attr] + + def __setattr__(self, name, value): + if name == '_options': + setattr(self, name, value) + if self.type_check(value, Option): + self._options[name] = value + raise TypeError("Attribute " + name + " must be an Option object") + +class Configuration(validity.ValidityRoutines): + """Class to handle configuration, contains configuration groups""" + + def __init__(self): + self._config_groups = {} + + def __getattr__(self, attr): + """Locates a group within the configuration and returns it""" + if attr in self._config_groups: + return self._config_groups[attr] + raise AttributeError("Attribute " + attr + " not found in the configuration") + + def __setattr__(self, attr, value): + if attr == '_config_groups': + setattr(self, attr, value) + if self.type_check(value, ConfigurationGroup): + self._config_groups[attr] = value + raise TypeError("Attribute " + attr + " must be a ConfigurationGroup") diff --git a/volatility/framework/interfaces/output.py b/volatility/framework/interfaces/output.py deleted file mode 100644 index d80e2882e..000000000 --- a/volatility/framework/interfaces/output.py +++ /dev/null @@ -1,69 +0,0 @@ -from framework import validity -import collections - -__author__ = 'mike' - -class TreeRow(validity.ValidityRoutines): - """Class providing the interface for an individual Row of the TreeGrid""" - def __init__(self, treegrid, values): - self._treegrid = treegrid - if not isinstance(treegrid, TreeGrid): - raise TypeError("TreeRow requires treegrid to be a TreeGrid") - self._values = values - if not isinstance(self, TreeGrid): - if not isinstance(values, list): - raise TypeError("Values must be a list of values of the type specified by treegrid.") - treegrid.validate_values(self._values) - else: - self._values = None - self._children = [] - - def add_child(self, child): - """Appends a child to the current Row""" - raise NotImplementedError("Abstract method add_child not implemented.") - - def insert_child(self, child, position): - """Adds a child at the specified position""" - raise NotImplementedError("Abstract method insert_child not implemented") - - def clear(self): - """Removes all children from this row""" - self._children = [] - - @property - def children(self): - """Returns an iterator of the children of the current row""" - for child in self._children: - yield child - -class TreeGrid(TreeRow): - """Class providing the interface for""" - - simple_types = {int, str, float} - - def __init__(self, columns): - """Constructs a TreeGrid object using a specific set of columns - - The TreeGrid itself is a root element, that can have children but no values - - :param columns: An ordered dictionary of column name to column types. - """ - if not isinstance(columns, collections.OrderedDict): - raise TypeError("Columns must be an OrderedDict of column names to column types") - self._columns = columns - - for k in columns: - is_simple_type = False - for t in self.simple_types: - is_simple_type = is_simple_type or issubclass(columns[k], t) - if not is_simple_type: - raise TypeError("One of the column types is not a simple type") - - # We can use the special type None because we're the top level node without values - TreeRow.__init__(self, self, None) - - def validate_values(self, values): - """Takes a list of values and verified them against the column types""" - for i in range(len(self._columns)): - if not isinstance(values[i], self._columns[i]): - raise TypeError("Column type " + str(i) + " is incorrect.") \ No newline at end of file diff --git a/volatility/framework/interfaces/plugins.py b/volatility/framework/interfaces/plugins.py new file mode 100644 index 000000000..9e31c225c --- /dev/null +++ b/volatility/framework/interfaces/plugins.py @@ -0,0 +1,38 @@ +""" +Created on 6 May 2013 + +@author: mike +""" + +from volatility.framework import validity +from volatility.framework.interfaces import context as context_module + + +class PluginInterface(validity.ValidityRoutines): + """Class that defines the interface all Plugins must maintain""" + + def __init__(self, context): + self._context = self.type_check(context, context_module.ContextInterface) + + @property + def context(self): + return self._context + + def establish_context(self): + """Alters the context to ensure the plugin can run""" + raise NotImplementedError("Abstract method establish_context must be overridden by plugins.") + + def plugin_options(self, config_group = None): + """Modifies the passed in ConfigGroup object to contain the required options""" + raise NotImplementedError("Abstract method plugin_options must be overridden by plugins") + + def __call__(self): + """Executes the functionality of the code + + Returns an OutputUI object + """ + + +# Needs to say what it can/can't handle (validate context) +# Needs to offer available options' +# Figure out how to handle global config options diff --git a/volatility/framework/interfaces/renderers.py b/volatility/framework/interfaces/renderers.py new file mode 100644 index 000000000..47af32b17 --- /dev/null +++ b/volatility/framework/interfaces/renderers.py @@ -0,0 +1,81 @@ +from volatility.framework import validity +import collections + +__author__ = 'mike' + +class TreeRow(validity.ValidityRoutines): + """Class providing the interface for an individual Row of the TreeGrid""" + def __init__(self, treegrid, values): + self.type_check(treegrid, TreeGrid) + if not isinstance(self, TreeGrid): + self.type_check(values, list) + treegrid.validate_values(values) + + def add_child(self, child): + """Appends a child to the current Row""" + raise NotImplementedError("Abstract method add_child not implemented.") + + def insert_child(self, child, position): + """Adds a child at the specified position""" + raise NotImplementedError("Abstract method insert_child not implemented.") + + def clear(self): + """Removes all children from this row + + :rtype : None + """ + raise NotImplementedError("Abstract method clear not implemented.") + + @property + def children(self): + """Returns an iterator of the children of the current row + + :rtype : iterator of TreeRows + """ + raise NotImplementedError("Abstract property children not implemented.") + +class TreeGrid(TreeRow): + """Class providing the interface for a TreeGrid (which contains TreeRows)""" + + simple_types = {int, str, float, bytes} + + def __init__(self, columns): + """Constructs a TreeGrid object using a specific set of columns + + The TreeGrid itself is a root element, that can have children but no values + + :param columns: An ordered dictionary of column name to (column types). + """ + self.type_check(columns, collections.OrderedDict) + for k, column in columns.items(): + is_simple_type = False + for t in self.simple_types: + try: + self.class_check(column, t) + is_simple_type = True + except TypeError: + pass + if not is_simple_type: + raise TypeError("Column " + k + "'s type " + column.__class__.__name__ + " is not a simple type") + + # We can use the special type None because we're the top level node without values + TreeRow.__init__(self, self, None) + + def validate_values(self, values): + """Takes a list of values and verifies them against the column types""" + raise NotImplementedError("Abstract method validate_values not implemented.") + +class Renderer(validity.ValidityRoutines): + + def __init__(self, options): + """Accepts an options object to configure the renderers""" + #FIXME: Once the config option objects are in place, put the type_check in place + + @staticmethod + def get_render_options(): + """Returns a list of rendering options""" + raise NotImplementedError("Abstract method get_render_options not implemented.") + + def render(self, grid): + """Takes a grid object and renders it based on the object's preferences""" + raise NotImplementedError("Abstract method render not implemented.") diff --git a/volatility/framework/renderers/__init__.py b/volatility/framework/renderers/__init__.py new file mode 100644 index 000000000..7e2aab912 --- /dev/null +++ b/volatility/framework/renderers/__init__.py @@ -0,0 +1,42 @@ +__author__ = 'mike' + +from volatility.framework.interfaces import renderers as interface + +class TreeRow(interface.TreeRow): + def __init__(self, treegrid, values): + interface.TreeRow.__init__(self, treegrid, values) + self._treegrid = treegrid + self._children = [] + self._values = values + + def add_child(self, child): + """Appends a child to the current Row""" + self.type_check(child, interface.TreeRow) + self._children += [child] + + def insert_child(self, child, position): + """Inserts a child at a specific position in the current Row""" + self.type_check(child, interface.TreeRow) + self._children = self._children[:position] + [child] + self._children[:position] + + def clear(self): + """Removes all children from the current record""" + self._children = [] + + @property + def children(self): + """Returns an iterator of the children of the current row""" + for child in self._children: + yield child + +class TreeGrid(interface.TreeGrid, TreeRow): + def __init__(self, columns): + interface.TreeGrid.__init__(self, columns) + TreeRow.__init__(self, self, None) + self._columns = columns + + def validate_values(self, values): + """Takes a list of values and verified them against the column types""" + for i in range(len(self._columns)): + if not isinstance(values[i], self._columns[i]): + raise TypeError("Column type " + str(i) + " is incorrect.") \ No newline at end of file diff --git a/volatility/framework/renderers/basic.py b/volatility/framework/renderers/basic.py new file mode 100644 index 000000000..abd656b80 --- /dev/null +++ b/volatility/framework/renderers/basic.py @@ -0,0 +1,12 @@ +__author__ = 'mike' + +from volatility.framework.interfaces import renderers as interface + +class TextRenderer(interface.Renderer): + + def __init__(self, options): + interface.Renderer.__init__(self, options) + self._options = options + + def render(self, grid): + """Renders a text grid based on the contents of each element"""