Questions on integrating a new language for extensibility #3166
-
I've been thinking of writing some C# bindings for the Binary Ninja API, along with a native plugin that would load the .NET host and then further load (via the plugin manager API) any installed plugins written in C#. My questions are:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Ping; still looking for some input on this before I start implementing it. |
Beta Was this translation helpful? Give feedback.
-
Generally speaking, a loader plugin is necessary for languages whose plugins may not compile directly to loadable modules. You need a native module as an entrypoint to the plugin api, although you can use the C FFI bindings from user code after that. For example, the Python api uses a built-in native core plugin (pythonplugin.dll / .dylib / .so) which loads user python plugins from a directory. It handles versioning, resolving the user's selected python loader, virtualenv, etc, but generally just sets up a thread into which the binaryninja module is imported. The native plugin also searches the user plugins directory and imports all the various python files it finds in there. Apart from that, the python plugins do most of the interaction with the C FFI directly (via ctypes) and the native plugin is not necessary beyond that. I will caution you that the C FFI is not very well documented (apart from reading the python source) and subject to breakage as we generally don't guarantee ABI compatibility across versions. I would recommend picking one version (eg latest stable) and only targeting that. There are APIs to check ABI version support, which I would recommend using. So for an implementation of C#, you will need a native plugin that loads the .NET runtime and any .NET plugins it finds in the user plugin directory (or another directory of your choice). From there, the plugins can use native methods to call out to the Binary Ninja C FFI (either through a library or directly), and can interact with any core systems through that. I would not recommend trying to connect C# to the UI api, as that api is rather unstable and full of Qt nonsense. Even the python UI api bindings are brittle, and only work due to the magic that is Shiboken. As for implementing a console scripting provider, I would recommend looking at the Python implementation. Generally speaking, there are a couple callbacks you have to handle relating to view/navigation updates, input/output handling, instance creation, and module loading (module loading is only used by the Plugin Manager). The UI should create provider consoles for you, just be careful about running commands on the main (ui) thread vs background threads. I've heard of a couple people attempting to add console support for various other scripting languages, but I haven't actually seen any projects be completed. Support for them does exist in the product today, but the code paths are only tested for Python, as it's the only first-party scripting provider. |
Beta Was this translation helpful? Give feedback.
Generally speaking, a loader plugin is necessary for languages whose plugins may not compile directly to loadable modules. You need a native module as an entrypoint to the plugin api, although you can use the C FFI bindings from user code after that.
For example, the Python api uses a built-in native core plugin (pythonplugin.dll / .dylib / .so) which loads user python plugins from a directory. It handles versioning, resolving the user's selected python loader, virtualenv, etc, but generally just sets up a thread into which the binaryninja module is imported. The native plugin also searches the user plugins directory and imports all the various python files it finds in there. Apart from t…