|
| 1 | +# Ghidra Extension in Kotlin using IntelliJ IDEA |
| 2 | + |
| 3 | +> Write a Ghidra Extension without using Java or Eclipse! |
| 4 | +
|
| 5 | +## Setup |
| 6 | + |
| 7 | +* Hit `Use this template` at the top of the repo on GitHub |
| 8 | +* Clone the new repo to your development machine |
| 9 | +* Add the line `GHIDRA_INSTALL_DIR=/path/to/your/ghidra_10.1_PUBLIC/` to `$HOME/.gradle/gradle.properties` |
| 10 | +* Open IntelliJ, create a new `Project from Existing Sources...` and select the `build.gradle` |
| 11 | + * If you are using the [Kotlin Jupyter Plugin](https://github.com/GhidraJupyter/ghidra-jupyter-kotlin) uncomment the line in the `dependencies` block in the `build.gradle` |
| 12 | +* Wait for IntelliJ to finish indexing and fetching dependencies, hit the build button, and then run Ghidra |
| 13 | + |
| 14 | + |
| 15 | +## Features |
| 16 | + |
| 17 | +* Gradle Config that works out of the box with IntelliJ |
| 18 | +* IntelliJ IDEA Run Configuration for debugging of the extension |
| 19 | + * If you have are using the [Kotlin Jupyter Plugin](https://github.com/GhidraJupyter/ghidra-jupyter-kotlin) you can also set breakpoints in the script file! |
| 20 | +* GitHub CI files that |
| 21 | + * make sure the extension at least builds for each PR |
| 22 | + * will automatically build a release and publish it on GitHub if a commit is tagged with a version matching `vX.X.X`, e.g. `v1.2.3`/`v1.2.0` (`v1.2` doesn't work!) |
| 23 | + |
| 24 | + |
| 25 | +## Additional Development Tips |
| 26 | + |
| 27 | +These aspects can not be included in the repo files itself, but make development smoother. |
| 28 | + |
| 29 | +### Thread Breakpoints |
| 30 | + |
| 31 | +Make sure that you use breakpoints that only suspend the thread, and not everything. |
| 32 | +This means that the breakpoint will only suspend the thread that is currently running the analysis or the script, |
| 33 | +and the GUI will keep working. |
| 34 | + * Set a breakpoint, right-click the icon, and in the `Suspend` line select `Thread` instead of `All` |
| 35 | + * IntelliJ IDEA will suggest making this the default, click this too |
| 36 | + |
| 37 | + |
| 38 | +### Use Scripts and the Jupyter Kernel to prototype ideas |
| 39 | + |
| 40 | +With the [Kotlin Jupyter Plugin](https://github.com/GhidraJupyter/ghidra-jupyter-kotlin) you can test your new ideas first. |
| 41 | +IntelliJ IDEA can do hot reloading of classes, but this has limits and then requires an IDE restart, |
| 42 | +which take an annoying amount of time. The QT Console only is fairly basic, but the Jupyter Notebook uses nearly the same |
| 43 | +code analysis engine as IntelliJ itself. |
| 44 | + |
| 45 | +### Automatic conversion to Kotlin |
| 46 | + |
| 47 | +* pasting Java code into a Kotlin file you will get the suggestion for this to be converted and then pasted |
| 48 | +* right-click `.java` file in the Project Tree there is an action at the very bottom to convert the entire file |
| 49 | + |
| 50 | + |
| 51 | +## Issues |
| 52 | + |
| 53 | +If any step in this process doesn't work as described in the README, please open an issue on GitHub. |
| 54 | +I have only tested this on Linux so there might be some aspects that work differently on macOS or Windows, though these |
| 55 | +should be minor. |
0 commit comments