Skip to main content

Introduction

PyGhidra is a Python library that provides direct access to the Ghidra API within a native CPython 3 interpreter using JPype. Originally developed by the Department of Defense Cyber Crime Center (DC3) as “Pyhidra”, it enables modern Python workflows with full Ghidra functionality.

Key Features

  • Native CPython 3 - Use Python 3.x with modern syntax and libraries
  • Standalone operation - Run Ghidra scripts outside the GUI
  • Full API access - Complete access to Ghidra’s Java API
  • Project management - Open, create, and manage Ghidra projects
  • Type stubs - IDE autocomplete and type checking support
  • Integration ready - Use Ghidra as part of larger Python workflows

Installation

Prerequisites

  1. Ghidra 12.0 or later installed
  2. Python 3.8 or later
  3. pip package manager

Install PyGhidra

Online installation:
Offline installation:

Install Type Stubs (Optional)

For better IDE support:

Set Ghidra Installation Path

Option 1: Environment variable
Option 2: In code

Quick Start

Basic Program Analysis

Legacy API (Simple)

Core API Reference

pyghidra.start()

Initialize Ghidra in headless mode:

Project Management

Open or create project:
Load program from file:
Access program:

Analysis Operations

Run analysis:
Configure analysis:

Transactions

All program modifications require transactions:

Running GhidraScripts

Advanced Usage

Walking Projects

Process all domain files:
Process all programs:

Working with Filesystems

Accessing the Decompiler

Memory Operations

Symbol Operations

Real-World Examples

Example 1: Batch Binary Analysis

Example 2: Function Signature Extraction

Example 3: Custom Analysis with Transactions

Custom Launchers

For advanced JVM configuration:

Package Name Conflicts

When Python modules conflict with Java packages:

Best Practices

  1. Use context managers - Ensures proper resource cleanup
  2. Handle transactions - Always wrap modifications in transactions
  3. Set timeouts - Use task monitors with timeouts for long operations
  4. Save work - Call program.save() after modifications
  5. Check started state - Use pyghidra.started() before calling start()
  6. Release programs - Always release programs when done

Troubleshooting

Common Issues

ImportError: No module named pyghidra
Ghidra installation not found
JVM already started
Program locked Ensure previous program instances are released:

Migration from Jython

Key differences when migrating from Jython scripts: