-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
Bug: PyGhidra incorrectly appends project_name to project_location causing project loading failure
Describe the bug
There is a critical bug in the PyGhidra package (on PyPI) where an existing Ghidra project cannot be loaded because of an incorrect path manipulation. Specifically, at line 100 in Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.py
, the code project_location /= project_name
incorrectly appends the project name to the project location. This prevents loading existing projects, as Ghidra's internal engine already concatenates the project path and name when locating a project.
To Reproduce
The issue can be reproduced in two ways:
Prerequisite
- First create a Ghidra project and (optional) insert and auto-analyze a binary:
- Ensure all required PyGhidra configurations have been made (GHIDRA_INSTALL_DIR environment variable is set, etc.)
- Create a dummy python script, so everything works.
Method 1: Using Python API
import pyghidra
pyghidra.run_script(
binary_path=None,
script_path="/home/ghidra/ghidra_scripts/count_binaries.py",
project_location="/home/ghidra",
project_name="project_a",
analyze=False,
)
Method 2: Using CLI
pyghidra --project-location="/home/ghidra" --project-name="project_a" --script="/home/ghidra/ghidra_scripts/count_binaries.py"
Expected behavior
PyGhidra should correctly load an existing project by using the provided project location and name as separate parameters. The internal Ghidra engine is designed to handle the concatenation of these paths.
Actual behavior
The code at line 100 causes project_location
to be modified to include project_name
twice:
- First in the PyGhidra code (line 100):
project_location /= project_name
- Then again when Ghidra internally concatenates the path
If you add a debug statement print(project_location, "------", project_name)
after line 100, you'll see output like:
/home/ghidra/project_a ------ project_a
This causes PyGhidra to never find the existing project and instead creates a new one at the incorrect path /home/ghidra/project_a/project_a
.
Proposed fix
The fix is straightforward: remove line 100 from Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.py
:
# Remove this line:
project_location /= project_name
After removing this line, I confirmed that PyGhidra correctly opens the existing project at /home/ghidra/project_a
and the script runs as expected without any errors or creating duplicate projects.
Environment
- OS: Ubuntu 24.04
- Java Version: 21.0.7
- Ghidra Version: 11.3.2
- Ghidra Origin: Official GitHub distribution
- Python: 3.11
- PyGhidra version: 2.1.0 (from PyPI)
Additional context
This issue makes PyGhidra unable to work with existing projects when using either the Python API or CLI interface, which significantly impacts automation workflows that depend on script execution against existing projects.