Introduction
angr Management has a flexible plugin framework that allows you to extend the UI and functionality of the application. Plugins are Python files containing subclasses ofBasePlugin that can hook into various aspects of the application.
Plugin Discovery and Loading
Plugin Locations
Plugin files are automatically loaded from two locations:- The built-in
pluginsmodule of angr Management ~/.local/share/angr-management/plugins(user plugins directory)
Plugin Activation
Plugins can be in two states:- Loaded: The plugin class is discovered and loaded, but not instantiated
- Activated: An instance of the plugin class exists and is actively processing events
- The
Pluginsmenu in the main window - Configuration file (
enabled_pluginssetting) - Plugin manager UI dialog
Plugin Structure
Basic Plugin Template
Here’s the minimal structure for a plugin:Plugin Lifecycle
- Discovery: Plugin manager scans plugin directories for Python files
- Loading: Plugin classes are imported and verified
- Activation: Plugin
__init__is called with the workspace - Operation: Plugin methods are called in response to events
- Deactivation:
teardown()is called to clean up resources
Workspace and Instance Access
When a plugin is initialized, it receives aworkspace parameter:
Plugin Modes
UI Mode (workspace available)
Most plugins run in UI mode where they have access to the workspace and can:- Add menu items and toolbar buttons
- Modify the disassembly and decompiler views
- Create custom views and widgets
- Handle user interactions
Headless Mode (no workspace)
Plugins withREQUIRE_WORKSPACE = False can run in headless mode. This is useful for:
- URL handlers
- Background processing
- Command-line tools
Container Registration
Plugins can register custom containers to store and synchronize state:Best Practices
Initialization
- Keep
__init__lightweight - Set up callbacks and subscriptions
- Don’t perform heavy computation
- Handle missing dependencies gracefully
Teardown
- Always implement
teardown()if you subscribe to containers - Remove all UI elements you added
- Clean up threads and resources
Error Handling
- Always catch and log exceptions in callbacks
- Don’t let errors in your plugin crash the application
- Use
workspace.log()to communicate with users
Plugin Capabilities
Plugins can extend angr Management through:- UI Customization: Add menus, toolbars, status bar widgets
- View Instrumentation: Modify disassembly and code views
- Custom Coloring: Change colors of instructions, blocks, and functions
- Event Handling: Respond to clicks, view changes, and project events
- Context Menus: Add custom menu items to various UI elements
- Custom Analysis: Run analyses and display results
- Decompiler Integration: Add optimization passes, handle variable changes
- Persistence: Store and load plugin data in project files
Example: Simple Bookmark Plugin
- Registering a custom container
- Adding a menu button
- Handling menu clicks
- Accessing views and current state
- Customizing function colors
- Using the workspace logger