From 4bccf116292e6269f0ecc306b8dba0973af55697 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:31:16 +0000 Subject: [PATCH 1/4] Remove redundant part of if statement Also reorder imports. --- volatility3/cli/volshell/generic.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/volatility3/cli/volshell/generic.py b/volatility3/cli/volshell/generic.py index 82c470e1a..534546dcd 100644 --- a/volatility3/cli/volshell/generic.py +++ b/volatility3/cli/volshell/generic.py @@ -11,11 +11,6 @@ import sys from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union from urllib import parse, request -from volatility3.cli import text_renderer, volshell -from volatility3.framework import exceptions, interfaces, objects, plugins, renderers -from volatility3.framework.configuration import requirements -from volatility3.framework.layers import intel, physical, resources, scanners - try: import capstone @@ -23,6 +18,11 @@ try: except ImportError: has_capstone = False +from volatility3.cli import text_renderer, volshell +from volatility3.framework import exceptions, interfaces, objects, plugins, renderers +from volatility3.framework.configuration import requirements +from volatility3.framework.layers import intel, physical, resources, scanners + class Volshell(interfaces.plugins.PluginInterface): """Shell environment to directly interact with a memory image.""" @@ -553,12 +553,11 @@ class Volshell(interfaces.plugins.PluginInterface): if argname in kwargs: del kwargs[argname] - for keyword in kwargs: - val = kwargs[keyword] + for keyword, val in kwargs.items(): if not isinstance( val, interfaces.configuration.BasicTypes ) and not isinstance(val, list): - if not isinstance(val, list) or all( + if all( isinstance(x, interfaces.configuration.BasicTypes) for x in val ): raise TypeError( From faa6cab797da8719305f49e1e824448a159509eb Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:16:42 +0000 Subject: [PATCH 2/4] Remove redundant part of if statement Also reorder imports. --- volatility3/cli/volshell/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/volatility3/cli/volshell/generic.py b/volatility3/cli/volshell/generic.py index 534546dcd..b1a61fcff 100644 --- a/volatility3/cli/volshell/generic.py +++ b/volatility3/cli/volshell/generic.py @@ -555,8 +555,8 @@ class Volshell(interfaces.plugins.PluginInterface): for keyword, val in kwargs.items(): if not isinstance( - val, interfaces.configuration.BasicTypes - ) and not isinstance(val, list): + val, (interfaces.configuration.BasicTypes, list) + ): if all( isinstance(x, interfaces.configuration.BasicTypes) for x in val ): From 0b2f4fdeb772ccb097aaf310ff3169ae37279f13 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:26:39 +0000 Subject: [PATCH 3/4] Remove redundant part of if statement Also reorder imports. --- volatility3/cli/volshell/generic.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/volatility3/cli/volshell/generic.py b/volatility3/cli/volshell/generic.py index b1a61fcff..08132608b 100644 --- a/volatility3/cli/volshell/generic.py +++ b/volatility3/cli/volshell/generic.py @@ -554,12 +554,8 @@ class Volshell(interfaces.plugins.PluginInterface): del kwargs[argname] for keyword, val in kwargs.items(): - if not isinstance( - val, (interfaces.configuration.BasicTypes, list) - ): - if all( - isinstance(x, interfaces.configuration.BasicTypes) for x in val - ): + if not isinstance(val, (interfaces.configuration.BasicTypes, list)): + if all(isinstance(x, interfaces.configuration.BasicTypes) for x in val): raise TypeError( "Configurable values must be simple types (int, bool, str, bytes)" ) From bed03dfbc7024d97c289b0c26f98d0627e105eee Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Sat, 21 Dec 2024 06:15:35 +0000 Subject: [PATCH 4/4] Refactor check of BasicType The intention is either a BasicType or a list where each element is only a BasicType (and not a list). --- volatility3/cli/volshell/generic.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/volatility3/cli/volshell/generic.py b/volatility3/cli/volshell/generic.py index 08132608b..a4b141c2d 100644 --- a/volatility3/cli/volshell/generic.py +++ b/volatility3/cli/volshell/generic.py @@ -554,11 +554,15 @@ class Volshell(interfaces.plugins.PluginInterface): del kwargs[argname] for keyword, val in kwargs.items(): - if not isinstance(val, (interfaces.configuration.BasicTypes, list)): - if all(isinstance(x, interfaces.configuration.BasicTypes) for x in val): - raise TypeError( - "Configurable values must be simple types (int, bool, str, bytes)" - ) + BasicType_or_list_of_BasicType = False # excludes list of lists + if isinstance(val, interfaces.configuration.BasicTypes): + BasicType_or_list_of_BasicType = True + if all(isinstance(x, interfaces.configuration.BasicTypes) for x in val): + BasicType_or_list_of_BasicType = True + if not BasicType_or_list_of_BasicType: + raise TypeError( + "Configurable values must be simple types (int, bool, str, bytes)" + ) self.context.config[config_path + "." + keyword] = val constructed = clazz(self.context, config_path, **constructor_args)