From 4def8010a30591ef5771ad297a6b104a7e49dcef Mon Sep 17 00:00:00 2001 From: Joran Honig Date: Wed, 22 Apr 2020 13:45:35 +0200 Subject: [PATCH] make laser plugins be builders --- mythril/plugin/interface.py | 7 ++----- mythril/plugin/loader.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mythril/plugin/interface.py b/mythril/plugin/interface.py index f41bf939..c1b7d542 100644 --- a/mythril/plugin/interface.py +++ b/mythril/plugin/interface.py @@ -36,13 +36,10 @@ class MythrilCLIPlugin(MythrilPlugin): pass -class MythrilLaserPlugin(MythrilPlugin, ABC): +class MythrilLaserPlugin(MythrilPlugin, LaserPluginBuilder, ABC): """ Mythril Laser Plugin interface Plugins of this type are used to instrument the laser EVM """ - @abstractmethod - @property - def builder(self) -> LaserPluginBuilder: - pass + pass diff --git a/mythril/plugin/loader.py b/mythril/plugin/loader.py index e4e612d9..8c722cec 100644 --- a/mythril/plugin/loader.py +++ b/mythril/plugin/loader.py @@ -13,6 +13,8 @@ log = logging.getLogger(__name__) class UnsupportedPluginType(Exception): + """Raised when a plugin with an unsupported type is loaded""" + pass @@ -28,7 +30,13 @@ class MythrilPluginLoader(object, metaclass=Singleton): self._load_default_enabled() def load(self, plugin: MythrilPlugin): - """Loads the passed plugin""" + """Loads the passed plugin + + This function handles input validation and dispatches loading to type specific loaders. + Supported plugin types: + - laser plugins + - detection modules + """ if not isinstance(plugin, MythrilPlugin): raise ValueError("Passed plugin is not of type MythrilPlugin") logging.info(f"Loading plugin: {plugin.name}") @@ -51,10 +59,12 @@ class MythrilPluginLoader(object, metaclass=Singleton): @staticmethod def _load_laser_plugin(plugin: MythrilLaserPlugin): + """Loads the laser plugin""" log.info(f"Loading laser plugin: {plugin.name}") - LaserPluginLoader().load(plugin.builder) + LaserPluginLoader().load(plugin) def _load_default_enabled(self): + """Loads the plugins that have the default enabled flag""" log.info("Loading installed analysis modules that are enabled by default") for plugin_name in PluginDiscovery().get_plugins(default_enabled=True): plugin = PluginDiscovery().build_plugin(plugin_name)