From 3709143c405849534f86d18d0da0d4f6c3dac5dd Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Fri, 28 Mar 2014 08:47:00 +0000 Subject: [PATCH] Clean-up a few files according to PyCharm's warning system. --- volatility/framework/interfaces/__init__.py | 4 ++-- volatility/framework/interfaces/context.py | 13 ++++++++----- volatility/framework/interfaces/layers.py | 11 ++++++++--- volatility/framework/interfaces/objects.py | 11 ++++++++--- volatility/framework/layers/physical.py | 2 +- volatility/framework/objects/__init__.py | 4 ++-- volatility/framework/symbols/__init__.py | 2 +- volatility/framework/symbols/native.py | 3 ++- 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/volatility/framework/interfaces/__init__.py b/volatility/framework/interfaces/__init__.py index 789142ef3..7fa7e5497 100644 --- a/volatility/framework/interfaces/__init__.py +++ b/volatility/framework/interfaces/__init__.py @@ -1,8 +1,8 @@ -''' +""" Created on 12 Apr 2013 @author: mike -''' +""" # 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 diff --git a/volatility/framework/interfaces/context.py b/volatility/framework/interfaces/context.py index d9f988e73..186f01aaf 100644 --- a/volatility/framework/interfaces/context.py +++ b/volatility/framework/interfaces/context.py @@ -1,26 +1,29 @@ -''' +""" Created on 6 May 2013 @author: mike -''' +""" + class ContextInterface(object): """Class for providing the interface for the Context object""" def __init__(self): - """Intializes the context with a symbol_space""" + """Initializes the context with a symbol_space""" ### Symbol Space Functions @property def symbol_space(self): """Returns the symbol_space for the context""" + raise NotImplementedError("Symbol_space has not been implemented.") ### Memory Functions @property def memory(self): """Returns the memory object for the context""" + raise NotImplementedError("Memory has not been implemented.") def add_layer(self, layer): """Adds a named translation layer to the context memory""" @@ -29,9 +32,9 @@ class ContextInterface(object): ### Object Factory Functions def object(self, symbol, layer_name, offset): - """Object factory, takes a context, symbol, offset and optional layername + """Object factory, takes a context, symbol, offset and optional layer_name - Looks up the layername in the context, finds the object template based on the symbol, + Looks up the layer_name in the context, finds the object template based on the symbol, and constructs an object using the object template on the layer at the offset. Returns a fully constructed object diff --git a/volatility/framework/interfaces/layers.py b/volatility/framework/interfaces/layers.py index c88524d87..4a2ccab4f 100644 --- a/volatility/framework/interfaces/layers.py +++ b/volatility/framework/interfaces/layers.py @@ -1,13 +1,14 @@ -''' +""" Created on 4 May 2013 @author: mike -''' +""" from volatility.framework import validity, exceptions # We can't just import interfaces because we'd have a cycle going from volatility.framework.interfaces import context as context_module + class DataLayerInterface(validity.ValidityRoutines): """A Layer that directly holds data (and does not translate it""" @@ -23,10 +24,12 @@ class DataLayerInterface(validity.ValidityRoutines): @property def maximum_address(self): """Returns the maximum valid address of the space""" + raise NotImplementedError("Maximum Address has not been implemented") @property def minimum_address(self): """Returns the minimum valid address of the space""" + raise NotImplementedError("Minimum Address has not been implemented") def is_valid(self, offset): """Returns a boolean based on whether the offset is valid or not""" @@ -34,7 +37,7 @@ class DataLayerInterface(validity.ValidityRoutines): def read(self, offset, length, pad = False): """Reads an offset for length bytes and returns 'bytes' (not 'str') of length size - If there is a fault of any kind (such as a pagefault), an exception will be thrown + If there is a fault of any kind (such as a page fault), an exception will be thrown unless pad is set, in which case the read errors will be replaced by null characters. """ @@ -45,6 +48,7 @@ class DataLayerInterface(validity.ValidityRoutines): Note: Writes are not atomic, therefore some data can be written, even if an exception is thrown. """ + class TranslationLayerInterface(DataLayerInterface): def translate(self, offset): @@ -55,6 +59,7 @@ class TranslationLayerInterface(DataLayerInterface): This allows translation layers to provide maps of contiguous regions in one layer """ + return [] def dependencies(self): """Returns a list of layer names that this layer translates onto""" diff --git a/volatility/framework/interfaces/objects.py b/volatility/framework/interfaces/objects.py index 81ea2f41b..d2d8394ca 100644 --- a/volatility/framework/interfaces/objects.py +++ b/volatility/framework/interfaces/objects.py @@ -34,7 +34,7 @@ class Template(object): This is effectively a class for currying object calls """ - def __init__(self, structure_name = None, **kwargs): + def __init__(self, structure_name: str = None, **kwargs): """Stores the keyword arguments for later use""" self._kwargs = kwargs self._structure_name = structure_name @@ -53,8 +53,13 @@ class Template(object): """Updates the keyword arguments""" self._kwargs.update(newargs) - def __call__(self, context, layer_name, offset, parent = None): + def __call__(self, context: context_module.ContextInterface, layer_name: str, offset: int, parent: ObjectInterface = None): """Constructs the object - Returns: an object adhereing to the Object interface + :param context: + :param layer_name: + :param offset: + :param parent: + + :return O Returns: an object adhereing to the Object interface """ diff --git a/volatility/framework/layers/physical.py b/volatility/framework/layers/physical.py index 6f9fb75e2..39afbaedb 100644 --- a/volatility/framework/layers/physical.py +++ b/volatility/framework/layers/physical.py @@ -26,7 +26,7 @@ class BufferDataLayer(interfaces.layers.DataLayerInterface): def is_valid(self, offset): """Returns whether the offset is valid or not""" - return (offset >= self.minimum_address and offset <= self.maximum_address) + return offset >= self.minimum_address and offset <= self.maximum_address def read(self, address, length, pad = False): """Reads the data from the buffer""" diff --git a/volatility/framework/objects/__init__.py b/volatility/framework/objects/__init__.py index f6708b7bd..1b5653ecc 100644 --- a/volatility/framework/objects/__init__.py +++ b/volatility/framework/objects/__init__.py @@ -89,7 +89,7 @@ class Bytes(PrimitiveObject, bytes): """Primitive Object that handles specific series of bytes""" def __init__(self, context, layer_name, offset, structure_name, size = None, parent = None, length = 1, **kwargs): - bytes.__init__() + bytes.__init__(self) PrimitiveObject.__init__(self, context, layer_name, offset, structure_name, size, parent, struct_format = str(length) + 's') self.length = length @@ -110,7 +110,7 @@ class String(PrimitiveObject, str): """ def __init__(self, context, layer_name, offset, structure_name, size = None, parent = None, length = 1, **kwargs): - str.__init__() + str.__init__(self) PrimitiveObject.__init__(self, context, layer_name, offset, structure_name, size, parent, struct_format = str(length) + 's') self.length = length diff --git a/volatility/framework/symbols/__init__.py b/volatility/framework/symbols/__init__.py index 7bbd06d9b..0de80f305 100644 --- a/volatility/framework/symbols/__init__.py +++ b/volatility/framework/symbols/__init__.py @@ -34,7 +34,7 @@ class SymbolSpace(collections.Mapping): return self._dict[i] def __iter__(self): - return self._dict.__iter__(self) + return self._dict.__iter__() def append(self, value): """Adds a symbol_list to the end of the space""" diff --git a/volatility/framework/symbols/native.py b/volatility/framework/symbols/native.py index 50f7b0ced..fe7767c75 100644 --- a/volatility/framework/symbols/native.py +++ b/volatility/framework/symbols/native.py @@ -17,7 +17,8 @@ class NativeTable(interfaces.symbols.NativeTableInterface): native_class, _native_struct = self._native_dictionary[native_type] self._overrides[native_type] = native_class # Create this once early, because it may get used a lot - self._structures = set(self._native_dictionary.keys()).union(set(['Enumeration', 'array', 'BitField', 'void', 'pointer'])) + self._structures = set(self._native_dictionary.keys()).union( + {'Enumeration', 'array', 'BitField', 'void', 'pointer'}) def get_structure_class(self, name): ntype, fmt = native_types.get(name, (objects.Integer, ''))