diff --git a/test/volatility3_code_analysis.py b/test/volatility3_code_analysis.py index ee1a54ce2..100ad3074 100644 --- a/test/volatility3_code_analysis.py +++ b/test/volatility3_code_analysis.py @@ -165,13 +165,16 @@ class ModuleVisitor(NodeVisitor): def violations(self): return self._violations - def enter_ImportFrom(self, node: ast.ImportFrom): - if not node.module: - return - + def _check_vol3_import_from(self, node: ast.ImportFrom): + """ + Ensure that the only thing imported from a volatility3 module (apart + from the root volatility3 module) are functions and modules. This + prevents re-exporting of classes and variables from modules that use + them. + """ if ( node.module - and node.module.startswith("volatility3") + and node.module.startswith("volatility3.") # Give a pass to volatility3 module and node.module != "volatility3.framework.constants._version" # make an exception for this ): for name in node.names: @@ -198,6 +201,10 @@ class ModuleVisitor(NodeVisitor): ) ) + def enter_ImportFrom(self, node: ast.ImportFrom): + self._check_vol3_import_from(node) + + def enter_ClassDef(self, node: ast.ClassDef) -> Any: logger.debug("Entering class %s", node.name) clazz = None