From c6e8cc8ffa354ce1a7a6b30afeaf9b66efbe771a Mon Sep 17 00:00:00 2001 From: e-ngo Date: Tue, 30 Jul 2019 18:24:36 -0700 Subject: [PATCH] Revert "Refactored code" This reverts commit a8dc3aa7bc1c6e5809cdf020b5ce062e06ab60d2. --- mythril/analysis/security.py | 46 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/mythril/analysis/security.py b/mythril/analysis/security.py index 4d95497a..5c5e520a 100644 --- a/mythril/analysis/security.py +++ b/mythril/analysis/security.py @@ -65,36 +65,38 @@ def get_detection_modules(entrypoint, include_modules=(), custom_modules_directo _modules = [] - custom_modules_directory = os.path.abspath(custom_modules_directory) - - if custom_modules_directory and custom_modules_directory not in sys.path: - sys.path.append(custom_modules_directory) - - custom_packages = ( - list(pkgutil.walk_packages([custom_modules_directory])) - if custom_modules_directory - else [] - ) - packages = list(pkgutil.walk_packages(modules.__path__)) + custom_packages - - for loader, module_name, _ in packages: + for loader, module_name, _ in pkgutil.walk_packages(modules.__path__): if include_modules and module_name not in include_modules: continue if module_name != "base": - try: - module = importlib.import_module( - "mythril.analysis.modules." + module_name - ) - except ModuleNotFoundError: - try: - module = importlib.import_module(module_name) - except ModuleNotFoundError: - raise ModuleNotFoundError + module = importlib.import_module("mythril.analysis.modules." + module_name) module.log.setLevel(log.level) if module.detector.entrypoint == entrypoint: _modules.append(module) + if custom_modules_directory: + custom_modules = [os.path.abspath(custom_modules_directory)] + sys.path.append(custom_modules_directory) + for loader, module_name, _ in pkgutil.walk_packages(custom_modules): + if include_modules and module_name not in include_modules: + continue + + if module_name != "base": + module = importlib.import_module(module_name, custom_modules[0]) + module.log.setLevel(log.level) + if module.detector.entrypoint == entrypoint: + _modules.append(module) + + """ + for loader, module_name, _ in pkgutil.walk_packages([custom_modules_path]): + + custom_modules_path = os.path.abspath("custom/") + sys.path.append(custom_modules_path); + module = importlib.import_module( + module_name, custom_modules_path + ) + """ log.info("Found %s detection modules", len(_modules)) return _modules