Skip to content

Instantly share code, notes, and snippets.

@jstaursky
Last active September 7, 2022 20:04
Show Gist options
  • Save jstaursky/7caae3f964e8f6ac032d8c6985319265 to your computer and use it in GitHub Desktop.
Save jstaursky/7caae3f964e8f6ac032d8c6985319265 to your computer and use it in GitHub Desktop.
Ghidra plugin development with emacs
  1. Need to create ghidra.jar and place into the lib directory.
  2. run below script to create the directory structure
  3. put the following contents in the src/main/java/MyProject.java file
    import ghidra.app.script.GhidraScript;
    
      public class MyProject extends GhidraScript {
    
      @Override
      public void run() throws Exception {
      println("Hello World");
      }
    }
        
  4. Enter gradle build at the root directory.
  5. Open in Spacemacs.
#!/bin/sh
# usage ./<this-script> <project-name>
project="${1:-MyProject}"
toplevel='src,lib'
echo -n ${toplevel} | xargs -d, -I% mkdir -p ${project}/%
mkdir -p ${project}/src/main/java
touch ${project}/src/main/java/${project}.java
touch ${project}/settings.gradle
# create an initial build.gradle file
cat << EOF > ${project}/build.gradle
apply plugin: 'java'
dependencies {
implementation fileTree (dir: 'lib', include: ['*.jar'])
}
EOF
# Readme
cat << EOF > ${project}/README.org
The file =src/main/java/<file-name>.java=
must have "=public class <file-name> ...=" in it.
to compile enter
=gradle build= at the root directory.
You should be able to drop any =jar= file into the =lib= directory
and be able to import it for use in the =src/main/java/<file-name>.java= file.
EOF
echo "created project folder '${project}'"
#!/bin/sh
GHIDRA_HOME="$HOME/ghidra_10.1.5_PUBLIC"
FILENAME=$1
SCRIPT=$2
DIR=${SCRIPT%/*}
TMP_PROJECT_NAME=$RANDOM
CMD="$GHIDRA_HOME/support/analyzeHeadless \"/tmp\" \"$TMP_PROJECT_NAME\" -deleteProject "
$CMD -import "$FILENAME" -scriptPath $DIR -postScript $SCRIPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment