This Ghidra extension allows running ghidra-scripts written in Kotlin.
The extension uses kotlinc
to compile Kotlin scripts.
To install it, follow the instructions here.
When finished, make sure that kotlinc
is in your PATH
.
- Download the latest build for your version of Ghidra
- In the main Ghidra window, go to
File -> Install Extensions
to open the extensions window - Once there, press the green
+
sign to install a new extension - Choose the zip archive you downloaded
- Restart Ghidra
- Download the latest build for your version of Ghidra
- Unpack it into
$GHIDRA_HOME/Ghidra/Extensions
- Launch Ghidra
Once installed, you can use .kt
scripts just like .java
and .py
scripts.
Under ghidra_scripts
you can find some example scripts.
The scripts are (mostly automatically) translated from Java scripts provided with Ghidra.
Once you install the extension, they should be available in the Script Manager.
To develop Kotlin in IntelliJ IDEA, with full auto-completion for the Ghidra APIs, there are a few simple steps you need to perform:
- Create a new Kotlin project in IntelliJ (see this tutorial)
- Build the
ghidra.jar
. This only needs to be done once.$GHIDRA_HOME/support/buildGhidraJar
- Define the generated
$GHIDRA_HOME/support/ghidra.jar
as a global library in IntelliJ (see defining global libraries). This only needs to be done once. This only needs to be done once, and will allow you to use it easily in the future. - Add the library from the previous step to your module dependencies (see adding libraries to module dependencies).
- To load the scripts into Ghidra, add the
src
directory of your project to the Script Directories in Ghidra's Script Manager. - For easy script creation, add the following template to your IntelliJ file templates:
import ghidra.app.script.GhidraScript class ${NAME} : GhidraScript() { override fun run() { TODO("Write your code here.") } }
If you have MyScript.java
and MyScript.kt
, and you run one of them, its code will be
used for both.
This happens because both will be compiled to MyScript.class
. Once the first one is built,
Ghidra will find a .class
file with a matching name and just use that.
This is why all the example scripts have Kt
appended to the names.
Gradle is required for building the extension. Please see the
application.gradle.version
property in <GHIDRA_INSTALL_DIR>/Ghidra/application.properties
for the correction version of Gradle to use for the Ghidra installation you specify.
Follow the instructions here to install the correct version of Gradle.
If you plan to use the "proper" install method, ensure the version in your extension.properties
matches your Ghidra version.
To build, open a terminal in the project directory and run the following:
export GHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
gradle
If everything succeeds, you should see BUILD SUCCESSFUL
written to the screen.
If the build fails with error: cannot access ghidra.app.script
, just give it another
go and it should work.
Once done, a zip archive with the extension will be created under the dist
directory.