Ghidra Python Uses Other Packages

Ghidra is a reverse engineering framework. It is similar to IDA pro and it is a open source project. Ghidra also provide java and python api to write plugin. Actually, its “python” is Jython, and its version is python2.7.
And its site-packages location is /opt/ghidra/Ghidra/Features/Python/data/jython-2.7.1/Lib. It only supports some uses of basic packages. And I want to use other packages(such as protobuf) in Ghidra python, I did not find a proper way to install the protobuf in Ghidra Jython’s site-packages location.

And I find another way to solve it. Firstly, I install protobuf in my system’s default python2.7.

1
sudo pip2 install protobuf

The protobuf is installed into python2.7 site-packages location. To find the site-packges location, you can open python2.7 and type below:

1
2
3
4
In [1]: import site
In [2]: print(site.getsitepackages())

['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

You can find that there are two folders. Add these folders into Ghidra python’s sys.path.

In Ghidra python file, add belows at the start of the file:

1
2
3
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')
sys.path.append('/usr/lib/python2.7/dist-packages')