Skip to main content

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 the Plugin 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 @PluginInfo annotation
  • Provide a constructor with exactly one parameter: PluginTool

Plugin Lifecycle

Understanding the plugin lifecycle is crucial for proper initialization and cleanup:

1. Construction Phase

Reference: ~/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

Reference: ~/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

Reference: ~/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

Reference: ~/workspace/source/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/Plugin.java:249

Delegated Implementation

Reference: ~/workspace/source/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/Plugin.java:637
Cyclic dependencies are not allowed. If PluginA requires a service that PluginB provides, and PluginB requires a service that PluginA provides, both plugins will fail to load.

Real-World Example: BSimSearchPlugin

Here’s an example from Ghidra’s BSim feature:
Reference: ~/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 through ComponentProvider:

Options and Configuration

Plugins can register options with the tool:
Implement OptionsChangeListener to respond to option changes:

State Management

Saving Configuration State

Restoring Configuration State

Best Practices

  • Call super constructor first
  • Register services provided (if delegated)
  • Do NOT access other services (dependencies may not be met)
  • Keep initialization lightweight
  • Access required services via tool.getService()
  • Create actions and UI components
  • Register event listeners
  • Register options
  • Close any open resources
  • Remove listeners you manually added
  • Clean up UI components
  • Services and events are automatically de-registered
  • Keep service interfaces focused and cohesive
  • Document service contracts clearly
  • Consider using @ServiceInfo annotation with defaultProvider
  • Multiple plugins can implement the same service interface

Special Plugin Interfaces

ApplicationLevelPlugin

Marks a plugin as suitable for inclusion in the application-level tool.

ApplicationLevelOnlyPlugin

Marks a plugin as application-level only, not usable in sub-tools.

ProgramaticUseOnly

Marks a plugin as special and not for user configuration. These plugins don’t need to follow the standard naming convention.

Common Patterns

Managing Multiple Domain Objects

Background Tasks

  • Services - Service architecture and interfaces
  • Events - Event system and communication