From 7c75018fc49d4d1166a0468358f902c9136e8aa7 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Wed, 4 Nov 2020 21:02:25 +0000 Subject: [PATCH] Core: Fix Warnings from LGTM --- volatility/cli/volargparse.py | 3 ++- volatility/framework/automagic/stacker.py | 9 ++++----- .../framework/interfaces/configuration.py | 4 ++++ volatility/framework/interfaces/layers.py | 3 +++ volatility/framework/interfaces/objects.py | 3 +++ volatility/framework/objects/__init__.py | 3 +++ .../framework/plugins/windows/hashdump.py | 2 -- .../framework/plugins/windows/verinfo.py | 5 +---- .../framework/renderers/format_hints.py | 7 +++++++ .../symbols/linux/extensions/__init__.py | 3 +-- .../framework/symbols/windows/pdbconv.py | 19 ++++++++++--------- 11 files changed, 38 insertions(+), 23 deletions(-) diff --git a/volatility/cli/volargparse.py b/volatility/cli/volargparse.py index 99c3f13f6..79d59982a 100644 --- a/volatility/cli/volargparse.py +++ b/volatility/cli/volargparse.py @@ -6,6 +6,7 @@ import argparse import gettext import re + # This effectively overrides/monkeypatches the core argparse module to provide more helpful output around choices # We shouldn't really steal a private member from argparse, but otherwise we're just duplicating code @@ -27,7 +28,7 @@ class HelpfulSubparserAction(argparse._SubParsersAction): arg_strings = values[1:] # set the parser name if requested - if self.dest is not argparse.SUPPRESS: + if self.dest != argparse.SUPPRESS: setattr(namespace, self.dest, parser_name) matched_parsers = [name for name in self._name_parser_map if parser_name in name] diff --git a/volatility/framework/automagic/stacker.py b/volatility/framework/automagic/stacker.py index 657388c00..8c87d5669 100644 --- a/volatility/framework/automagic/stacker.py +++ b/volatility/framework/automagic/stacker.py @@ -221,12 +221,11 @@ class LayerStacker(interfaces.automagic.AutomagicInterface): context.config[child_config_path] = layer_name if not requirement.unsatisfied(context, config_path): return child_config_path, layer_name + # Clean-up to restore the config + if original_setting: + context.config[child_config_path] = original_setting else: - # Clean-up to restore the config - if original_setting: - context.config[child_config_path] = original_setting - else: - del context.config[child_config_path] + del context.config[child_config_path] else: return child_config_path, context.config.get(child_config_path, None) for req_name, req in requirement.requirements.items(): diff --git a/volatility/framework/interfaces/configuration.py b/volatility/framework/interfaces/configuration.py index 5cbad9e5b..e19e12a0c 100644 --- a/volatility/framework/interfaces/configuration.py +++ b/volatility/framework/interfaces/configuration.py @@ -90,6 +90,10 @@ class HierarchicalDict(collections.abc.Mapping): raise TypeError( "Initial_dict must be a dictionary or JSON string containing a dictionary: {}".format(initial_dict)) + def __eq__(self, other): + """Define equality between HierarchicalDicts""" + return dict(self) == dict(other) + @property def separator(self) -> str: """Specifies the hierarchy separator in use in this HierarchyDict.""" diff --git a/volatility/framework/interfaces/layers.py b/volatility/framework/interfaces/layers.py index 7ef23e533..bd088fc09 100644 --- a/volatility/framework/interfaces/layers.py +++ b/volatility/framework/interfaces/layers.py @@ -540,6 +540,9 @@ class LayerContainer(collections.abc.Mapping): """ return self[layer].read(offset, length, pad) + def __eq__(self, other): + return dict(self) == dict(other) + def write(self, layer: str, offset: int, data: bytes) -> None: """Writes to a particular layer at offset for length bytes.""" self[layer].write(offset, data) diff --git a/volatility/framework/interfaces/objects.py b/volatility/framework/interfaces/objects.py index 6070b9110..1850cb2b6 100644 --- a/volatility/framework/interfaces/objects.py +++ b/volatility/framework/interfaces/objects.py @@ -46,6 +46,9 @@ class ReadOnlyMapping(collections.abc.Mapping): """Returns the length of the internal dictionary.""" return len(self._dict) + def __eq__(self, other): + return dict(self) == dict(other) + class ObjectInformation(ReadOnlyMapping): """Contains common information useful/pertinent only to an individual diff --git a/volatility/framework/objects/__init__.py b/volatility/framework/objects/__init__.py index b356843e9..89d08f664 100644 --- a/volatility/framework/objects/__init__.py +++ b/volatility/framework/objects/__init__.py @@ -438,6 +438,9 @@ class Enumeration(interfaces.objects.ObjectInterface, int): self._vol['base_type'] = base_type + def __eq__(self, other): + return super(self) == super(other) and self.choices == other.choices + @classmethod def _generate_inverse_choices(cls, choices: Dict[str, int]) -> Dict[int, str]: """Generates the inverse choices for the object.""" diff --git a/volatility/framework/plugins/windows/hashdump.py b/volatility/framework/plugins/windows/hashdump.py index 518308c12..f6e103c85 100644 --- a/volatility/framework/plugins/windows/hashdump.py +++ b/volatility/framework/plugins/windows/hashdump.py @@ -175,8 +175,6 @@ class Hashdump(interfaces.plugins.PluginInterface): lmhash = cls.decrypt_single_salted_hash(rid, hbootkey, enc_lm_hash, cls.almpassword, lm_salt) # NT hash decryption - nt_len = unpack(" get_module_core: Unable to determine base address of module") - def get_init_size(self): if self.has_member("init_layout"): return self.init_layout.size diff --git a/volatility/framework/symbols/windows/pdbconv.py b/volatility/framework/symbols/windows/pdbconv.py index 4909f3726..4f1836084 100644 --- a/volatility/framework/symbols/windows/pdbconv.py +++ b/volatility/framework/symbols/windows/pdbconv.py @@ -620,8 +620,8 @@ class PdbReader: else: leaf_type, name, value = self.types[index - 0x1000] if leaf_type in [ - leaf_type.LF_UNION, leaf_type.LF_CLASS, leaf_type.LF_CLASS_ST, leaf_type.LF_STRUCTURE, - leaf_type.LF_STRUCTURE_ST, leaf_type.LF_INTERFACE + leaf_type.LF_UNION, leaf_type.LF_CLASS, leaf_type.LF_CLASS_ST, leaf_type.LF_STRUCTURE, + leaf_type.LF_STRUCTURE_ST, leaf_type.LF_INTERFACE ]: if not value.properties.forward_reference: result = value.size @@ -665,8 +665,8 @@ class PdbReader: self._progress_callback(index * 100 / max_len, "Processing types") leaf_type, name, value = self.types[index] if leaf_type in [ - leaf_type.LF_CLASS, leaf_type.LF_CLASS_ST, leaf_type.LF_STRUCTURE, leaf_type.LF_STRUCTURE_ST, - leaf_type.LF_INTERFACE + leaf_type.LF_CLASS, leaf_type.LF_CLASS_ST, leaf_type.LF_STRUCTURE, leaf_type.LF_STRUCTURE_ST, + leaf_type.LF_INTERFACE ]: if not value.properties.forward_reference and name: self.user_types[name] = { @@ -700,12 +700,11 @@ class PdbReader: self.user_types = self.replace_forward_references(self.user_types, type_references) def consume_type( - self, module: interfaces.context.ModuleInterface, offset: int, length: int + self, module: interfaces.context.ModuleInterface, offset: int, length: int ) -> Tuple[Tuple[Optional[interfaces.objects.ObjectInterface], Optional[str], Union[ - None, List, interfaces.objects.ObjectInterface]], int]: + None, List, interfaces.objects.ObjectInterface]], int]: """Returns a (leaf_type, name, object) Tuple for a type, and the number of bytes consumed.""" - result = None, None, None # type: Tuple[Optional[interfaces.objects.ObjectInterface], Optional[str], Optional[Union[List, interfaces.objects.ObjectInterface]]] leaf_type = self.context.object(module.get_enumeration("LEAF_TYPE"), layer_name = module._layer_name, offset = offset) @@ -713,8 +712,8 @@ class PdbReader: remaining = length - consumed if leaf_type in [ - leaf_type.LF_CLASS, leaf_type.LF_CLASS_ST, leaf_type.LF_STRUCTURE, leaf_type.LF_STRUCTURE_ST, - leaf_type.LF_INTERFACE + leaf_type.LF_CLASS, leaf_type.LF_CLASS_ST, leaf_type.LF_STRUCTURE, leaf_type.LF_STRUCTURE_ST, + leaf_type.LF_INTERFACE ]: structure = module.object(object_type = "LF_STRUCTURE", offset = offset + consumed) name_offset = structure.name.vol.offset - structure.vol.offset @@ -914,6 +913,7 @@ class PdbRetreiver: if __name__ == '__main__': import argparse + class PrintedProgress(object): """A progress handler that prints the progress value and the description onto the command line.""" @@ -934,6 +934,7 @@ if __name__ == '__main__': self._max_message_len = max([self._max_message_len, message_len]) print(message, end = (' ' * (self._max_message_len - message_len)) + '\r') + parser = argparse.ArgumentParser( description = "Read PDB files and convert to Volatility 3 Intermediate Symbol Format") parser.add_argument("-o", "--output", metavar = "OUTPUT", help = "Filename for data output", required = True)