diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index efaa6f8..24131c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build with Maven +name: Build with Gradle on: push: @@ -12,15 +12,6 @@ jobs: env: GHIDRA_VERSION: 11.4.1 GHIDRA_DATE: 20250731 - GHIDRA_LIBS: >- - Features/Base/lib/Base.jar - Features/Decompiler/lib/Decompiler.jar - Framework/Docking/lib/Docking.jar - Framework/Generic/lib/Generic.jar - Framework/Project/lib/Project.jar - Framework/SoftwareModeling/lib/SoftwareModeling.jar - Framework/Utility/lib/Utility.jar - Framework/Gui/lib/Gui.jar steps: - uses: actions/checkout@v4 @@ -29,29 +20,15 @@ jobs: with: java-version: '21' distribution: 'temurin' - cache: maven + cache: gradle - name: Download Ghidra run: | wget --no-verbose -O ghidra.zip https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_${{ env.GHIDRA_VERSION }}_build/ghidra_${{ env.GHIDRA_VERSION }}_PUBLIC_${{ env.GHIDRA_DATE }}.zip 7z x -bd ghidra.zip - - name: Copy Ghidra libs - run: | - mkdir -p ./lib - for libfile in ${{ env.GHIDRA_LIBS }} - do echo "Copying ${libfile} to lib/" - cp ghidra_${{ env.GHIDRA_VERSION }}_PUBLIC/Ghidra/${libfile} ./lib/ - done - - - name: Build with Maven - run: mvn clean package assembly:single - - - name: Assemble release directory - run: | - mkdir release - cp target/GhidraMCP-*.zip release/ - cp bridge_mcp_ghidra.py release/ + - name: Build with Gradle + run: gradle - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index 900dbfc..a5036d9 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,6 @@ etc/ # Autogenerated files docs/ dependency-reduced-pom.xml +.gradle/ +build/ +dist/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..6048aa9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,50 @@ +// Builds a Ghidra Extension for a given Ghidra installation. +// +// An absolute path to the Ghidra installation directory must be supplied either by setting the +// GHIDRA_INSTALL_DIR environment variable or Gradle project property: +// +// > export GHIDRA_INSTALL_DIR= +// > gradle +// +// or +// +// > gradle -PGHIDRA_INSTALL_DIR= +// +// Gradle should be invoked from the directory of the project to build. Please see the +// application.gradle.version property in /Ghidra/application.properties +// for the correction version of Gradle to use for the Ghidra installation you specify. +plugins { + id 'java' + id 'eclipse' + id 'idea' +} + +def ghidraInstallDir + +if (System.env.GHIDRA_INSTALL_DIR) { + ghidraInstallDir = System.env.GHIDRA_INSTALL_DIR +} else if (project.hasProperty("GHIDRA_INSTALL_DIR")) { + ghidraInstallDir = project.getProperty("GHIDRA_INSTALL_DIR") +} + +if (ghidraInstallDir) { + apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle" +} else { + throw new GradleException("GHIDRA_INSTALL_DIR is not defined!") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'com.google.code.gson:gson:2.10.1' + implementation 'org.reflections:reflections:0.10.2' + + testImplementation 'junit:junit:4.13.2' +} + +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} diff --git a/src/main/resources/extension.properties b/extension.properties similarity index 66% rename from src/main/resources/extension.properties rename to extension.properties index 281a5a9..cbc5984 100644 --- a/src/main/resources/extension.properties +++ b/extension.properties @@ -1,6 +1,5 @@ name=GhidraMCP description=A plugin that runs an embedded HTTP server to expose program data. author=LaurieWired -createdOn=2025-07-31 -version=11.4.1 -ghidraVersion=11.4.1 \ No newline at end of file +createdOn= +version=2.3.1 diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 1a13ca0..0000000 --- a/pom.xml +++ /dev/null @@ -1,209 +0,0 @@ - - - 4.0.0 - com.lauriewired - GhidraMCP - jar - 2.3 - GhidraMCP - http://maven.apache.org - - - - - ghidra - Generic - 11.4.1 - system - ${project.basedir}/lib/Generic.jar - - - ghidra - SoftwareModeling - 11.4.1 - system - ${project.basedir}/lib/SoftwareModeling.jar - - - ghidra - Project - 11.4.1 - system - ${project.basedir}/lib/Project.jar - - - ghidra - Docking - 11.4.1 - system - ${project.basedir}/lib/Docking.jar - - - ghidra - Decompiler - 11.4.1 - system - ${project.basedir}/lib/Decompiler.jar - - - ghidra - Utility - 11.4.1 - system - ${project.basedir}/lib/Utility.jar - - - ghidra - Base - 11.4.1 - system - ${project.basedir}/lib/Base.jar - - - ghidra - Gui - 11.4.1 - system - ${project.basedir}/lib/Gui.jar - - - - org.reflections - reflections - 0.10.2 - - - - - junit - junit - 3.8.1 - test - - - - - com.google.code.gson - gson - 2.10.1 - - - - - 21 - 21 - UTF-8 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - 21 - 21 - - -Xlint:-options - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.5.0 - - - package - - shade - - - GhidraMCP - - - - - ghidra:* - - - - - - - - - - maven-jar-plugin - 3.2.2 - - - src/main/resources/META-INF/MANIFEST.MF - - - GhidraMCP - - - **/App.class - - - ${project.build.directory} - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.3.0 - - - - src/assembly/ghidra-extension.xml - - - - GhidraMCP-${project.version} - - - false - - - - - make-assembly - package - - single - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.1.2 - - - copy-dependencies - prepare-package - - copy-dependencies - - - ${project.build.directory}/lib - runtime - - - - - - - diff --git a/src/assembly/ghidra-extension.xml b/src/assembly/ghidra-extension.xml deleted file mode 100644 index b176e7f..0000000 --- a/src/assembly/ghidra-extension.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - ghidra-extension - - - - zip - - - - false - - - - - src/main/resources - - extension.properties - Module.manifest - - GhidraMCP - - - - - ${project.build.directory} - - - GhidraMCP.jar - - GhidraMCP/lib - - - - - . - - LICENSE - - GhidraMCP - - - diff --git a/src/main/java/com/lauriewired/handlers/act/DisassembleFunction.java b/src/main/java/com/lauriewired/handlers/act/DisassembleFunction.java index c60c8f1..7aa5216 100644 --- a/src/main/java/com/lauriewired/handlers/act/DisassembleFunction.java +++ b/src/main/java/com/lauriewired/handlers/act/DisassembleFunction.java @@ -73,7 +73,7 @@ private String disassembleFunction(String addressStr) { if (instr.getAddress().compareTo(end) > 0) { break; // Stop if we've gone past the end of the function } - String comment = listing.getComment(CodeUnit.EOL_COMMENT, instr.getAddress()); + String comment = listing.getComment(CommentType.EOL, instr.getAddress()); comment = (comment != null) ? "; " + comment : ""; result.append(String.format("%s: %s %s\n", diff --git a/src/main/java/com/lauriewired/handlers/comment/SetDecompilerComment.java b/src/main/java/com/lauriewired/handlers/comment/SetDecompilerComment.java index 0832d34..12edf45 100644 --- a/src/main/java/com/lauriewired/handlers/comment/SetDecompilerComment.java +++ b/src/main/java/com/lauriewired/handlers/comment/SetDecompilerComment.java @@ -3,7 +3,7 @@ import com.lauriewired.handlers.Handler; import com.sun.net.httpserver.HttpExchange; import ghidra.framework.plugintool.PluginTool; -import ghidra.program.model.listing.CodeUnit; +import ghidra.program.model.listing.CommentType; import java.util.Map; @@ -48,6 +48,6 @@ public void handle(HttpExchange exchange) throws Exception { * @return true if the comment was set successfully, false otherwise */ private boolean setDecompilerComment(String addressStr, String comment) { - return setCommentAtAddress(tool, addressStr, comment, CodeUnit.PRE_COMMENT, "Set decompiler comment"); + return setCommentAtAddress(tool, addressStr, comment, CommentType.PRE, "Set decompiler comment"); } } diff --git a/src/main/java/com/lauriewired/handlers/comment/SetDisassemblyComment.java b/src/main/java/com/lauriewired/handlers/comment/SetDisassemblyComment.java index f6c59f4..f9e4ce4 100644 --- a/src/main/java/com/lauriewired/handlers/comment/SetDisassemblyComment.java +++ b/src/main/java/com/lauriewired/handlers/comment/SetDisassemblyComment.java @@ -3,7 +3,7 @@ import com.lauriewired.handlers.Handler; import com.sun.net.httpserver.HttpExchange; import ghidra.framework.plugintool.PluginTool; -import ghidra.program.model.listing.CodeUnit; +import ghidra.program.model.listing.CommentType; import java.util.Map; @@ -49,6 +49,6 @@ public void handle(HttpExchange exchange) throws Exception { * @return true if the comment was set successfully, false otherwise */ private boolean setDisassemblyComment(String addressStr, String comment) { - return setCommentAtAddress(tool, addressStr, comment, CodeUnit.EOL_COMMENT, "Set disassembly comment"); + return setCommentAtAddress(tool, addressStr, comment, CommentType.EOL, "Set disassembly comment"); } } diff --git a/src/main/java/com/lauriewired/handlers/set/SetFunctionPrototype.java b/src/main/java/com/lauriewired/handlers/set/SetFunctionPrototype.java index 3e4616f..3bcfd46 100644 --- a/src/main/java/com/lauriewired/handlers/set/SetFunctionPrototype.java +++ b/src/main/java/com/lauriewired/handlers/set/SetFunctionPrototype.java @@ -5,7 +5,7 @@ import ghidra.framework.plugintool.PluginTool; import ghidra.program.model.address.Address; import ghidra.program.model.data.DataTypeManager; -import ghidra.program.model.listing.CodeUnit; +import ghidra.program.model.listing.CommentType; import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Program; import ghidra.program.model.symbol.SourceType; @@ -186,7 +186,7 @@ private void addPrototypeComment(Program program, Function func, String prototyp try { program.getListing().setComment( func.getEntryPoint(), - CodeUnit.PLATE_COMMENT, + CommentType.PLATE, "Setting prototype: " + prototype); } finally { program.endTransaction(txComment, true); diff --git a/src/main/java/com/lauriewired/util/GhidraUtils.java b/src/main/java/com/lauriewired/util/GhidraUtils.java index dd0a81e..9b3c619 100644 --- a/src/main/java/com/lauriewired/util/GhidraUtils.java +++ b/src/main/java/com/lauriewired/util/GhidraUtils.java @@ -6,6 +6,7 @@ import ghidra.program.model.data.DataTypeManager; import ghidra.program.model.address.Address; import ghidra.program.model.listing.Program; +import ghidra.program.model.listing.CommentType; import ghidra.util.Msg; import javax.swing.*; @@ -85,7 +86,7 @@ public static DataType resolveDataType(PluginTool tool, DataTypeManager dtm, Str * @return true if successful, false otherwise */ public static boolean setCommentAtAddress(PluginTool tool, - String addressStr, String comment, int commentType, String transactionName) { + String addressStr, String comment, CommentType commentType, String transactionName) { Program program = getCurrentProgram(tool); if (program == null) return false; diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index 4145ab2..0000000 --- a/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,6 +0,0 @@ -Manifest-Version: 1.0 -Plugin-Class: com.lauriewired.GhidraMCP -Plugin-Name: GhidraMCP -Plugin-Version: 1.0 -Plugin-Author: LaurieWired -Plugin-Description: A custom plugin by LaurieWired diff --git a/src/main/resources/Module.manifest b/src/main/resources/Module.manifest deleted file mode 100644 index 7c9fc6f..0000000 --- a/src/main/resources/Module.manifest +++ /dev/null @@ -1,6 +0,0 @@ -MODULE_FILE_LICENSE: LICENSE -MODULE_VERSION: 1.0 -GHIDRA_MODULE_NAME: GhidraMCP -GHIDRA_MODULE_DESC: An HTTP server plugin for Ghidra -GHIDRA_MIN_FRAMEWORK_VERSION: 11.4 -GHIDRA_MAX_FRAMEWORK_VERSION: diff --git a/src/test/java/com/lauriewired/AppTest.java b/src/test/java/com/lauriewired/AppTest.java deleted file mode 100644 index a39d69e..0000000 --- a/src/test/java/com/lauriewired/AppTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.lauriewired; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest(String testName) { - super(testName); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() { - return new TestSuite(AppTest.class); - } - - /** - * Rigourous Test :-) - */ - public void testApp() { - assertTrue(true); - } -}