diff --git a/volatility/cli/__init__.py b/volatility/cli/__init__.py index d1eb1e98b..640fdba5c 100644 --- a/volatility/cli/__init__.py +++ b/volatility/cli/__init__.py @@ -108,10 +108,16 @@ class CommandLine(interfaces.plugins.FileConsumerInterface): file_logger.setFormatter(file_formatter) vollog.addHandler(file_logger) vollog.info("Logging started") + if partial_args.verbosity < 3: + console.setLevel(30 - (partial_args.verbosity * 10)) + else: + console.setLevel(10 - (partial_args.verbosity - 2)) # Do the initialization ctx = contexts.Context() # Construct a blank context - framework.import_files(volatility.plugins) # Will not log as console's default level is WARNING + failures = framework.import_files(volatility.plugins, + True) # Will not log as console's default level is WARNING + vollog.info("Plugins could not be loaded: " + ", ".join(failures)) automagics = automagic.available(ctx) plugin_list = framework.list_plugins() @@ -141,10 +147,6 @@ class CommandLine(interfaces.plugins.FileConsumerInterface): args = parser.parse_args() if args.plugin is None: parser.error("Please select a plugin to run") - if args.verbosity < 3: - console.setLevel(30 - (args.verbosity * 10)) - else: - console.setLevel(10 - (args.verbosity - 2)) vollog.log(constants.LOGLEVEL_VVV, "Cache directory used: {}".format(constants.CACHE_PATH)) diff --git a/volatility/framework/__init__.py b/volatility/framework/__init__.py index 541fce32c..5335999d1 100644 --- a/volatility/framework/__init__.py +++ b/volatility/framework/__init__.py @@ -82,8 +82,9 @@ def class_subclasses(cls: T) -> typing.Generator[T, None, None]: yield return_value -def import_files(base_module) -> None: +def import_files(base_module, ignore_errors = False) -> typing.List[str]: """Imports all plugins present under plugins path""" + failures = [] if not isinstance(base_module.__path__, list): raise TypeError("[base_module].__path__ must be a list of paths") for path in base_module.__path__: @@ -101,11 +102,13 @@ def import_files(base_module) -> None: __import__(base_module.__name__ + "." + module) except ImportError as e: vollog.debug(str(e)) - vollog.warning("Failed to import module {} based on file: {}".format(module, modpath)) - raise + vollog.debug("Failed to import module {} based on file: {}".format(module, modpath)) + failures.append(base_module.__name__ + "." + module) + if not ignore_errors: + raise else: vollog.info("Skipping existing module: {}".format(module)) - return None + return failures def list_plugins() -> typing.Dict[str, typing.Type[interfaces.plugins.PluginInterface]]: diff --git a/volatility/plugins/windows/vadyarascan.py b/volatility/plugins/windows/vadyarascan.py index 625bdcd39..990f17ed3 100644 --- a/volatility/plugins/windows/vadyarascan.py +++ b/volatility/plugins/windows/vadyarascan.py @@ -1,13 +1,6 @@ import logging import typing -try: - import yara - - has_yara = True -except ImportError: - has_yara = False - from volatility.framework import interfaces, layers, renderers from volatility.framework.renderers import format_hints from volatility.framework.symbols.windows import extensions @@ -16,6 +9,11 @@ from volatility.plugins.windows import pslist vollog = logging.getLogger(__name__) +try: + import yara +except ImportError: + vollog.info("Python Yara module not found, plugin (and dependent plugins) not available") + class VadYaraScan(interfaces.plugins.PluginInterface): @@ -79,8 +77,5 @@ class VadYaraScan(interfaces.plugins.PluginInterface): return scan_iterator def run(self): - if not has_yara: - vollog.error("Please install Yara from https://plusvic.github.io/yara/") - return renderers.TreeGrid([('Offset', format_hints.Hex), ('Rule', str)], self._generator()) diff --git a/volatility/plugins/yarascan.py b/volatility/plugins/yarascan.py index 897391621..b8ddbc70e 100644 --- a/volatility/plugins/yarascan.py +++ b/volatility/plugins/yarascan.py @@ -6,14 +6,13 @@ from volatility.framework.configuration import requirements from volatility.framework.interfaces import plugins from volatility.framework.renderers import format_hints +vollog = logging.getLogger(__name__) + try: import yara - - has_yara = True -except: - has_yara = False - -vollog = logging.getLogger(__name__) +except ImportError: + vollog.info("Python Yara module not found, plugin (and dependent plugins) not available") + raise class YaraScanner(interfaces.layers.ScannerInterface): @@ -87,8 +86,5 @@ class YaraScan(plugins.PluginInterface): yield format_hints.Hex(offset), name def run(self): - if not has_yara: - vollog.error("Please install Yara from https://plusvic.github.io/yara/") - return renderers.TreeGrid([('Offset', format_hints.Hex), ('Rule', str)], self._generator())