From de3bfad135ce4723c4e7e9ae1931d6019b7019db Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Fri, 28 Sep 2018 12:44:19 +0100 Subject: [PATCH] Replace 'raise StopIteration' with a blank 'return', since changes in python-3.7 change StopIeration to a RuntimeError. --- volatility/framework/automagic/nlpdtbfinder.py | 2 +- volatility/framework/automagic/pdbscan.py | 7 ++++--- volatility/framework/layers/intel.py | 4 ++-- volatility/framework/layers/segmented.py | 4 ++-- .../framework/symbols/windows/extensions/__init__.py | 2 +- volatility/plugins/windows/handles.py | 4 ++-- volatility/plugins/windows/registry/printkey.py | 2 +- volatility/plugins/windows/registry/userassist.py | 2 +- volatility/plugins/windows/strings.py | 2 +- 9 files changed, 15 insertions(+), 14 deletions(-) diff --git a/volatility/framework/automagic/nlpdtbfinder.py b/volatility/framework/automagic/nlpdtbfinder.py index 74e55371d..3910f8f18 100644 --- a/volatility/framework/automagic/nlpdtbfinder.py +++ b/volatility/framework/automagic/nlpdtbfinder.py @@ -118,7 +118,7 @@ class NlpDtbScanner(interfaces.layers.ScannerInterface): entry_num = 0 if len(validity_tests[self._layer_class]) < 1: - raise StopIteration + return validity_mask, validity_success = validity_tests[self._layer_class][0] for entry in entries: if (entry & validity_mask) == validity_success: diff --git a/volatility/framework/automagic/pdbscan.py b/volatility/framework/automagic/pdbscan.py index 7c772b813..9fba3a2d8 100644 --- a/volatility/framework/automagic/pdbscan.py +++ b/volatility/framework/automagic/pdbscan.py @@ -195,9 +195,10 @@ class KernelPDBScanner(interfaces.automagic.AutomagicInterface): _kvo, kernel = self.valid_kernels[virtual_layer] filter_string = os.path.join(kernel['pdb_name'], kernel['GUID'] + "-" + str(kernel['age'])) # Take the first result of search for the intermediate file - try: - isf_path = intermed.IntermediateSymbolTable.file_symbol_url("windows", filter_string).__next__() - except StopIteration: + for value in intermed.IntermediateSymbolTable.file_symbol_url("windows", filter_string): + isf_path = value + break + else: isf_path = '' if isf_path: vollog.debug("Using symbol library: {}".format(filter_string)) diff --git a/volatility/framework/layers/intel.py b/volatility/framework/layers/intel.py index cd206bc16..7b8b06676 100644 --- a/volatility/framework/layers/intel.py +++ b/volatility/framework/layers/intel.py @@ -155,9 +155,9 @@ class Intel(interfaces.layers.TranslationLayerInterface): except exceptions.InvalidAddressException: if not ignore_errors: raise - raise StopIteration + return yield (offset, mapped_offset, length, layer_name) - raise StopIteration + return while length > 0: try: chunk_offset, page_size, layer_name = self._translate(offset) diff --git a/volatility/framework/layers/segmented.py b/volatility/framework/layers/segmented.py index 5859c8a6c..dcc96cecb 100644 --- a/volatility/framework/layers/segmented.py +++ b/volatility/framework/layers/segmented.py @@ -88,9 +88,9 @@ class SegmentedLayer(interfaces.layers.TranslationLayerInterface, metaclass = AB current_offset = logical_offset # If it starts too late then we're done if logical_offset > offset + length: - raise StopIteration + return except exceptions.InvalidAddressException: - raise StopIteration + return # Crop it to the amount we need left chunk_size = min(size, length + offset - logical_offset) yield (logical_offset, mapped_offset, chunk_size, self._base_layer) diff --git a/volatility/framework/symbols/windows/extensions/__init__.py b/volatility/framework/symbols/windows/extensions/__init__.py index 737bc8167..979bd646e 100644 --- a/volatility/framework/symbols/windows/extensions/__init__.py +++ b/volatility/framework/symbols/windows/extensions/__init__.py @@ -515,7 +515,7 @@ class _EPROCESS(generic.GenericIntelProcess, ExecutiveObject): proc_layer = self._context.memory[proc_layer_name] if not proc_layer.is_valid(self.Peb): - raise StopIteration + return sym_table = self.vol.type_name.split(constants.BANG)[0] peb = self._context.object("{}{}_PEB".format(sym_table, constants.BANG), diff --git a/volatility/plugins/windows/handles.py b/volatility/plugins/windows/handles.py index 57b7b5c96..09da2acf7 100644 --- a/volatility/plugins/windows/handles.py +++ b/volatility/plugins/windows/handles.py @@ -206,7 +206,7 @@ class Handles(interfaces_plugins.PluginInterface): count = 0x1000 / subtype.size if not self.context.memory[virtual].is_valid(offset): - raise StopIteration + return table = ntkrnlmp.object(type_name = "array", offset = offset, subtype = subtype, count = int(count)) @@ -248,7 +248,7 @@ class Handles(interfaces_plugins.PluginInterface): table_levels = handle_table.TableCode & self._level_mask except exceptions.PagedInvalidAddressException: vollog.log(constants.LOGLEVEL_VVV, "Handle table parsing was aborted due to an invalid address exception") - raise StopIteration + return for handle_table_entry in self._make_handle_array(TableCode, table_levels): yield handle_table_entry diff --git a/volatility/plugins/windows/registry/printkey.py b/volatility/plugins/windows/registry/printkey.py index 935cc0d2e..cb4c1f533 100644 --- a/volatility/plugins/windows/registry/printkey.py +++ b/volatility/plugins/windows/registry/printkey.py @@ -45,7 +45,7 @@ class PrintKey(plugins.PluginInterface): node_path = [hive.get_node(hive.root_cell_offset)] if not isinstance(node_path, list) or len(node_path) < 1: vollog.warning("Hive walker was not passed a valid node_path (or None)") - raise StopIteration + return node = node_path[-1] key_path = key_path or node.get_key_path() last_write_time = utility.wintime_to_datetime(node.LastWriteTime.QuadPart) diff --git a/volatility/plugins/windows/registry/userassist.py b/volatility/plugins/windows/registry/userassist.py index 5d04ba7d9..61095f4f7 100644 --- a/volatility/plugins/windows/registry/userassist.py +++ b/volatility/plugins/windows/registry/userassist.py @@ -132,7 +132,7 @@ class UserAssist(interfaces_plugins.PluginInterface): if not userassist_node_path: vollog.warning("list_userassist did not find a valid node_path (or None)") - raise StopIteration + return userassist_node = userassist_node_path[-1] # iterate through the GUIDs under the userassist key diff --git a/volatility/plugins/windows/strings.py b/volatility/plugins/windows/strings.py index 8b4e5f1e2..546dc054e 100644 --- a/volatility/plugins/windows/strings.py +++ b/volatility/plugins/windows/strings.py @@ -45,7 +45,7 @@ class Strings(interfaces.plugins.PluginInterface): yield (0, (str(string, 'latin-1'), format_hints.Hex(offset), ", ".join(revmap_list))) except ValueError: vollog.error("Strings file is in the wrong format") - raise StopIteration + return def _parse_line(self, line: bytes) -> typing.Tuple[int, bytes]: """Parses a single line from a strings file"""