Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert plugin list to dict #1781

Merged
merged 3 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions manticore/core/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import itertools
import logging
import sys
import time
import typing
import random
import weakref
from typing import Callable
Expand Down Expand Up @@ -364,7 +364,7 @@ def __init__(self, initial_state, workspace_url=None, outputspace_url=None, **kw
# the different type of events occur over an exploration.
# Note that each callback will run in a worker process and that some
# careful use of the shared context is needed.
self.plugins = set()
self.plugins = {}

# Set initial root state
if not isinstance(initial_state, StateBase):
Expand Down Expand Up @@ -850,7 +850,7 @@ def generate_testcase(self, state, message: str = "test", name: str = "test") ->
PickleSerializer().serialize(state, statef)

# Let the plugins generate a state based report
for p in self.plugins:
for p in self.plugins.values():
p.generate_testcase(state, testcase, message)

logger.info("Generated testcase No. %d - %s", testcase.num, message)
Expand All @@ -860,11 +860,11 @@ def generate_testcase(self, state, message: str = "test", name: str = "test") ->
def register_plugin(self, plugin: Plugin):
# Global enumeration of valid events
assert isinstance(plugin, Plugin)
assert plugin not in self.plugins, "Plugin instance already registered"
assert plugin.unique_name not in self.plugins, "Plugin instance already registered"
assert getattr(plugin, "manticore", None) is None, "Plugin instance already owned"

plugin.manticore = self
self.plugins.add(plugin)
self.plugins[plugin.unique_name] = plugin

events = Eventful.all_events()
prefix = Eventful.prefixes
Expand Down Expand Up @@ -916,13 +916,17 @@ def register_plugin(self, plugin: Plugin):
return plugin

@at_not_running
def unregister_plugin(self, plugin):
def unregister_plugin(self, plugin: typing.Union[str, Plugin]):
""" Removes a plugin from manticore.
No events should be sent to it after
"""
assert plugin in self.plugins, "Plugin instance not registered"
if type(plugin) is str: # Passed plugin.unique_name instead of value
assert plugin in self.plugins, "Plugin instance not registered"
plugin = self.plugins[plugin]

assert plugin.unique_name in self.plugins, "Plugin instance not registered"
plugin.on_unregister()
self.plugins.remove(plugin)
del self.plugins[plugin.unique_name]
plugin.manticore = None

def subscribe(self, name, callback):
Expand Down
6 changes: 5 additions & 1 deletion manticore/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ def is_enabled(self):
return context.get(self._enabled_key, True)

@property
def name(self):
def name(self) -> str:
return str(self.__class__)

@property
def unique_name(self) -> str:
feliam marked this conversation as resolved.
Show resolved Hide resolved
return f"{self.name}_{id(self)}"

@contextmanager
def locked_context(self, key=None, value_type=list):
"""
Expand Down
2 changes: 1 addition & 1 deletion manticore/ethereum/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def ethereum_main(args, logger):
m.register_plugin(filter_nohuman_constants)

if m.plugins:
logger.info(f'Registered plugins: {", ".join(d.name for d in m.plugins)}')
logger.info(f'Registered plugins: {", ".join(d.name for d in m.plugins.values())}')

logger.info("Beginning analysis")

Expand Down