Clean-up a few files according to PyCharm's warning system.

This commit is contained in:
Mike Auty
2014-03-28 08:47:00 +00:00
parent 5b23325447
commit 3709143c40
8 changed files with 32 additions and 18 deletions
+2 -2
View File
@@ -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
+8 -5
View File
@@ -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
+8 -3
View File
@@ -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"""
+8 -3
View File
@@ -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
"""
+1 -1
View File
@@ -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"""
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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"""
+2 -1
View File
@@ -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, ''))