Overview
Plugins are the fundamental building blocks in Ghidra’s architecture. They bundle features or capabilities into units that can be enabled or disabled by users within their Tool. Plugins expose functionality through menu items, toolbar buttons, service APIs, and PluginEvents.Plugin Structure
All plugins must extend thePlugin base class located in ghidra.framework.plugintool.Plugin.
Well-Formed Plugins
A properly structured plugin must:- Derive from
Plugin(directly or indirectly) - Have a class name ending with “Plugin” (required for ClassSearcher discovery)
- Include a
@PluginInfoannotation - Provide a constructor with exactly one parameter:
PluginTool
Plugin Lifecycle
Understanding the plugin lifecycle is crucial for proper initialization and cleanup:1. Construction Phase
~/workspace/source/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/Plugin.java:237
2. Dependency Resolution
Other plugins are constructed and dependencies are evaluated. If your plugin’s required services are unavailable,dispose() is called and the plugin instance is discarded.
3. Initialization
~/workspace/source/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/Plugin.java:414
4. Configuration Restoration
5. Active Phase
During normal operation:processEvent(PluginEvent)is called for consumed events- Action methods are invoked by user interactions
- Published service methods are called by other plugins
- Listener methods receive notifications
6. Shutdown Phase
~/workspace/source/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/Plugin.java:423
Service Dependencies
Declaring Required Services
Use the@PluginInfo annotation to declare service dependencies:
Providing Services
Plugins can provide services to other plugins in two ways:Direct Implementation
~/workspace/source/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/Plugin.java:249
Delegated Implementation
~/workspace/source/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/Plugin.java:637
Real-World Example: BSimSearchPlugin
Here’s an example from Ghidra’s BSim feature:~/workspace/source/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/gui/BSimSearchPlugin.java:67
Creating Actions
Plugins typically provide user interface through actions:Component Providers
Plugins can supply visual components throughComponentProvider:
Options and Configuration
Plugins can register options with the tool:OptionsChangeListener to respond to option changes:
State Management
Saving Configuration State
Restoring Configuration State
Best Practices
Constructor Responsibilities
Constructor Responsibilities
- Call super constructor first
- Register services provided (if delegated)
- Do NOT access other services (dependencies may not be met)
- Keep initialization lightweight
Initialization Responsibilities
Initialization Responsibilities
- Access required services via
tool.getService() - Create actions and UI components
- Register event listeners
- Register options
Disposal Responsibilities
Disposal Responsibilities
- Close any open resources
- Remove listeners you manually added
- Clean up UI components
- Services and events are automatically de-registered
Service Design
Service Design
- Keep service interfaces focused and cohesive
- Document service contracts clearly
- Consider using
@ServiceInfoannotation withdefaultProvider - Multiple plugins can implement the same service interface
