From e02feed16e4653181e3f76fdd63e0ecd231b0b26 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sun, 14 Aug 2016 00:55:02 +0100 Subject: [PATCH] Python 3 has a sane super() implementation (no arguments), so convert to using that. --- volatility/framework/automagic/windows.py | 12 ++--- .../framework/configuration/requirements.py | 6 +-- volatility/framework/contexts/__init__.py | 4 +- volatility/framework/exceptions.py | 2 +- volatility/framework/interfaces/automagic.py | 3 ++ .../framework/interfaces/configuration.py | 8 +-- volatility/framework/interfaces/layers.py | 3 +- volatility/framework/interfaces/objects.py | 9 ++-- volatility/framework/interfaces/plugins.py | 3 +- volatility/framework/layers/intel.py | 6 +-- volatility/framework/layers/lime.py | 2 +- volatility/framework/layers/physical.py | 6 +-- volatility/framework/layers/scanners.py | 2 +- volatility/framework/objects/__init__.py | 50 ++++++++----------- volatility/framework/objects/templates.py | 4 +- volatility/framework/symbols/native.py | 4 +- volatility/framework/symbols/vtypes.py | 2 +- .../framework/symbols/windows/__init__.py | 2 +- 18 files changed, 60 insertions(+), 68 deletions(-) diff --git a/volatility/framework/automagic/windows.py b/volatility/framework/automagic/windows.py index b5f8b66fb..05f8110f9 100644 --- a/volatility/framework/automagic/windows.py +++ b/volatility/framework/automagic/windows.py @@ -56,8 +56,7 @@ class DtbTest(validity.ValidityRoutines): class DtbTest32bit(DtbTest): def __init__(self): - DtbTest.__init__(self, - layer_type = layers.intel.Intel, + super().__init__(layer_type = layers.intel.Intel, ptr_size = 4, ptr_struct = "I", ptr_reference = 0x300, @@ -66,8 +65,7 @@ class DtbTest32bit(DtbTest): class DtbTest64bit(DtbTest): def __init__(self): - DtbTest.__init__(self, - layer_type = layers.intel.Intel32e, + super().__init__(layer_type = layers.intel.Intel32e, ptr_size = 8, ptr_struct = "Q", ptr_reference = 0x1ED, @@ -76,8 +74,7 @@ class DtbTest64bit(DtbTest): class DtbTestPae(DtbTest): def __init__(self): - DtbTest.__init__(self, - layer_type = layers.intel.IntelPAE, + super().__init__(layer_type = layers.intel.IntelPAE, ptr_size = 8, ptr_struct = "Q", ptr_reference = 0x3, @@ -98,7 +95,7 @@ class PageMapScanner(interfaces.layers.ScannerInterface): tests = [DtbTest32bit, DtbTest64bit, DtbTestPae] def __init__(self, tests): - interfaces.layers.ScannerInterface.__init__(self) + super().__init__() for value in tests: self._check_type(value, DtbTest) self.tests = tests @@ -119,6 +116,7 @@ class PageMapOffsetHelper(automagic_interface.AutomagicInterface): priority = 20 def __init__(self): + super().__init__() self.tests = [DtbTest32bit(), DtbTest64bit(), DtbTestPae()] def branch_leave(self, node, config_path): diff --git a/volatility/framework/configuration/requirements.py b/volatility/framework/configuration/requirements.py index d06bb784b..7e13906b2 100644 --- a/volatility/framework/configuration/requirements.py +++ b/volatility/framework/configuration/requirements.py @@ -57,7 +57,7 @@ class TranslationLayerRequirement(config_interface.ConstructableRequirementInter :param layer_name: String detailing the expected name of the required layer, this can be None if it is to be randomly generated :return: """ - config_interface.ConstructableRequirementInterface.__init__(self, name, description, default, optional) + super().__init__(name, description, default, optional) # TODO: Add requirements: acceptable OSes from the address_space information # TODO: Add requirements: acceptable arches from the available layers @@ -150,7 +150,7 @@ class ChoiceRequirement(config_interface.RequirementInterface): """Allows one from a choice of strings""" def __init__(self, choices, *args, **kwargs): - config_interface.RequirementInterface.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) if not isinstance(choices, list) or any([not isinstance(choice, str) for choice in choices]): raise TypeError("ChoiceRequirement takes a list of strings as choices") self._choices = choices @@ -166,7 +166,7 @@ class ChoiceRequirement(config_interface.RequirementInterface): class ListRequirement(config_interface.RequirementInterface): def __init__(self, element_type, max_elements, min_elements, *args, **kwargs): - config_interface.RequirementInterface.__init__(self, *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) diff --git a/volatility/framework/contexts/__init__.py b/volatility/framework/contexts/__init__.py index 042a1f1b7..caf877929 100644 --- a/volatility/framework/contexts/__init__.py +++ b/volatility/framework/contexts/__init__.py @@ -1,4 +1,4 @@ -from volatility.framework import interfaces, symbols, layers +from volatility.framework import interfaces, layers, symbols from volatility.framework.configuration import HierarchicalDict __author__ = 'mike' @@ -21,7 +21,7 @@ class Context(interfaces.context.ContextInterface): :param natives: Defines the native types such as integers, floats, arrays and addresses. :type natives: interfaces.symbols.NativeTableInterface """ - interfaces.context.ContextInterface.__init__(self) + super().__init__() self._symbol_space = symbols.SymbolSpace(natives) self._memory = layers.Memory() self._config = HierarchicalDict() diff --git a/volatility/framework/exceptions.py b/volatility/framework/exceptions.py index 8bfbb68f5..e936b6ec0 100644 --- a/volatility/framework/exceptions.py +++ b/volatility/framework/exceptions.py @@ -17,7 +17,7 @@ class InvalidAddressException(VolatilityException): """Thrown when an address is not valid in the space it was requested""" def __init__(self, layer_name, invalid_address, *args, **kwargs): - VolatilityException.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self.invalid_address = invalid_address self.layer_name = layer_name diff --git a/volatility/framework/interfaces/automagic.py b/volatility/framework/interfaces/automagic.py index add3cc8de..b58f46504 100644 --- a/volatility/framework/interfaces/automagic.py +++ b/volatility/framework/interfaces/automagic.py @@ -8,6 +8,9 @@ class AutomagicInterface(validity.ValidityRoutines, metaclass = ABCMeta): priority = 10 + def __init__(self): + super().__init__() + @abstractmethod def __call__(self, context, config_path, configurable): """Runs the automagic over the configurable""" diff --git a/volatility/framework/interfaces/configuration.py b/volatility/framework/interfaces/configuration.py index 19f55367f..d6885fd4a 100644 --- a/volatility/framework/interfaces/configuration.py +++ b/volatility/framework/interfaces/configuration.py @@ -17,7 +17,7 @@ class RequirementInterface(validity.ValidityRoutines, metaclass = ABCMeta): """Class to distinguish configuration elements from everything else""" def __init__(self, name, description = None, default = None, optional = False): - validity.ValidityRoutines.__init__(self) + super().__init__() self._check_type(name, str) if CONFIG_SEPARATOR in name: raise ValueError("Name cannot contain the config-hierarchy divider (" + CONFIG_SEPARATOR + ")") @@ -88,7 +88,7 @@ class ClassRequirement(RequirementInterface): """Requires a specific class""" def __init__(self, *args, **kwargs): - RequirementInterface.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self._cls = None @property @@ -114,7 +114,7 @@ class ClassRequirement(RequirementInterface): class ConstructableRequirementInterface(RequirementInterface): def __init__(self, *args, **kwargs): - RequirementInterface.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self.add_requirement(ClassRequirement("class", "Class of the translation layer")) self._current_class_requirements = set() @@ -171,7 +171,7 @@ class ConfigurableInterface(validity.ValidityRoutines): def __init__(self, config_path): """Basic initializer that allows configurables to access their own config settings""" - validity.ValidityRoutines.__init__(self) + super().__init__() self._config_path = self._check_type(config_path, str) @classmethod diff --git a/volatility/framework/interfaces/layers.py b/volatility/framework/interfaces/layers.py index b0479e28c..de0136406 100644 --- a/volatility/framework/interfaces/layers.py +++ b/volatility/framework/interfaces/layers.py @@ -68,8 +68,7 @@ class DataLayerInterface(configuration.ConfigurableInterface, validity.ValidityR provides = {"type": "interface"} def __init__(self, context, config_path, name): - configuration.ConfigurableInterface.__init__(self, config_path) - validity.ValidityRoutines.__init__(self) + super().__init__(config_path) self._context = context self._check_type(name, str) self._name = name diff --git a/volatility/framework/interfaces/objects.py b/volatility/framework/interfaces/objects.py index a7d3763b5..4b77646b7 100644 --- a/volatility/framework/interfaces/objects.py +++ b/volatility/framework/interfaces/objects.py @@ -44,10 +44,10 @@ class ObjectInformation(ReadOnlyMapping): self._check_type(offset, int) if parent: self._check_type(parent, ObjectInterface) - ReadOnlyMapping.__init__(self, {'layer_name': layer_name, - 'offset': offset, - 'member_name': member_name, - 'parent': parent}) + super().__init__({'layer_name': layer_name, + 'offset': offset, + 'member_name': member_name, + 'parent': parent}) class ObjectInterface(validity.ValidityRoutines, metaclass = ABCMeta): @@ -124,6 +124,7 @@ class Template(validity.ValidityRoutines): def __init__(self, type_name, **arguments): """Stores the keyword arguments for later use""" # Allow the updating of template arguments whilst still in template form + super().__init__() self._vol = collections.ChainMap(arguments, {'type_name': type_name}) @property diff --git a/volatility/framework/interfaces/plugins.py b/volatility/framework/interfaces/plugins.py index 3e001618a..b2fa10901 100644 --- a/volatility/framework/interfaces/plugins.py +++ b/volatility/framework/interfaces/plugins.py @@ -26,8 +26,7 @@ class PluginInterface(configuration_interface.ConfigurableInterface, validity.Va """Class that defines the interface all Plugins must maintain""" def __init__(self, context, config_path): - validity.ValidityRoutines.__init__(self) - configuration_interface.ConfigurableInterface.__init__(self, config_path) + super().__init__(config_path) self._context = self._check_type(context, context_interface.ContextInterface) # self.validate() diff --git a/volatility/framework/layers/intel.py b/volatility/framework/layers/intel.py index f87ea5298..944412161 100644 --- a/volatility/framework/layers/intel.py +++ b/volatility/framework/layers/intel.py @@ -20,7 +20,7 @@ class Intel(interfaces.layers.TranslationLayerInterface): } def __init__(self, context, config_path, name, page_map_offset, memory_layer, swap_layer = None): - interfaces.layers.TranslationLayerInterface.__init__(self, context, config_path, name) + super().__init__(context, config_path, name) self._base_layer = self._check_type(memory_layer, str) self._page_map_offset = self._check_type(page_map_offset, int) # All Intel address spaces work on 4096 byte pages @@ -155,7 +155,7 @@ class IntelPAE(Intel): priority = 35 def __init__(self, *args, **kwargs): - Intel.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) # These can vary depending on the type of space self._entry_format = "> start_bit) & ((1 << end_bit) - 1)) def __init__(self, context, type_name, object_info, struct_format, target = None, start_bit = 0, end_bit = 0): - PrimitiveObject.__init__(self, context, type_name, object_info, struct_format) + super().__init__(context, type_name, object_info, struct_format) self._vol['target'] = target self._vol['start_bit'] = start_bit self._vol['end_bit'] = end_bit @@ -238,10 +234,9 @@ class Array(interfaces.objects.ObjectInterface, collections.Sequence): def __init__(self, context, type_name, object_info, count = 0, target = None): self._check_type(target, templates.ObjectTemplate) - interfaces.objects.ObjectInterface.__init__(self, - context = context, - type_name = type_name, - object_info = object_info) + super().__init__(context = context, + type_name = type_name, + object_info = object_info) self._vol['count'] = self._check_type(count, int) self._vol['target'] = target @@ -298,12 +293,11 @@ class Struct(interfaces.objects.ObjectInterface): """ def __init__(self, context, type_name, object_info, size, members): - interfaces.objects.ObjectInterface.__init__(self, - context = context, - type_name = type_name, - object_info = object_info, - size = size, - members = members) + super().__init__(context = context, + type_name = type_name, + object_info = object_info, + size = size, + members = members) self._check_members(members) self._concrete_members = {} diff --git a/volatility/framework/objects/templates.py b/volatility/framework/objects/templates.py index 404adb58a..dce80baf1 100644 --- a/volatility/framework/objects/templates.py +++ b/volatility/framework/objects/templates.py @@ -18,9 +18,7 @@ class ObjectTemplate(interfaces.objects.Template, validity.ValidityRoutines): """ def __init__(self, object_class = None, type_name = None, **arguments): - interfaces.objects.Template.__init__(self, - type_name = type_name, - **arguments) + super().__init__(type_name = type_name, **arguments) self._check_class(object_class, interfaces.objects.ObjectInterface) self.update_vol(object_class = object_class) diff --git a/volatility/framework/symbols/native.py b/volatility/framework/symbols/native.py index c74e70015..f8f418ca7 100644 --- a/volatility/framework/symbols/native.py +++ b/volatility/framework/symbols/native.py @@ -5,14 +5,14 @@ Created on 10 Apr 2013 """ import copy -from volatility.framework import objects, interfaces +from volatility.framework import interfaces, objects class NativeTable(interfaces.symbols.NativeTableInterface): """Symbol List that handles Native types""" def __init__(self, name, native_dictionary): - interfaces.symbols.NativeTableInterface.__init__(self, name, self) + super().__init__(name, self) self._native_dictionary = copy.deepcopy(native_dictionary) self._overrides = {} for native_type in self._native_dictionary: diff --git a/volatility/framework/symbols/vtypes.py b/volatility/framework/symbols/vtypes.py index 043b68a39..6975b6677 100644 --- a/volatility/framework/symbols/vtypes.py +++ b/volatility/framework/symbols/vtypes.py @@ -46,7 +46,7 @@ class VTypeSymbolTable(interfaces.symbols.SymbolTableInterface): raise TypeError("VType Provider interface cannot be used to fulfill a requirement") vtype_dictionary = getattr(module, vtype_variable) - interfaces.symbols.SymbolTableInterface.__init__(self, name, native_types) + super().__init__(name, native_types) self._vtypedict = vtype_dictionary self._overrides = {} diff --git a/volatility/framework/symbols/windows/__init__.py b/volatility/framework/symbols/windows/__init__.py index a27edbb7c..43faae2de 100644 --- a/volatility/framework/symbols/windows/__init__.py +++ b/volatility/framework/symbols/windows/__init__.py @@ -10,7 +10,7 @@ class WindowsKernelVTypeSymbols(vtypes.VTypeSymbolTable): def __init__(self, context, config_path, name, vtype_pymodule, vtype_variable): # FIXME: Make natives another requirement, or in some way hand it in when building the vtype_table - vtypes.VTypeSymbolTable.__init__(self, name, vtype_pymodule, vtype_variable, context.symbol_space.natives) + super().__init__(name, vtype_pymodule, vtype_variable, context.symbol_space.natives) # Set-up windows specific types self.set_type_class('_ETHREAD', extensions._ETHREAD)