Skip to content

Commit

Permalink
Add support for Ghidra 10.4 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-eschwartz authored Oct 3, 2023
1 parent 2563fec commit 6feaa30
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 752 deletions.
598 changes: 0 additions & 598 deletions .classpath

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release_on_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
ghidra_version: [10.3, 10.3.1, 10.3.2, 10.3.3]
ghidra_version: [10.3, 10.3.1, 10.3.2, 10.3.3, 10.4]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/run_tests_on_push_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
ghidra_version: [10.3, 10.3.1, 10.3.2, 10.3.3]
ghidra_version: [10.3, 10.3.1, 10.3.2, 10.3.3, 10.4]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up ccache
uses: hendrikmuhs/[email protected]
- name: Set up ccache PATH
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -44,7 +49,7 @@ jobs:
GHIDRA_INSTALL_DIR: '${{ github.workspace }}/ghidra_${{ matrix.ghidra_version }}_PUBLIC/'
KAIJU_AUTOCATS_DIR: '${{ github.workspace }}/autocats/'
run: |
gradle --build-cache install
env CC="cache gcc" CXX="ccache g++" gradle --build-cache install
- name: Checkout AUTOCATS repo for testing
uses: actions/checkout@v3
with:
Expand Down
41 changes: 0 additions & 41 deletions .project

This file was deleted.

22 changes: 17 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def minor;
String[] str;
str = ghidraInstallDir.split('_');
for( String values : str )
if (values =~ '[0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,}') {
if (values =~ '[0-9]{1,}\\.[0-9]{1,}(\\.[0-9]{1,})?') {
ghidraVersion = values;
String[] substr = values.split('\\.');
minor = substr[1] as int;
Expand Down Expand Up @@ -123,16 +123,22 @@ if (VersionNumber.parse( gradle.gradleVersion ) <= VersionNumber.parse ("6.8.0")
throw new GradleException("CERT Kaiju requires at least gradle version 6.8.0. Please update gradle and retry.")
}

// Export GHIDRA_10_4 for conditional compilation
compileJava {
options.compilerArgs << '-AGHIDRA_10_4=' + (VersionNumber.parse( ghidraVersion ) >= VersionNumber.parse("10.4"))
}
compileTestJava {
options.compilerArgs << '-AGHIDRA_10_4=' + (VersionNumber.parse( ghidraVersion ) >= VersionNumber.parse("10.4"))
}
repositories {
mavenCentral()
}

dependencies {
//testRuntimeOnly('org.opentest4j:opentest4j:1.1.1')
// implementation(
// ':com.microsoft.z3:4.12.1.0'
// ) { because "Z3 is required to use Kaiju Ghihorn." }

annotationProcessor 'systems.manifold:manifold-preprocessor:2023.1.28'
testAnnotationProcessor 'systems.manifold:manifold-preprocessor:2023.1.28'

testImplementation(
'junit:junit:4.12', // needed on classpath to support junit 5 vintage
'org.junit.jupiter:junit-jupiter-api:5.9.2',
Expand All @@ -145,6 +151,11 @@ dependencies {
)
}

tasks.withType(JavaCompile) {
// If you DO NOT define a module-info.java file:
options.compilerArgs += ['-Xplugin:Manifold']
}

// don't include files not needed for runtime!
buildExtension.exclude 'azure-pipelines.yml'
buildExtension.exclude '*.bak'
Expand Down Expand Up @@ -462,6 +473,7 @@ test {
testLogging {
events "passed", "skipped", "failed"
exceptionFormat = 'full'
showStackTraces = true
}

beforeSuite { descriptor ->
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/kaiju/AlignmentAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,10 @@
import docking.action.*;
import ghidra.app.context.ListingActionContext;
import ghidra.app.plugin.core.data.DataPlugin;
import ghidra.app.util.datatype.DataTypeSelectionDialog;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.data.AlignmentDataType;
import ghidra.program.model.data.DataType;
import ghidra.program.model.listing.Data;
import ghidra.util.data.DataTypeParser.AllowedDataTypes;

import kaiju.common.di.GhidraDI;

import java.lang.reflect.*;
// try
// {
// c.getDeclaredMethod("allowSwingToProcessEvents");
// try {
// c.getDeclaredMethod("allowSwingToProcessEvents").invoke(this);
// } catch (Exception e) {
// Msg.warn(this, "Error invoking function.");
// } catch(NoSuchMethodException e) {
// Msg.warn(this, "Unable to locate allowSwingToProcessEvents. The GUI may be irresponsive.");
// }

/**
* An action that allows the user to set an Alignment data type.
*/
Expand Down Expand Up @@ -85,7 +68,7 @@ public void actionPerformed(ActionContext context) {
} catch (ClassNotFoundException e) {
//TODO
}
Class[] cArg = new Class[3];
Class<?>[] cArg = new Class[3];
cArg[0] = DataType.class;
cArg[1] = ListingActionContext.class;
cArg[2] = boolean.class;
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/kaiju/common/KaijuGhidraCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/***
* CERT Kaiju Copyright 2021 Carnegie Mellon University.
*
* NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS
* FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER
* EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
* PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE
* MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT,
* TRADEMARK, OR COPYRIGHT INFRINGEMENT.
*
* Released under a BSD (SEI)-style license, please see LICENSE.md or contact [email protected]
* for full terms.
*
* [DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited
* distribution. Please see Copyright notice for non-US Government use and distribution.
*
* Carnegie Mellon (R) and CERT (R) are registered in the U.S. Patent and Trademark Office by
* Carnegie Mellon University.
*
* This Software includes and/or makes use of the following Third-Party Software subject to its own
* license: 1. OpenJDK (http://openjdk.java.net/legal/gplv2+ce.html) Copyright 2021 Oracle. 2.
* Ghidra (https://github.com/NationalSecurityAgency/ghidra/blob/master/LICENSE) Copyright 2021
* National Security Administration. 3. GSON (https://github.com/google/gson/blob/master/LICENSE)
* Copyright 2020 Google. 4. JUnit (https://github.com/junit-team/junit5/blob/main/LICENSE.md)
* Copyright 2020 JUnit Team. 5. Gradle (https://github.com/gradle/gradle/blob/master/LICENSE)
* Copyright 2021 Gradle Inc. 6. markdown-gradle-plugin
* (https://github.com/kordamp/markdown-gradle-plugin/blob/master/LICENSE.txt) Copyright 2020 Andres
* Almiray. 7. Z3 (https://github.com/Z3Prover/z3/blob/master/LICENSE.txt) Copyright 2021 Microsoft
* Corporation. 8. jopt-simple (https://github.com/jopt-simple/jopt-simple/blob/master/LICENSE.txt)
* Copyright 2021 Paul R. Holser, Jr.
*
* DM21-0792
*/
package kaiju.common;

import java.lang.reflect.InvocationTargetException;
import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;

public class KaijuGhidraCompat {

/**
* This is a helper function to return the ToolOptions for a specific service.
* @param sp The service provider
* @param serviceNAme The specific service
* @return The ToolOptions for service
* @throws SecurityException
* @throws InvocationTargetException
* @throws IllegalArgumentException
**/
public static ToolOptions getToolOptions(ServiceProvider sp, String serviceName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException {
Class<?> OptionsServiceClass;

try {
OptionsServiceClass = Class.forName("ghidra.framework.plugin.util.OptionsService");
}
catch (ClassNotFoundException e) {
OptionsServiceClass = Class.forName("docking.options.OptionsService");
}

var optionService = sp.getService(OptionsServiceClass);

if (optionService != null) {
ToolOptions opt = (ToolOptions) OptionsServiceClass.getMethod("getOptions", String.class).invoke(optionService, serviceName);
return opt;
} else {
throw new RuntimeException("Could not get options for service " + serviceName);
}
}
}
10 changes: 0 additions & 10 deletions src/main/java/kaiju/tools/disasm/DisasmImprovementsAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,20 @@
import ghidra.app.services.AnalysisPriority;
import ghidra.app.services.AnalyzerType;
import ghidra.app.util.importer.MessageLog;
import ghidra.framework.task.gui.GProgressBar;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressRange;
import ghidra.program.model.address.AddressRangeImpl;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.data.BuiltInDataTypeManager;
import ghidra.program.model.data.CategoryPath;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.lang.Processor;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Instruction;
import ghidra.program.model.listing.Listing;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
import kaiju.common.KaijuLogger;
import kaiju.tools.disasm.DisasmImprover;
import kaiju.tools.disasm.GhidraTypeUtilities;
import kaiju.util.Pair;

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/kaiju/tools/disasm/DisasmImprover.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
package kaiju.tools.disasm;

import ghidra.program.model.address.AddressRange;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Program;
import ghidra.util.task.TaskMonitor;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/kaiju/tools/disasm/DisasmStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.data.DataType;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Listing;
import ghidra.program.model.listing.Program;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/kaiju/tools/disasm/GhidraTypeUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
*/
package kaiju.tools.disasm;

import ghidra.app.cmd.disassemble.DisassembleCommand;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressRange;
import ghidra.program.model.address.AddressRangeImpl;
import ghidra.program.model.data.BuiltInDataTypeManager;
import ghidra.program.model.data.CategoryPath;
import ghidra.program.model.data.DataType;
Expand All @@ -43,8 +40,6 @@
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Instruction;
import ghidra.program.model.listing.Listing;
import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.util.task.TaskMonitor;

/**
* A static class with utility functions for locating Ghidra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressRange;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Listing;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/kaiju/tools/fnhash/FnHashPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
package kaiju.tools.fnhash;

import java.io.File;
import javax.swing.ImageIcon;

import docking.ActionContext;
import docking.action.DockingAction;
Expand Down Expand Up @@ -125,7 +124,6 @@ protected void init() {
createActions();

this.openFnHashAction = new ActionBuilder("Open Fn2Hash", getName())
.supportsDefaultToolContext(true)
.menuPath("&Kaiju", "Fn2Hash")
.onAction(c -> provider.setVisible(true))
.menuIcon(null)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/kaiju/tools/fnhash/HashViewerContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@
import java.util.List;
import java.util.function.Predicate;

#if GHIDRA_10_4 == "true"
import docking.DefaultActionContext;
#else
import docking.ActionContext;
#endif
import ghidra.app.context.DataLocationListContext;
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
import ghidra.util.table.GhidraTable;

public class HashViewerContext extends ActionContext implements DataLocationListContext {
public class HashViewerContext extends #if GHIDRA_10_4 == "true" DefaultActionContext #else ActionContext #endif implements DataLocationListContext {

private HashViewerProvider hashViewerProvider;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/kaiju/tools/fnhashclassic/FnUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public FnUtils(Function fn, Program currentProgram, TaskMonitor monitor) throws


fep_cu = cuIter.next();
if (!fep_cu.contains(fep)) {
if (fep_cu != null && !fep_cu.contains(fep)) {
//debug("Function entry point not in first CodeUnit!");
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/kaiju/tools/fnxrefs/FnXrefViewerContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
import java.util.List;
import java.util.function.Predicate;

#if GHIDRA_10_4 == "true"
import docking.DefaultActionContext;
#endif
import docking.ActionContext;
import ghidra.app.context.DataLocationListContext;
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
import ghidra.util.table.GhidraTable;

public class FnXrefViewerContext extends ActionContext implements DataLocationListContext {
public class FnXrefViewerContext extends #if GHIDRA_10_4 == "true" DefaultActionContext #else ActionContext #endif implements DataLocationListContext {

private FnXrefViewerProvider xrefViewerProvider;

Expand Down
Loading

0 comments on commit 6feaa30

Please sign in to comment.