From be0d010f1a8a6aad4fdb924d107fed2eb7510017 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Mon, 4 Mar 2019 21:46:45 +0000 Subject: [PATCH] Add in warning if anyone tries to import from volatility.framework.plugins rather than voltility.plugins. --- volatility/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/volatility/__init__.py b/volatility/__init__.py index 3e4859f15..b265b0cdf 100644 --- a/volatility/__init__.py +++ b/volatility/__init__.py @@ -18,3 +18,18 @@ # specific language governing rights and limitations under the License. # """Volatility 3 - An open-source memory forensics framework""" +import sys +from importlib import abc + + +class WarningFindSpec(abc.MetaPathFinder): + """Checks import attempts and throws a warning if the name shouldn't be used""" + + def find_spec(name: str, _p, _t): + """Mock find_spec method that just checks the name, this must go first""" + if name.startswith("volatility.framework.plugins."): + raise Warning("Please do not use the volatility.framework.plugins namespace, only use volatility.plugins") + + +if WarningFindSpec not in sys.meta_path: + sys.meta_path = [WarningFindSpec] + sys.meta_path