Support args for mythril plugins (#1398)

Co-authored-by: Nikhil Parasaram <nikhilparasaram@Nikhils-MacBook-Pro.local>
pull/1400/head
Nikhil Parasaram 4 years ago committed by GitHub
parent 05ef257480
commit 6e37c937af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      mythril/plugin/discovery.py
  2. 2
      mythril/plugin/interface.py
  3. 9
      mythril/plugin/loader.py

@ -30,7 +30,7 @@ class PluginDiscovery(object, metaclass=Singleton):
"""Returns whether there is python package with a plugin with plugin_name"""
return plugin_name in self.installed_plugins.keys()
def build_plugin(self, plugin_name: str) -> MythrilPlugin:
def build_plugin(self, plugin_name: str, plugin_args: Dict) -> MythrilPlugin:
"""Returns the plugin for the given plugin_name if it is installed"""
if not self.is_installed(plugin_name):
raise ValueError(f"Plugin with name: `{plugin_name}` is not installed")
@ -40,7 +40,7 @@ class PluginDiscovery(object, metaclass=Singleton):
if plugin is None or not issubclass(plugin, MythrilPlugin):
raise ValueError(f"No valid plugin was found for {plugin_name}")
return plugin()
return plugin(**plugin_args)
def get_plugins(self, default_enabled=None) -> List[str]:
""" Gets a list of installed mythril plugins

@ -19,7 +19,7 @@ class MythrilPlugin:
plugin_version = "0.0.1 "
plugin_description = "This is an example plugin description"
def __init__(self):
def __init__(self, **kwargs):
pass
def __repr__(self):

@ -7,6 +7,7 @@ from mythril.support.support_utils import Singleton
from mythril.analysis.module.loader import ModuleLoader
from mythril.laser.plugin.builder import PluginBuilder as LaserPluginBuilder
from mythril.laser.plugin.loader import LaserPluginLoader
from typing import Dict
import logging
log = logging.getLogger(__name__)
@ -28,6 +29,10 @@ class MythrilPluginLoader(object, metaclass=Singleton):
log.info("Initializing mythril plugin loader")
self.loaded_plugins = []
self._load_default_enabled()
self.plugin_args = dict() # type: Dict[str, Dict]
def set_args(self, plugin_name: str, **kwargs):
self.plugin_args[plugin_name] = kwargs
def load(self, plugin: MythrilPlugin):
"""Loads the passed plugin
@ -69,5 +74,7 @@ class MythrilPluginLoader(object, metaclass=Singleton):
"""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)
plugin = PluginDiscovery().build_plugin(
plugin_name, self.plugin_args.get(plugin_name, {})
)
self.load(plugin)

Loading…
Cancel
Save