Writing Plugins

First, take a look at some of the example plugins, or some of the community plugins to get a feel for different APIs you might be interested in. Of course, the full API docs are online and available offline via the Help/Open Python API Reference....

To start, we suggest you download the sample plugin as a template since it contains all of the elements you're likely to need.

  • Begin by editing the plugin.json file
  • Next, update the LICENSE
  • For small scripts, you can include all the code inside of __init__.py, though we recommend for most larger scripts that init just act as an initializer and call into functions organized appropriately in other files.

Plugin Debugging Mode

Available via settings, enabling plugin debugging mode will enable additional IL types via the UI.

UI Elements

There are several ways to create UI elements in Binary Ninja. The first is to use the simplified interaction API which lets you make simple UI elements for use in GUI plugins in Binary Ninja. As an added bonus, they all have fallbacks that will work in headless console-based applications as well. Plugins that use these API include the angr and nampa plugins.

The second and more powerful (but more complicated) mechanism is to leverage the binaryninjaui module. Additional documentation is forthcoming, but there are several examples (1, 2, 3), and most of the APIs are backed by the documented C++ headers. Additionally, the generated binaryninjaui module is shipped with each build of binaryninja and the usual python dir() instructions are helpful for exploring its capabilities.

Testing

It's useful to be able to reload your plugin during testing. On the Commercial edition of Binary Ninja, this is easily accomplished with a stand-alone headless install using import binaryninja after installing the API. (install_api.py is included in each platforms respective installation folder)

For other plugins, we recommend the following workflow from the scripting console which enables easy iteration and testing:

import pluginname
import importlib
importlib.reload(pluginname);pluginname.callbackmethod(bv)

Then just [UP] [ENTER] to trigger the reload when the plugin has changed.