generated from fmagin/ghidra-kotlin-extension-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
229 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,49 @@ | ||
# Ghidra Extension in Kotlin using IntelliJ IDEA | ||
# OpenAI Integration for Ghidra | ||
|
||
> Write a Ghidra Extension without using Java or Eclipse! | ||
> Get Function Summaries from ChatGTP | ||
## Setup | ||
## Installation | ||
|
||
* Hit `Use this template` at the top of the repo on GitHub | ||
* Clone the new repo to your development machine | ||
* Add the line `GHIDRA_INSTALL_DIR=/path/to/your/ghidra_10.1_PUBLIC/` to `$HOME/.gradle/gradle.properties` | ||
* Open IntelliJ, create a new `Project from Existing Sources...` and select the `build.gradle` | ||
* 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` | ||
* Wait for IntelliJ to finish indexing and fetching dependencies, hit the build button, and then run Ghidra | ||
1. This plugin requires Kotlin language support in Ghidra, so make sure that you have it installed: | ||
https://github.com/GhidraJupyter/ghidra-jupyter-kotlin/releases | ||
|
||
2. Grab the latest release of this Plugin from the [releases page](https://github.com/fmagin/ghidra-openai/releases) | ||
and install it in Ghidra. | ||
|
||
## Features | ||
|
||
* Gradle Config that works out of the box with IntelliJ | ||
* IntelliJ IDEA Run Configuration for debugging of the extension | ||
* 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! | ||
* GitHub CI files that | ||
* make sure the extension at least builds for each PR | ||
* 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!) | ||
|
||
## Usage | ||
|
||
## Additional Development Tips | ||
### Initial Setup | ||
|
||
These aspects can not be included in the repo files itself, but make development smoother. | ||
Configure your API Key via `Edit -> Tool Options -> OpenAI` | ||
|
||
### Thread Breakpoints | ||
![img.png](imgs/API_key.png) | ||
|
||
Make sure that you use breakpoints that only suspend the thread, and not everything. | ||
This means that the breakpoint will only suspend the thread that is currently running the analysis or the script, | ||
and the GUI will keep working. | ||
* Set a breakpoint, right-click the icon, and in the `Suspend` line select `Thread` instead of `All` | ||
* IntelliJ IDEA will suggest making this the default, click this too | ||
|
||
### GUI Integration | ||
|
||
### Use Scripts and the Jupyter Kernel to prototype ideas | ||
Right Click in the Decompiler, and select `Get and apply Function Summary via OpenAI` | ||
|
||
With the [Kotlin Jupyter Plugin](https://github.com/GhidraJupyter/ghidra-jupyter-kotlin) you can test your new ideas first. | ||
IntelliJ IDEA can do hot reloading of classes, but this has limits and then still requires a Ghidra restart, | ||
which takes an annoying amount of time. The QT Console is fairly basic, but the Jupyter Notebook uses nearly the same | ||
code analysis engine as IntelliJ itself. | ||
Before: | ||
![img.png](imgs/before.png) | ||
|
||
### Automatic conversion to Kotlin | ||
After: | ||
![img.png](imgs/after.png) | ||
|
||
* pasting Java code into a Kotlin file you will get the suggestion for this to be converted and then pasted | ||
* right-click `.java` file in the Project Tree there is an action at the very bottom to convert the entire file | ||
|
||
### Configuration | ||
|
||
## Issues | ||
You can easily change the model used for the completions and its parameters via | ||
the `Edit -> Tool Options -> OpenAI -> Model` menu. | ||
|
||
If any step in this process doesn't work as described in the README, please open an issue on GitHub. | ||
I have only tested this on Linux so there might be some aspects that work differently on macOS or Windows, though these | ||
should be minor. | ||
![img.png](imgs/parameters.png) | ||
|
||
The decompiled text will be appended to the prompt and will be sent as a completion request to the OpenAI API. | ||
|
||
### Known issues | ||
|
||
#### Ghidra looks even worse than usual when run via IDE | ||
## Potential Future Work | ||
|
||
The run configuration only includes the class loader VM option, and none of the others that are usually set by the | ||
Ghidra launch script, which include OpenGL settings and Font Anti Aliasing, because this depends on the OS. | ||
|
||
Generate the VM options for your system: | ||
```sh | ||
cd $GHIDRA_INSTALL_DIR | ||
java -cp ./support/LaunchSupport.jar LaunchSupport ./support/.. -vmargs | ||
``` | ||
|
||
and then [edit the run configuration](https://www.jetbrains.com/help/idea/run-debug-configuration.html) and add them. | ||
No promises that I will ever implement them, but I'll gladly provide advice if you want to try: | ||
* Dedicated Dialog that previews the function summary and allows retrying before applying | ||
* Allow a custom prompt to be specified for a specific _program_ via the `Options for $program` menu | ||
* Request better variable or function names like https://github.com/JusticeRage/Gepetto does |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=@extname@ | ||
description=Kotlin Example Extension. | ||
description=OpenAI Integration Proof of Concept. | ||
author=Florian Magin | ||
createdOn=2021-12-15 | ||
createdOn=2022-12-06 | ||
version=@extversion@ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.