2019-04-02 19:27:40 +00:00
# Developer's Guide
2019-03-28 20:21:24 +00:00
2019-11-13 17:05:38 +00:00
## References
- [Catalog of Dependencies ](#catalog-of-dependencies )
- [Install Development and Build Tools ](#install-development-and-build-tools )
- [Setup Source Repository ](#setup-source-repository )
- [Setup Build Dependency Repository ](#setup-build-dependency-repository )
* [Automatic script instructions ](#automatic-script-instructions )
* [Manual download instructions ](#manual-download-instructions )
- [Building Ghidra ](#building-ghidra )
- [Developing Ghidra ](#developing-ghidra )
* [Prepare the Environment ](#prepare-the-environment )
* [Import Eclipse Projects ](#import-eclipse-projects )
* [Building the natives ](#building-the-natives )
* [Pre-compile Language Modules ](#pre-compile-language-modules-optional )
* [Import and Build GhidraDev project ](#import-and-build-ghidradev-project-optional )
* [Run and Debug Ghidra from Eclipse ](#run-and-debug-ghidra-from-eclipse )
* [Running tests ](#running-tests )
- [Setup build in CI ](#setup-build-in-ci )
- [Building Supporting Data ](#building-supporting-data )
* [Building Data Type Archives ](#building-data-type-archives )
* [Building FID Databases ](#building-fid-databases )
2019-03-28 20:21:24 +00:00
## Catalog of Dependencies
The following is a list of dependencies, in no particular order.
2019-03-29 15:10:47 +00:00
This guide includes instructions for obtaining many of these at the relevant step(s).
2019-03-28 20:21:24 +00:00
You may not need all of these, depending on which portions you are building or developing.
2021-02-09 23:28:06 +00:00
#### At minimum you will need all of the following
2019-09-12 13:40:36 +00:00
* Java JDK 11 (64-bit) - Free long term support (LTS) versions of JDK 11 are provided by:
2019-06-24 18:12:31 +00:00
- AdoptOpenJDK
- https://adoptopenjdk.net/releases.html?variant=openjdk11& jvmVariant=hotspot
- Amazon Corretto
- https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html
2021-04-07 14:51:05 +00:00
* Gradle 5.0 or later - We use version 5.0, and tested with up to 6.8.3.
2019-03-29 15:10:47 +00:00
- https://gradle.org/next-steps/?version=5.0& format=bin
2019-11-06 13:08:49 +00:00
* A C/C++ compiler - We use GCC on Linux, Xcode (Clang) on macOS, and Visual Studio (2017 or later) on Windows.
2019-03-29 15:10:47 +00:00
- https://gcc.gnu.org/
- https://developer.apple.com/xcode/
- https://visualstudio.microsoft.com/downloads/
2021-02-09 23:28:06 +00:00
#### Optional for Development
* Eclipse - It must support JDK 11. Eclipse 2018-12 or later should work. Other IDEs may work, but we have not tested them.
- https://www.eclipse.org/downloads/
#### Necessary unless a download zip snapshot of the ghidra repository is used
* Git - We use the official installer on Windows. For windows you can also use the github CLI or git from with (Windows Subsystem for Linux - WSL). Most Linux distros have git in their repos. Xcode provides git on macOS. You can skip Git if you download a .zip file of the ghidra repository.
2019-03-29 15:10:47 +00:00
- https://git-scm.com/downloads
2021-02-09 23:28:06 +00:00
- https://cli.github.com/
#### Optional unless following [Manual download instructions](#manual-download-instructions)
* Bash - This is moot on Linux and macOS. On Windows, we use MinGW. This may be distributed with Git for Windows. This can be skipped if using the automatic build.
2019-03-29 15:10:47 +00:00
- https://osdn.net/projects/mingw/releases/
2021-02-09 23:28:06 +00:00
#### Necessary for the development and building of Ghidra, these and more will be downloaded during the [Automatic](#automatic-script-instructions) or the [Manual](#manual-download-instructions) instructions
2019-03-29 15:10:47 +00:00
* dex2jar. We use version 2.0.
- https://github.com/pxb1988/dex2jar/releases
2019-03-28 20:21:24 +00:00
* AXMLPrinter2
2019-03-29 15:10:47 +00:00
- https://code.google.com/archive/p/android4me/downloads
* HFS Explorer. We use version 0.21.
- https://sourceforge.net/projects/catacombae/files/HFSExplorer/0.21/
- https://github.com/unsound/hfsexplorer/releases (newer versions)
* Yet Another Java Service Wrapper. We use version 12.12 - Only to build Ghidra package.
- https://sourceforge.net/projects/yajsw/files/yajsw/yajsw-stable-12.12/
* Eclipse PDE - Environment for developing the GhidraDev plugin.
- https://www.eclipse.org/pde/
2021-04-07 14:51:05 +00:00
* Eclipse CDT. We build against version 8.6.0 - Build dependency for the GhidraDev plugin.
2019-03-29 15:10:47 +00:00
- https://www.eclipse.org/cdt/
2021-04-07 14:51:05 +00:00
* PyDev. We build against version 6.3.1 - Build dependency for the GhidraDev plugin.
2019-03-29 15:10:47 +00:00
- https://sourceforge.net/projects/pydev/files/pydev/
There are many, many others automatically downloaded by Gradle from Maven Central and Bintray JCenter when building and/or setting up the development environment.
If you need these offline, a reasonable course of action is to set up a development environment online, perhaps perform a build, and then scrape Gradle's cache.
2019-03-28 20:21:24 +00:00
## Install Development and Build Tools
2021-02-09 23:28:06 +00:00
If you're on Windows, install Git unless you will download a .zip clone of the ghidra repository. If you go the manual route
many of the commands given below must be executed in Bash (Windows Subsystem for Linux (WSL), or Use git-bash or MSYS from MinGW).
2019-04-02 19:27:40 +00:00
2019-03-26 17:45:32 +00:00
Install OpenJDK 11 and make sure it's the default java.
2019-03-28 20:21:24 +00:00
Install Eclipse.
You can launch Eclipse with any JRE/JDK, but you'll need to ensure Eclipse knows about your JDK 11 installation.
2019-11-13 17:15:20 +00:00
In Eclipse, select Window -> Preferences (Eclipse -> Preferences on macOS), then navigate to Java -> Installed JREs, and ensure a JDK 11 is configured.
2019-03-26 17:45:32 +00:00
2019-03-28 20:21:24 +00:00
Install Gradle, add it to your `PATH` , and ensure it is launched using JDK 11.
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
## Setup Source Repository
2019-03-26 17:45:32 +00:00
2021-02-09 23:28:06 +00:00
You may choose any directory for your working copy, however these instructions will assume you have cloned the source to `~/git/ghidra` .
2019-03-26 17:45:32 +00:00
Be sure to adjust the commands to match your chosen working directory if different than suggested:
```bash
2019-03-28 20:21:24 +00:00
mkdir ~/git
2019-03-26 17:45:32 +00:00
cd ~/git
git clone git@github.com:NationalSecurityAgency/ghidra.git
```
2021-02-09 23:28:06 +00:00
or unzip a snapshot .zip of the ghidra repository
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
## Setup Build Dependency Repository
2019-03-28 20:21:24 +00:00
Ghidra's build uses artifacts named as available in Maven Central and Bintray JCenter, when possible.
2019-03-26 17:45:32 +00:00
Unfortunately, in some cases, the artifact or the particular version we desire is not available.
2019-06-24 18:12:31 +00:00
So, in addition to mavenCentral and jcenter, you must configure a flat directory-style repository for
manually-downloaded dependencies.
The flat directory-style repository can be created and populated automatically by a provided script,
or manually by downloading the required dependencies. Choose one of the two following methods:
* [Automatic script instructions ](#automatic-script-instructions )
2019-06-25 13:00:40 +00:00
* [Manual download instructions ](#manual-download-instructions )
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
### Automatic Script Instructions
The flat directory-style repository can be setup automatically by running a simple Gradle script.
2019-06-26 15:05:42 +00:00
Navigate to `~/git/ghidra` and run the following:
2019-06-04 19:21:06 +00:00
```
2021-04-07 14:51:05 +00:00
gradle -I gradle/support/fetchDependencies.gradle init
2019-06-04 19:21:06 +00:00
```
2019-06-27 15:51:29 +00:00
The Gradle task to be executed, in this case _init_ , is unimportant. The point is to have Gradle execute
2021-04-07 14:51:05 +00:00
the `fetchDependencies.gradle` script. If it ran correctly you will have a new `~/git/ghidra/dependencies/`
directory populated with the following files:
* flatRepo/AXMLPrinter2.jar
* flatRepo/csframework.jar
* flatRepo/dex-ir-2.0.jar
* flatRepo/dex-reader-2.0.jar
* flatRepo/dex-reader-api-2.0.jar
* flatRepo/dex-tools-2.0.jar
* flatRepo/dex-translator-2.0.jar
* flatRepo/dex-writer-2.0.jar
* flatRepo/hfsx.jar
* flatRepo/hfsx_dmglib.jar
* flatRepo/iharder-base64.jar
* cdt-8.6.0.zip
* PyDev 6.3.1.zip
* yajsw-stable-12.12.zip
2021-04-15 17:22:59 +00:00
* fidb/*.fidb
2019-06-04 19:21:06 +00:00
2019-06-24 18:12:31 +00:00
If you see these, congrats! Skip to [building ](#building-ghidra ) or [developing ](#developing-ghidra ). If not, continue with manual download
instructions below...
### Manual Download Instructions
2019-06-04 19:21:06 +00:00
2021-04-07 14:51:05 +00:00
Create the `~/git/ghidra/dependencies/` and `~/git/ghidra/dependencies/flatRepo` directories to hold the manually-downloaded dependencies:
2019-03-26 17:45:32 +00:00
```bash
2021-04-07 14:51:05 +00:00
mkdir ~/git/ghidra/dependencies
mkdir ~/git/ghidra/dependencies/flatRepo
2019-03-26 17:45:32 +00:00
```
2019-06-24 18:12:31 +00:00
#### Get Dependencies for FileFormats:
2019-03-26 17:45:32 +00:00
Download `dex-tools-2.0.zip` from the dex2jar project's releases page on GitHub.
2021-04-07 14:51:05 +00:00
Unpack the `dex-*.jar` files from the `lib` directory to `~/git/ghidra/dependencies/flatRepo` :
2019-03-26 17:45:32 +00:00
```bash
cd ~/Downloads # Or wherever
curl -OL https://github.com/pxb1988/dex2jar/releases/download/2.0/dex-tools-2.0.zip
unzip dex-tools-2.0.zip
2021-04-07 14:51:05 +00:00
cp dex2jar-2.0/lib/dex-*.jar ~/git/ghidra/dependencies/flatRepo/
2019-03-26 17:45:32 +00:00
```
Download `AXMLPrinter2.jar` from the "android4me" archive on code.google.com.
2021-04-07 14:51:05 +00:00
Place it in `~/git/ghidra/dependencies/flatRepo` :
2019-03-26 17:45:32 +00:00
```bash
2021-04-07 14:51:05 +00:00
cd ~/git/ghidra/dependencies/flatRepo
2019-03-26 17:45:32 +00:00
curl -OL https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android4me/AXMLPrinter2.jar
```
2019-06-24 18:12:31 +00:00
#### Get Dependencies for DMG:
2019-03-26 17:45:32 +00:00
Download `hfsexplorer-0_21-bin.zip` from www.catacombae.org.
2021-04-07 14:51:05 +00:00
Unpack the `lib` directory to `~/git/ghidra/dependencies/flatRepo` :
2019-03-26 17:45:32 +00:00
```bash
cd ~/Downloads # Or wherever
curl -OL https://sourceforge.net/projects/catacombae/files/HFSExplorer/0.21/hfsexplorer-0_21-bin.zip
mkdir hfsx
cd hfsx
unzip ../hfsexplorer-0_21-bin.zip
cd lib
2021-04-07 14:51:05 +00:00
cp csframework.jar hfsx_dmglib.jar hfsx.jar iharder-base64.jar ~/git/ghidra/dependencies/flatRepo/
2019-03-26 17:45:32 +00:00
```
2019-06-24 18:12:31 +00:00
#### Get Dependencies for GhidraServer
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
Building the GhidraServer requires "Yet another Java service wrapper" (yajsw) version 12.12.
2019-06-25 19:20:25 +00:00
Download `yajsw-stable-12.12.zip` from their project on www.sourceforge.net, and place it in:
2021-04-07 14:51:05 +00:00
`~/git/ghidra/dependencies/` :
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
```bash
cd ~/Downloads # Or wherever
curl -OL https://sourceforge.net/projects/yajsw/files/yajsw/yajsw-stable-12.12/yajsw-stable-12.12.zip
2021-04-07 14:51:05 +00:00
cp ~/Downloads/yajsw-stable-12.12.zip ~/git/ghidra/dependencies/
2019-06-24 18:12:31 +00:00
```
#### Get Dependencies for GhidraDev
Building the GhidraDev plugin for Eclipse requires the CDT and PyDev plugins for Eclipse.
2019-06-25 19:20:25 +00:00
Download `cdt-8.6.0.zip` from The Eclipse Foundation, and place it in:
2021-04-07 14:51:05 +00:00
`~/git/ghidra/dependencies/` :
2019-03-28 20:21:24 +00:00
```bash
2019-06-24 18:12:31 +00:00
cd ~/Downloads # Or wherever
2020-08-04 12:04:20 +00:00
curl -OL 'https://archive.eclipse.org/tools/cdt/releases/8.6/cdt-8.6.0.zip'
2019-10-18 05:58:54 +00:00
curl -o 'cdt-8.6.0.zip.sha512' -L --retry 3 'https://www.eclipse.org/downloads/sums.php?type=sha512& file=/tools/cdt/releases/8.6/cdt-8.6.0.zip'
2019-06-25 19:20:25 +00:00
shasum -a 512 -c 'cdt-8.6.0.zip.sha512'
2021-04-07 14:51:05 +00:00
cp ~/Downloads/cdt-8.6.0.zip ~/git/ghidra/dependencies/
2019-03-28 20:21:24 +00:00
```
2019-06-24 18:12:31 +00:00
Download `PyDev 6.3.1.zip` from www.pydev.org, and place it in the same directory:
2019-03-26 21:58:40 +00:00
2019-06-24 18:12:31 +00:00
```bash
cd ~/Downloads # Or wherever
2019-06-26 15:05:42 +00:00
curl -L -o 'PyDev 6.3.1.zip' https://sourceforge.net/projects/pydev/files/pydev/PyDev%206.3.1/PyDev%206.3.1.zip
2021-04-07 14:51:05 +00:00
cp ~/Downloads/'PyDev 6.3.1.zip' ~/git/ghidra/dependencies/
2019-06-24 18:12:31 +00:00
```
## Building Ghidra
Before building, you may want to update the version and release name.
2019-06-26 15:05:42 +00:00
These properties are kept in `~/git/ghidra/Ghidra/application.properties` .
2019-06-24 18:12:31 +00:00
To build the full package, use Gradle:
```bash
gradle buildGhidra
```
2019-06-26 15:05:42 +00:00
The output will be placed in `~/git/ghidra/build/dist/` .
2019-06-24 18:12:31 +00:00
It will be named according to the version, release name, build date, and platform.
To test it, unzip it where you like, and execute `./ghidraRun` .
2019-06-26 15:05:42 +00:00
__NOTE:__ Unless pre-built manually, the Eclipse GhidraDev plugin will not be included
in the build. In addition, some other supporting data will also be missing.
See the sections below for instructions on how to produce these components.
You may also be able to copy some of these already-built components from a previous official distribution.
2019-06-24 18:12:31 +00:00
## Developing Ghidra
### Prepare the Environment
2019-03-26 17:45:32 +00:00
From the project root, execute:
```bash
2019-06-24 18:12:31 +00:00
gradle prepDev
2019-03-26 17:45:32 +00:00
```
2019-03-28 20:21:24 +00:00
The `prepDev` tasks primarily include generating some source, indexing our built-in help, and unpacking some dependencies.
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
### Import Eclipse Projects
2020-04-09 17:10:44 +00:00
To develop/modify Ghidra, you must first use Gradle to generate Eclipse projects. From the project
root:
2019-03-26 17:45:32 +00:00
```bash
2019-06-24 18:12:31 +00:00
gradle eclipse
2019-03-26 17:45:32 +00:00
```
2019-06-24 18:12:31 +00:00
Select __File -> Import__ , expand General, and select "Existing Projects into Workspace."
Select the root of the source repo, and select "Search for nested projects."
Select all, and Finish.
You may see build path errors until the environment is properly prepared, as described below.
2019-03-26 17:45:32 +00:00
### Building the natives
Some of Ghidra's components are built for the native platform.
We currently support Linux, macOS, and Windows 64-bit x86 systems.
2019-03-28 20:21:24 +00:00
Others should be possible, but we do not test on them.
2019-03-26 17:45:32 +00:00
Now build using Gradle:
On Linux:
```bash
2019-03-29 15:10:47 +00:00
gradle buildNatives_linux64
2019-03-26 17:45:32 +00:00
```
On macOS:
```bash
2019-03-29 15:10:47 +00:00
gradle buildNatives_osx64
2019-03-26 17:45:32 +00:00
```
2019-04-05 00:29:15 +00:00
On Windows:
2019-03-26 17:45:32 +00:00
```bash
2019-03-29 15:10:47 +00:00
gradle buildNatives_win64
2019-03-26 17:45:32 +00:00
```
2019-03-29 15:10:47 +00:00
This will build the decompiler, the demangler for GNU toolchains, the sleigh compiler, and (on Windows only) the PDB parser.
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
### Pre-compile Language Modules (optional)
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
Optionally, to pre-compile all the language modules, you may also execute:
2019-03-26 17:45:32 +00:00
```bash
2019-06-24 18:12:31 +00:00
gradle sleighCompile
2019-03-26 17:45:32 +00:00
```
2019-06-24 18:12:31 +00:00
If the language modules are not pre-compiled, Ghidra will compile them at run time on an as-needed basis.
2019-03-26 17:45:32 +00:00
2019-06-26 15:05:42 +00:00
### Import and Build GhidraDev project (optional)
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
Developing the GhidraDev Eclipse plugin requires the _Eclipse PDE (Plug-in Development Environment)_ , which
can be installed via the Eclipse marketplace. It is also included in the _Eclipse IDE for RCP and RAP Developers_ .
To generate the GhidraDev Eclipse projects, execute:
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
```
gradle eclipse -PeclipsePDE
```
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
Import the newly generated GhidraDev projects into Eclipse.
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
__Note:__ If you are getting compilation errors related to PyDev and CDT, go into Eclipse's preferences,
and under _Target Platform_ , activate _/Eclipse GhidraDevPlugin/GhidraDev.target_ .
2019-03-26 17:45:32 +00:00
2019-06-26 15:05:42 +00:00
See `~/git/ghidra/GhidraBuild/EclipsePlugins/GhidraDev/GhidraDevPlugin/build_README.txt`
for instructions on how to build the GhidraDev plugin.
2019-11-13 17:05:38 +00:00
### Run and Debug Ghidra from Eclipse
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
To run or debug Ghidra from Eclipse, use the provided launch configuration (usually under the "Run" or "Debug" buttons).
If the launcher does not appear, it probably has not been marked as a favorite.
Click the dropdown next to the "Run" button and select "Run Configurations."
Then expand "Java Application" on the left to find the "Ghidra" launcher.
2019-03-26 17:45:32 +00:00
2019-07-24 07:09:56 +00:00
### Running tests
For running unit tests, run
2019-07-31 16:34:30 +00:00
gradle unitTestReport
2019-07-24 07:09:56 +00:00
for more complex integration tests run
2019-07-31 16:34:30 +00:00
gradle integrationTest
2019-07-24 07:09:56 +00:00
For running both unit test and integration test and generate report use
2019-07-31 16:34:30 +00:00
gradle combinedTestReport
2019-07-24 07:09:56 +00:00
## Setup build in CI
2019-07-31 16:34:30 +00:00
For running build in headless mode on Linux, in CI environment, or in Docker, before running tests, run
2019-07-24 07:09:56 +00:00
2019-07-31 16:34:30 +00:00
Xvfb :99 -nolisten tcp &
2019-07-24 07:09:56 +00:00
export DISPLAY=:99
this is required to make AWT happy.
2019-06-24 18:12:31 +00:00
## Building Supporting Data
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
Some features of Ghidra require the curation of rather extensive databases.
2019-03-26 17:45:32 +00:00
These include the Data Type Archives and Function ID Databases, both of which require collecting header files and libraries for the relevant SDKs and platforms.
2019-03-28 20:21:24 +00:00
Much of this work is done by hand.
2020-09-08 19:28:01 +00:00
The archives included in our official builds can be found in the [ghidra-data] repository.
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
### Building Data Type Archives
2019-03-26 17:45:32 +00:00
2019-04-02 19:27:40 +00:00
This task is often done manually from the Ghidra GUI, and the archives included in our official build require a fair bit of fine tuning.
2019-06-26 15:05:42 +00:00
From a CodeBrowser window, select __File -> Parse C Source__ .
2019-04-02 19:27:40 +00:00
From here you can create and configure parsing profiles, which lists headers and pre-processor options.
2019-06-26 15:05:42 +00:00
Then, click _Parse to File_ to create the Data Type Archive.
The result can be added to an installation or source tree by copying it to `~/git/ghidra/Ghidra/Features/Base/data/typeinfo` .
2019-03-26 17:45:32 +00:00
2019-06-24 18:12:31 +00:00
### Building FID Databases
2019-03-26 17:45:32 +00:00
2019-04-02 19:27:40 +00:00
This task is often done manually from the Ghidra GUI, and the archives included in our official build require a fair bit of fine tuning.
You will first need to import the relevant libraries from which you'd like to produce a FID database.
This is often a set of libraries from an SDK.
2021-02-09 23:28:06 +00:00
We include a variety of Visual Studio platforms in the official build. The official .fidb files can be found in the ghidra-data repository here https://github.com/NationalSecurityAgency/ghidra-data/tree/master/FunctionID
2019-04-02 19:27:40 +00:00
2019-06-26 15:05:42 +00:00
From a CodeBrowser window, select __File -> Configure__ .
2019-04-02 19:55:10 +00:00
Enable the "Function ID" plugins, and close the dialog.
2019-06-26 15:05:42 +00:00
Now, from the CodeBrowser window, select __Tools -> Function ID -> Create new empty FidDb__ .
2019-04-02 19:27:40 +00:00
Choose a destination file.
2019-06-26 15:05:42 +00:00
Now, select __Tools -> Function ID -> Populate FidDb__ from programs.
2019-04-02 19:27:40 +00:00
Fill out the options appropriately and click OK.
2019-06-26 15:05:42 +00:00
If you'd like some details of our fine tuning, take a look at `~/git/ghidra/Ghidra/Features/FunctionID/data/building_fid.txt` .
2020-09-08 19:28:01 +00:00
[ghidra-data]: https://github.com/NationalSecurityAgency/ghidra-data