No project description provided
Project description
Ghidra .pyi
Generator
The Ghidra .pyi
Generator generates .pyi
type stubs
for the entire Ghidra API.
Those stub files can later be used in PyCharm to enhance the development experience.
You can either use the stubs released here, or follow the instructions below to generate them yourself.
Using The Stubs
Installation
The release contains PEP 561 stub package, which can simply be installed with pip install ghidra-stubs*.whl
into the environment in which the real ghidra
module is available. Any conformant tool will then use the stub package
for type analysis purposes.
If you want to manually add the stub files to PyCharm, follow the instructions in Install, uninstall, and upgrade interpreter paths.
Usage
Once installed, all you need to do is import the Ghidra modules as usual, and PyCharm will do the rest.
import ghidra
To get support for the Ghidra builtins, you need to import them as well. The type hints for those exist in
the generated ghidra_builtins.pyi
stub. Since it is not a real Python module, importing it at runtime will fail.
But the .pyi
gives PyCharm all the information it needs to help you.
try:
from ghidra.ghidra_builtins import *
except:
pass
If you are using ghidra_bridge from a Python 3 environment where no real ghidra
module
exists you can use a snippet like the following:
import typing
if typing.TYPE_CHECKING:
import ghidra
from ghidra.ghidra_builtins import *
else:
b = ghidra_bridge.GhidraBridge(namespace=globals())
# actual code follows here
typing.TYPE_CHECKING
is a special value that is always False
at runtime but True
during any kind of type checking or completion.
Once done, just code & enjoy.
Dependencies
Ghidra Docs
To properly extract all types from Ghidra, make sure to extract the API documentation.
- Open the Ghidra CodeBrowser
- Go to
Help -> Ghidra API Help
- Wait for Ghidra to extract the docs
Python Packages
The script depends on both the attr
and typing
packages.
They are now vendored under the vendor
directory as Python2.7 support is gradually
being dropped from the ecosystem, making it hard to install and fetch packages.
# Create Jython's site-pacakges directory.
jython_site_packages=~/.local/lib/jython2.7/site-packages
mkdir -p $jython_site_packages
# Create a PTH file to point Jython to our vendored site-packages
# Outside a virtualenv, use
echo "$(realpath ./vendor)" > $jython_site_packages/python.pth
Creating the .pyi
files
GUI
- Add this directory to the
Script Directories
in the Ghidra Script Manager - Refresh the script list
- Run
generate_ghidra_pyi.py
(will be located underIDE Helpers
) - When a directory-selection dialog appears, choose the directory you'd like to save the
.pyi
files in.
CLI
$GHIDRA_ROOT/support/analyzeHeadless /tmp tmp -scriptPath $(pwd) -preScript generate_ghidra_pyi.py ./
Python Package
generate_ghidra_pyi.py
generates a setup.py
inside the directory that was selected.
This allows using pip install
to install a PEP 561 stub package that is recognized by PyCharm and other tools as containing type information for the ghidra module.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ghidra-stubs-11.2.1.1.0.4.tar.gz
.
File metadata
- Download URL: ghidra-stubs-11.2.1.1.0.4.tar.gz
- Upload date:
- Size: 3.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9e361a1ff1d13a85972aee33d14b0aa03d4cbf6ad62b96a6ded7f666c410ac0 |
|
MD5 | 6a361d088118013ecfde722deb54aa4b |
|
BLAKE2b-256 | b47b9871d3a9ff635a62ac9f63fbb7a6a2c83cfb8aafb819e3217e444bf10983 |
Provenance
The following attestation bundles were made for ghidra-stubs-11.2.1.1.0.4.tar.gz
:
Publisher:
publish.yml
on VDOO-Connected-Trust/ghidra-pyi-generator
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ghidra_stubs-11.2.1.1.0.4.tar.gz
- Subject digest:
b9e361a1ff1d13a85972aee33d14b0aa03d4cbf6ad62b96a6ded7f666c410ac0
- Sigstore transparency entry: 147020659
- Sigstore integration time:
- Predicate type:
File details
Details for the file ghidra_stubs-11.2.1.1.0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: ghidra_stubs-11.2.1.1.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 6.7 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fab1a788d30e3fc144e83ee254f690bb0dd0a9942cf1ae0213a2878ee42096a5 |
|
MD5 | b01f4ea2350f38866068f6dd57e0b511 |
|
BLAKE2b-256 | c0a8c6f4385b23b263a74685a0b6d6ff38c80a21aefa28f29ee5746129ef5163 |
Provenance
The following attestation bundles were made for ghidra_stubs-11.2.1.1.0.4-py2.py3-none-any.whl
:
Publisher:
publish.yml
on VDOO-Connected-Trust/ghidra-pyi-generator
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ghidra_stubs-11.2.1.1.0.4-py2.py3-none-any.whl
- Subject digest:
fab1a788d30e3fc144e83ee254f690bb0dd0a9942cf1ae0213a2878ee42096a5
- Sigstore transparency entry: 147020660
- Sigstore integration time:
- Predicate type: