Skip to content

ghidra: initial capa explorer extension MVP #2839

Draft
vaishakh787 wants to merge 20 commits intomandiant:masterfrom
vaishakh787:ghidra-capa-explorer-mvp
Draft

ghidra: initial capa explorer extension MVP #2839
vaishakh787 wants to merge 20 commits intomandiant:masterfrom
vaishakh787:ghidra-capa-explorer-mvp

Conversation

@vaishakh787
Copy link
Copy Markdown

@vaishakh787 vaishakh787 commented Jan 26, 2026

ghidra: Implement a capa explorer plugin as a Ghidra extension #1980

Summary

Hey @mike-hunhoff , This PR introduces an initial MVP implementation of a capa explorer Ghidra extension.

The purpose of this draft PR is to validate the overall architecture and
integration approach before implementing full capa analysis functionality.

This work aims to replace the current script-based Ghidra workflow with a
proper, installable Ghidra extension that mirrors the IDA Pro capa explorer
plugin experience.


Current functionality

  • Ghidra extension packaged using the standard Ghidra extension mechanism
  • Java Swing–based UI integration (no PyQt)
  • Menu action: Tools ->Run capa analysis
  • Plugin lifecycle and registration validated
  • Java -> Python execution bridge implemented
  • Extension data directory handling verified
  • Minimal Python entry point for execution testing

This MVP confirms that the extension:

  • installs cleanly
  • enables correctly via Ghidra’s plugin manager
  • executes code from the UI
  • provides a stable foundation for further development

Non-goals for this PR

This PR intentionally does not implement:

  • Full capa rule execution
  • Feature extractor integration
  • Rule management or selection UI
  • Result tree view
  • Program navigation, bookmarks, or highlighting
  • Full parity with the IDA capa explorer plugin

These will be implemented incrementally after architectural review.


Design notes

  • UI is implemented entirely in Java Swing, consistent with Ghidra plugin requirements
  • Python is used only for capa execution logic
  • No PyQt usage (Ghidra main-thread constraint)
  • Architecture mirrors the IDA explorer separation of concerns:
    • Java: UI and Ghidra integration
    • Python: capa execution and result processing
  • Extension is implemented alongside the existing script-based integration
    without breaking backward compatibility

Repository layout

capa/ghidra/
├── helpers.py
├── plugin/
│ ├── capa_explorer.py # existing script integration
│ └── extension/ # new Ghidra extension (this PR)
│ ├── Module.manifest
│ ├── extension.properties
│ ├── build.gradle
│ ├── data/
│ │ └── python/
│ └── src/
│ └── main/java/capa/ghidra/


Related to #1980
image

image

@google-cla
Copy link
Copy Markdown

google-cla bot commented Jan 26, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add bug fixes, new features, breaking changes and anything else you think is worthwhile mentioning to the master (unreleased) section of CHANGELOG.md. If no CHANGELOG update is needed add the following to the PR description: [x] No CHANGELOG update needed

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @vaishakh787, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request lays the foundational architecture for integrating the capa analysis tool directly into Ghidra as a native extension. It transitions the existing script-based workflow into a more robust, installable plugin, providing a dedicated UI component and a menu action to initiate capa analysis. This MVP focuses on establishing the core framework and communication between Ghidra's Java environment and capa's Python logic, setting the stage for comprehensive feature development.

Highlights

  • Initial MVP for Capa Explorer Extension: This pull request introduces the Minimum Viable Product (MVP) for a capa explorer Ghidra extension, establishing the foundational architecture for integrating capa analysis directly into Ghidra.
  • Transition from Script-based to Extension-based Workflow: The new implementation moves away from the existing script-based Ghidra workflow, providing a proper, installable Ghidra extension that mirrors the IDA Pro capa explorer plugin experience.
  • Hybrid Architecture (Java UI, Python Logic): The extension utilizes Java Swing for its user interface and Ghidra integration, while employing a Python execution bridge to handle the core capa analysis logic, ensuring compatibility with Ghidra's main-thread constraints.
  • New 'Run capa analysis' Menu Action: A new menu action, 'Tools → Run capa analysis', has been added, allowing users to trigger capa analysis directly from the Ghidra UI.
  • Core Functionality Validation: The MVP successfully validates key functionalities, including clean installation, correct enablement via Ghidra’s plugin manager, and the ability to execute code from the UI, providing a stable base for future development.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a solid MVP for a capa explorer Ghidra extension. The architecture with a Java Swing UI and a Python backend for analysis is a good approach. My review includes suggestions to clean up some boilerplate code, improve error handling and configuration, and some minor code style points. Specifically, I've pointed out unused template files in the capaexplorer package that should be removed, and suggested improvements for handling Python executable paths and exception logging.

Comment thread capa/ghidra/plugin/extension/src/main/java/capa/ghidra/CapaProvider.java Outdated
Comment thread capa/ghidra/plugin/extension/src/main/java/capa/ghidra/CapaPythonBridge.java Outdated
Comment thread capa/ghidra/plugin/extension/extension.properties Outdated
Comment thread capa/ghidra/plugin/extension/src/main/java/capa/ghidra/CapaPlugin.java Outdated
Comment thread capa/ghidra/plugin/extension/src/main/java/capa/ghidra/CapaPythonBridge.java Outdated
Comment thread capa/ghidra/plugin/extension/src/main/java/capa/ghidra/CapaPythonBridge.java Outdated
Comment thread capa/ghidra/plugin/extension/src/main/java/capaexplorer/CapaExplorerPlugin.java Outdated
@vaishakh787 vaishakh787 marked this pull request as ready for review January 26, 2026 13:16
@vaishakh787 vaishakh787 marked this pull request as draft January 26, 2026 13:22
@vaishakh787 vaishakh787 changed the title ghidra: initial capa explorer extension MVP ghidra: initial capa explorer extension MVP Jan 26, 2026
Copy link
Copy Markdown
Collaborator

@mike-hunhoff mike-hunhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable so far, but we want to utilize PyGhidra to bridge Java and Python. This implementation creates a separate process to run Python. Additionally, the already analyzed Ghidra database (program object) should be passed to capa for analysis, so the initial binary analysis does not need to be completed twice.

Comment on lines +42 to +48
Process process =
new ProcessBuilder(
python,
scriptFile.getAbsolutePath()
)
.redirectErrorStream(true)
.start();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyGhidra should serve as the Python <-> Java bridge. Running Python in a separate process doesn't count 🙂

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification @mike-hunhoff that makes sense.

You're right: launching Python as a separate process is not the intended model here.
I’ll rework the bridge to use PyGhidra directly for in-process Java ↔ Python execution.

The updated approach will be:

  • Use PyGhidra as the execution bridge
  • Pass the already-loaded Program object into Python
  • Avoid reloading or reanalyzing the binary
  • Reuse the existing Ghidra analysis database for capa

For this draft PR, my goal was to validate extension packaging and UI wiring.
I’ll update the implementation to follow the PyGhidra-based design next.

Thanks for pointing this out — I’ll push an update shortly.

@vaishakh787
Copy link
Copy Markdown
Author

Hi @mike-hunhoff , I’ve pushed an update to the draft PR addressing your feedback.

The implementation now uses PyGhidra as the Java <-> Python bridge, removes the external Python subprocess, and passes the already-loaded Program object directly into the Python script so the existing analysis database is reused.

Please let me know when you have a chance to take another look, and if anything should be adjusted further.

Comment thread capa/ghidra/plugin/extension/README.md Outdated
Comment thread capa/ghidra/plugin/extension/.gradle/9.2.0/checksums/checksums.lock Outdated
Comment thread capa/ghidra/plugin/extension/extension.properties
Comment thread capa/ghidra/plugin/extension/src/main/java/capa/ghidra/CapaPlugin.java Outdated
@vaishakh787 vaishakh787 marked this pull request as ready for review February 19, 2026 16:25
@vaishakh787 vaishakh787 marked this pull request as draft February 19, 2026 16:25
@github-actions github-actions bot dismissed their stale review February 19, 2026 16:56

CHANGELOG updated or no update needed, thanks! 😄

@vaishakh787
Copy link
Copy Markdown
Author

Hey @mike-hunhoff , quick update.

I switched execution to GhidraScriptService as suggested and now the full flow works: the script runs in PyGhidra, generates the cache, and the plugin loads it successfully.

Next, I’ll integrate real Capa JSON output and expand the results model/UI.

Let me know if this direction looks good.

@mike-hunhoff
Copy link
Copy Markdown
Collaborator

Hey @mike-hunhoff , quick update.

I switched execution to GhidraScriptService as suggested and now the full flow works: the script runs in PyGhidra, generates the cache, and the plugin loads it successfully.

Next, I’ll integrate real Capa JSON output and expand the results model/UI.

Let me know if this direction looks good.

sounds good @vaishakh787 , I look forward to seeing the UI 🙂

@vaishakh787
Copy link
Copy Markdown
Author

Also @mike-hunhoff wanted to contact you regarding GSoC 2026. How do i reach out to you?

@mike-hunhoff
Copy link
Copy Markdown
Collaborator

Also @mike-hunhoff wanted to contact you regarding GSoC 2026. How do i reach out to you?

Review https://github.com/mandiant/flare-gsoc - this explains everything about the program, including preferred methods for contacting potential mentors.

@vaishakh787
Copy link
Copy Markdown
Author

vaishakh787 commented Feb 27, 2026

Hey @mike-hunhoff , here's my plan for the UI.

I'll replace the current JTextArea in CapaProvider with a JTree-based results panel. The tree will have three columns ,Rule Name, Namespace, and Address , where each top-level node is a matched capability rule and child nodes are the functions/addresses where the match was found. Clicking an address will use Ghidra's GoToService to navigate the listing view. A search bar above the tree will allow filtering by rule name or namespace.

For this iteration, the scope will be:

  • Replace JTextArea with a JTree-based results panel
  • Integrate real capa JSON output in capa_runner.py using the Ghidra feature extractor
  • Parse the capa result document into the tree model
  • Basic address navigation via GoToService

Everything is built on stable, non-deprecated Ghidra APIs : ComponentProvider, GoToService, and GhidraScriptService. "Show by function" mode, bookmarks, and highlighting will come in a later iteration.

Does this direction look good before I start coding?

@vaishakh787
Copy link
Copy Markdown
Author

vaishakh787 commented Mar 2, 2026

Hey @mike-hunhoff , here's my plan for the UI.

I'll replace the current JTextArea in CapaProvider with a JTree-based results panel. The tree will have three columns ,Rule Name, Namespace, and Address , where each top-level node is a matched capability rule and child nodes are the functions/addresses where the match was found. Clicking an address will use Ghidra's GoToService to navigate the listing view. A search bar above the tree will allow filtering by rule name or namespace.

For this iteration, the scope will be:

  • Replace JTextArea with a JTree-based results panel
  • Integrate real capa JSON output in capa_runner.py using the Ghidra feature extractor
  • Parse the capa result document into the tree model
  • Basic address navigation via GoToService

Everything is built on stable, non-deprecated Ghidra APIs : ComponentProvider, GoToService, and GhidraScriptService. "Show by function" mode, bookmarks, and highlighting will come in a later iteration.

Does this direction look good before I start coding?

image image

@vaishakh787
Copy link
Copy Markdown
Author

vaishakh787 commented Mar 2, 2026

Hey @mike-hunhoff , can you check this out and let me know

@mike-hunhoff
Copy link
Copy Markdown
Collaborator

Hey @mike-hunhoff , here's my plan for the UI.
I'll replace the current JTextArea in CapaProvider with a JTree-based results panel. The tree will have three columns ,Rule Name, Namespace, and Address , where each top-level node is a matched capability rule and child nodes are the functions/addresses where the match was found. Clicking an address will use Ghidra's GoToService to navigate the listing view. A search bar above the tree will allow filtering by rule name or namespace.
For this iteration, the scope will be:

  • Replace JTextArea with a JTree-based results panel
  • Integrate real capa JSON output in capa_runner.py using the Ghidra feature extractor
  • Parse the capa result document into the tree model
  • Basic address navigation via GoToService

Everything is built on stable, non-deprecated Ghidra APIs : ComponentProvider, GoToService, and GhidraScriptService. "Show by function" mode, bookmarks, and highlighting will come in a later iteration.
Does this direction look good before I start coding?

image image

Based on these screenshots it looks like you're headed in the right direction! Ideally, the extension mirrors the functionality of the IDA Plugin (minus the rule writing tab). I can't tell from your screenshots, but in terms of UX, all actions should be completed from the extension UI, e.g. starting analysis, configuring rule location, etc., looking something like:

  1. user opens extension UI
  2. user selects "Analyze" button
  3. capa analysis is executed, results are displayed in the UI

@vaishakh787 vaishakh787 closed this Mar 2, 2026
@vaishakh787 vaishakh787 reopened this Mar 2, 2026
@vaishakh787
Copy link
Copy Markdown
Author

@mike-hunhoff , can you please check this out?, and please let me know if anything else to be added.

Screen.Recording.2026-03-08.at.03.06.42.mov

@mike-hunhoff
Copy link
Copy Markdown
Collaborator

@mike-hunhoff , can you please check this out?, and please let me know if anything else to be added.

Screen.Recording.2026-03-08.at.03.06.42.mov

@mike-hunhoff , can you please check this out?, and please let me know if anything else to be added.

Screen.Recording.2026-03-08.at.03.06.42.mov

That is looking great @vaishakh787 !! A couple of quick comments from watching your screen share:

  1. Each matched feature should have an associated address that users can navigate to by double-clicking the address in the address column
  2. features should be fully rendered using their __str__ equivalent representation, e.g. match doesn't list any useful details for the user.

@vaishakh787
Copy link
Copy Markdown
Author

Screen.Recording.2026-03-12.at.01.52.34.mov

Hey @mike-hunhoff , I’ve been working on aligning the Ghidra plugin UI more closely with the capa IDA plugin based on your feedback.

Currently updating the feature rendering so matches are displayed using their str representation (e.g. api(CreateFileA), string("cmd.exe")) and ensuring each matched feature has an associated address in the results tree.

One issue I’m debugging at the moment is the double-click navigation. The Address column is populated correctly, but double-clicking it is not yet triggering navigation in the Ghidra listing view. The GoToService logic is in place, so I’m currently investigating how the mouse events propagate through the JTreeTable.

@mike-hunhoff
Copy link
Copy Markdown
Collaborator

Screen.Recording.2026-03-12.at.01.52.34.mov
Hey @mike-hunhoff , I’ve been working on aligning the Ghidra plugin UI more closely with the capa IDA plugin based on your feedback.

Currently updating the feature rendering so matches are displayed using their str representation (e.g. api(CreateFileA), string("cmd.exe")) and ensuring each matched feature has an associated address in the results tree.

One issue I’m debugging at the moment is the double-click navigation. The Address column is populated correctly, but double-clicking it is not yet triggering navigation in the Ghidra listing view. The GoToService logic is in place, so I’m currently investigating how the mouse events propagate through the JTreeTable.

The address column still appears incorrect? Each list feature should have an associated address for navigation.

@vaishakh787
Copy link
Copy Markdown
Author

Hey there! @mike-hunhoff , can you please check this out.

Screen.Recording.2026-03-16.at.01.06.54.mov

@mike-hunhoff
Copy link
Copy Markdown
Collaborator

Hey there! @mike-hunhoff , can you please check this out.

Screen.Recording.2026-03-16.at.01.06.54.mov

Nice! This looks much closer to the existing capa explorer plugin. I did notice the implementation appears to lack statement nesting? e.g. it appears from your recording that all statements and, or, etc. exist as top-level statements, e.g.

> and
  > or
    > Createfile

versus

> and
> or
> CreateFile

@vaishakh787
Copy link
Copy Markdown
Author

Hi @mike-hunhoff ,
I’ve updated the implementation to address the statement nesting issue you mentioned. As shown in the recording below, the CapaResultsTreeModel now correctly builds a hierarchical tree where and/or statements act as parent nodes rather than top-level items.

Screen.Recording.2026-03-21.at.18.55.28.mov

Since the GSoC proposal deadline is approaching, I’d love to get this merged as an MVP so I can reference it in my final application. Please let me know if there are any other refinements you'd like to see!

@mike-hunhoff
Copy link
Copy Markdown
Collaborator

Hi @mike-hunhoff , I’ve updated the implementation to address the statement nesting issue you mentioned. As shown in the recording below, the CapaResultsTreeModel now correctly builds a hierarchical tree where and/or statements act as parent nodes rather than top-level items.

Screen.Recording.2026-03-21.at.18.55.28.mov
Since the GSoC proposal deadline is approaching, I’d love to get this merged as an MVP so I can reference it in my final application. Please let me know if there are any other refinements you'd like to see!

Thanks @vaishakh787 . Reviewing your screen capture, I noticed that all of the API feature matches under a basic block have the same address? The address column should contain the address of the individual feature, so the user can navigate to it.

Regarding GSoC, don't worry about merging this PR before submitting your application. You've thoroughly demonstrated your abilities throughout our interactions. Simply link this PR in your application and we'll handle the rest. We don't want to rush this PR before it's ready. Let's keep iterating until we have an MVP that meets capa's quality standards.

@vaishakh787
Copy link
Copy Markdown
Author

Screen.Recording.2026-04-16.at.02.04.57.mov

Hey @mike-hunhoff ,
I can see that features like api(fopen) are currently showing the enclosing basic block address instead of their own instruction address. I’m looking into how feature-level locations are being propagated from the Python side.

If you have any pointers on the expected way to extract or map feature-level locations in this context, that would be really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants