Plugin Manager¶
The BipPluginManager
is in charge of loading
the BipPlugin
, create and register the BipActivity
link to
them and allow to access the BipPlugin
instances once loaded.
The BipPluginManager
is a singleton and
should only be accessed using the get_plugin_manager()
functions.
It is also the only class in Bip which is a real IDA plugin.
The main reason to use the BipPluginManager
is to recuperate a BipPlugin
instance:
bpm = get_plugin_manager() # get the BipPluginManager
plg = bpm["PLUGINNAME"] # get the plugin PLUGINNAME, PLUGINNAME should be the class of the plugin
or for loading a new plugin:
class MyPlugin(BipPlugin): # define a new class for the plugin
pass # implementation
bpm = get_plugin_manager() # get the BipPluginManager
bpm.addld_plugin("MyPlugin", MyPlugin, ifneeded=True) # add the plugin
# plugin in bipplugin folder will be loaded automatically and do not need those lines
The BipPluginManager
is not exposed at the
level of the module for avoiding instantiating a second object which will
trigger bugs, use get_plugin_manager()
for getting the singleton object.
The BipPluginManager
is also in charge of
loading automatically
BipPluginManager API¶
-
bip.gui.
get_plugin_manager
()¶ Function allowing access to the
BipPluginManager
singleton.
-
class
bip.gui.pluginmanager.
BipPluginManager
¶ Class for the plugin manager of Bip. This class represent the object in charge of loading all of the
BipPlugin
. For accessing the plugin manager useget_plugin_manager()
.This class also create the
Bip
directory as a top level menu entry. It is expected that plugins should add their menu actions in this directory (using themenu()
decorator).This object should not be instantiated by the user but should already be created when IDA load the plugin. This is a real IDAPython plugin as understood by IDA.
Todo
this should handle load order and plugin dependency
-
_modbipplug
= ['bipplugin']¶ List of module names from which to load the
BipPlugin
, by default this contains, only thebipplugin
module, but other can be added by users.
-
__init__
()¶ Constructor for the
BipPluginManager
, useget_plugin_manager()
for getting this object.
-
_plugins
= None¶ dict of
BipPlugin
, keys are name of the plugin class, and value are the class.
-
_loaded
= None¶ list of loaded
BipPlugin
, keys are name of the plugin class, and value are the object.
-
_is_loaded
= None¶ indicate if main loading is already done, used by
addld_plugin()
.
-
init
()¶ Init method called by IDA. This will instantiate and load all plugins already registered at this point. This is also the function in charge of creating the top level menu
Bip
.
-
is_ready
¶ Property indicating the
BipPluginManager
is ready and has loaded the plugin.
-
find_load_plugins
(name)¶ Use the
BipPluginLoader.get_plg_from_files_in_module()
for locating allBipPlugin
in a module and load them.Note
This functions allows to load all plugins define in a particular folder. This folder should be itself a module. This is how the plugins from the
bipplugin
folder are loaded.Parameters: name (str) – Name of the module in which all plugins are define.
-
load_all
()¶ Load all plugins which have not already been loaded up to this point.
This method is called automatically when the
init()
function is called by IDA.Todo
handle exception generated by the plugins
-
load_one
(name, forced=False, ifneeded=False)¶ Load a plugin from its name.
A plugin should already have been added, see
add_plugin()
. For adding and trying to load a plugin at the same time useaddld_plugin()
.For a plugin this means: it will be check if the
to_load()
return True and if it so an object will be created, and theload()
method will be called.Parameters: - name – The name of the plugin to load.
- forced – If True (default False) the call to
to_load()
will be skipped. - ifneeded – If True will load the plugin only if not already loaded, by default (False) will raise an exception.
Raises: RuntimeError – If the plugin was not found or already loaded.
Returns: the
BipPlugin
object created on succes, None if the plugin did not wanted to be loaded.
-
add_plugin
(name, cls, ifneeded=False)¶ Add a plugin to the plugin manager. This will not load the plugin directly. It will be loaded when a call to
load_all()
is made or, if not already done, when theBipPluginManager
will be loaded by IDA.For adding and trying to load a plugin at the same time use
addld_plugin()
.Parameters: - name – Name of the plugin, this should match the name of the class.
- cls – Class of the plugin to add, the plugin manager will instantiate it.
- ifneeded – If True (default False) will not raise an exception if a plugin of the same name is already added.
Raises: RuntimeError – If the plugin is already registered.
-
addld_plugin
(name, cls, forced=False, ifneeded=False)¶ Add a plugin and try to load it. If the :class`BipPluginManager` has not already been loaded the plugin will try to be loaded at that time (see
load_one()
for details on what loading means for a plugin).Parameters: - name – Name of the plugin, this should match the name of the class.
- cls – Class of the plugin to add, the plugin manager will instantiate it itself.
- forced – If True (default False) it will not check if the
:class:BipPluginManager` as been loaded by IDA, nor will it
call the
to_load()
of the plugin. - ifneeded – If True (default False) will add and load the plugin only if not already present internally.
Raises: RuntimeError – If the plugin is already registered or already loaded and
ifneeded
is False.
-
get_plugin
(name)¶ Get a plugin instance from its name. The plugin must be loaded for this method to work.
Parameters: name – A string representing the BipPlugin
name or a subclass ofBipPlugin
.Returns: An object (instance) which inherit from BipPlugin
orNone
if not found.
-
__getitem__
(key)¶ Get a plugin instance from its name or class. This is a wrapper on
get_plugin()
but it will raise aKeyError
in case the plugin was not found.
-
__contains__
(key)¶ Check if a plugin was loaded by the
BipPluginManager
and can be access through it.
-
-
class
bip.gui.pluginmanager.
BipPluginLoader
¶ Class for utility functions for loading plugins from modules and files.
-
static
get_plugins_from_module
(mod, thismodonly=True)¶ Return a dict of the different classes which inherit from
BipPlugin
in a module. Key of the dictionary are the name in the module and values are theBipPlugin
classes.Parameters: - mod – The module in which to search for
BipPlugin
. - thismodonly (bool) – A boolean (default True) indicating if only the plugin from the current module should be used. This is for avoiding to get plugins imported from another modules.
Returns: A dict of the name associated with the
BipPlugin
classes.- mod – The module in which to search for
-
static
get_plg_from_files_in_module
(name, thismodonly=True)¶ From the name of a module, will look for the file present in the module directory and import all the
.py
files present in it (at the first level), it will then search all theBipPlugin
present in those files and return a dict of the plugins (seeget_plugins_from_module()
).This method is used for loading the plugins located in the
bipplugin
folder.Warning
If two plugins have the same name only one will be loaded.
Parameters: - name (str) – Name of the module in which to search for
.py
containingBipPlugin
. It should be possible to import both the module (import NAME
) and the sub-files (import NAME.SUBFILE
). - thismodonly (bool) – Indicate if plugins not instanciated in
the module should be imported,
see
get_plugins_from_module()
.
Returns: A dict of the name associated with the
BipPlugin
classes, seeget_plugins_from_module()
.- name (str) – Name of the module in which to search for
-
__weakref__
¶ list of weak references to the object (if defined)
-
static