Skip to content

Commit

Permalink
Update for Java 17 and gradle 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-gwassermann authored Dec 15, 2022
1 parent 0b37f29 commit 0c54d33
Show file tree
Hide file tree
Showing 16 changed files with 791 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CERT Kaiju requires the following runtime dependencies:
- Java 11+ (we recommend [OpenJDK 11](https://openjdk.java.net/install/))
- [Z3](https://github.com/Z3Prover/z3) including Z3 Java bindings .jar

**NOTE**: We strongly recommend updating to Ghidra 10.1 or above
**NOTE**: We strongly recommend updating to Ghidra 10.1.2 or above
in order to address the log4j vulnerability that exists
in the library bundled with older versions of Ghidra.

Expand Down
32 changes: 21 additions & 11 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ jobs:
GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
AUTOCATS_DIR: $(Pipeline.Workspace)/autocats
GHIHORN_TEST_DIR: $(Pipeline.Workspace)/autocats/exe/ghihorn
GRADLE_VERSION: gradle-6.9.2
GRADLE_VERSION: gradle-7.5.1
GRADLE_URL: https://services.gradle.org/distributions/$(GRADLE_VERSION)-bin.zip
GRADLE_INSTALL_DIR: $(Pipeline.Workspace)/gradle
Z3_VERSION: z3-4.8.14
strategy:
matrix:
# Disabled because we can't even build ghidra master with gradle 6.9.2
# disabled until make needed changes for Ghidra 10.3
#ghidra-git:
# ghidraVersion: "master"
ghidra1022:
ghidraUrl: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.2.2_build/ghidra_10.2.2_PUBLIC_20221115.zip"
ghidraVersion: "10.2.2"
ghidra1021:
ghidraUrl: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.2.1_build/ghidra_10.2.1_PUBLIC_20221110.zip"
ghidraVersion: "10.2.1"
ghidra1020:
ghidraUrl: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.2_build/ghidra_10.2_PUBLIC_20221101.zip"
ghidraVersion: "10.2.0"
ghidra1015:
ghidraUrl: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.1.5_build/ghidra_10.1.5_PUBLIC_20220726.zip"
ghidraVersion: "10.1.5"
Expand All @@ -34,12 +43,6 @@ jobs:
ghidra1012:
ghidraUrl: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.1.2_build/ghidra_10.1.2_PUBLIC_20220125.zip"
ghidraVersion: "10.1.2"
ghidra1011:
ghidraUrl: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.1.1_build/ghidra_10.1.1_PUBLIC_20211221.zip"
ghidraVersion: "10.1.1"
ghidra101:
ghidraUrl: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.1_build/ghidra_10.1_PUBLIC_20211210.zip"
ghidraVersion: "10.1"
pool:
vmImage: 'Ubuntu-20.04'
steps:
Expand All @@ -61,7 +64,14 @@ jobs:
- script: |
echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
echo "##vso[task.prependpath]$(JAVA_HOME_11_X64)/bin:$(PATH)"
displayName: "Set java version"
displayName: "Set Java 11"
condition: or(eq(variables['ghidraVersion'], '10.1.5'), or(eq(variables['ghidraVersion'], '10.1.4'), or(eq(variables['ghidraVersion'], '10.1.3'), eq(variables['ghidraVersion'], '10.1.2'))))
- script: |
echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_17_X64)"
echo "##vso[task.prependpath]$(JAVA_HOME_17_X64)/bin:$(PATH)"
displayName: "Set Java 17"
condition: or(eq(variables['ghidraVersion'], 'master'), or(eq(variables['ghidraVersion'], '10.2.2'), or(eq(variables['ghidraVersion'], '10.2.1'), eq(variables['ghidraVersion'], '10.2.0'))))
- task: Cache@2
inputs:
Expand Down Expand Up @@ -94,7 +104,7 @@ jobs:
inputs:
key: '"$(GRADLE_URL)" | gradle'
path: $(GRADLE_INSTALL_DIR)
displayName: Cache Gradle 6.x
displayName: Cache Gradle 7.x

- bash: |
set -ex
Expand Down Expand Up @@ -141,7 +151,7 @@ jobs:
unzip -d $(GRADLE_INSTALL_DIR) gradle.zip
rm gradle.zip
workingDirectory: $(Pipeline.Workspace)
displayName: Download gradle 6.x binary from $(GRADLE_URL)
displayName: Download gradle 7.x binary from $(GRADLE_URL)
- bash: |
set -ex
Expand Down
29 changes: 25 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ plugins {
id 'kaiju.gradle.ghidrahtml'
}

// we target Java 11 LTS as recommended by Ghidra
sourceCompatibility = 1.11
targetCompatibility = 1.11


//----------------------START "DO NOT MODIFY" SECTION------------------------------
def ghidraInstallDir
Expand All @@ -76,6 +74,25 @@ else {
}
//----------------------END "DO NOT MODIFY" SECTION-------------------------------

def ghidraVersion;
def minor;
String[] str;
str = ghidraInstallDir.split('_');
for( String values : str )
if (values =~ '[0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,}') {
ghidraVersion = values;
String[] substr = values.split('\\.');
minor = substr[1] as int;
};
if (minor && minor < 2) {
// we target Java 11 LTS for old Ghidra
sourceCompatibility = 1.11
targetCompatibility = 1.11
} else {
// we target Java 17 LTS for Ghidra 10.2+
sourceCompatibility = 1.17
targetCompatibility = 1.17
}

// allow installation using:
// > gradle -PGHIDRA_INSTALL_DIR=/path/to/ghidra install
Expand Down Expand Up @@ -141,7 +158,8 @@ buildExtension {

task printGhidraDir {
println 'Using Ghidra install directory ' + ghidraInstallDir
println 'Using test directory ' + project.property('KAIJU_AUTOCATS_DIR')
println 'Using Java ' + targetCompatibility + ' for Ghidra ' + ghidraVersion
println 'Using AUTOCATS test directory ' + project.property('KAIJU_AUTOCATS_DIR')
}

task copyToLib(type: Copy) {
Expand Down Expand Up @@ -287,6 +305,9 @@ task install() {

test {

// needed prior to Ghidra 10.3 to address sun.awt not exported in JDK 17+
jvmArgs = ['--add-exports=java.desktop/sun.awt=ALL-UNNAMED']

useJUnitPlatform()

maxHeapSize = '2G'
Expand Down
118 changes: 84 additions & 34 deletions src/main/java/kaiju/AlignmentAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,100 @@
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.
*/
public class AlignmentAction extends DockingAction {

private DataPlugin plugin;
private static final KeyStroke KEY_BINDING = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0);
private final static String ACTION_NAME = "Create Alignment";
private static final String[] CREATE_ALIGNMENT_POPUP_MENU =
new String[] { "Data", "Create Alignment..." };
private DataPlugin plugin;
private static final KeyStroke KEY_BINDING = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0);
private final static String ACTION_NAME = "Create Alignment";
private static final String[] CREATE_ALIGNMENT_POPUP_MENU =
new String[] { "Data", "Create Alignment..." };

public AlignmentAction(DataPlugin plugin) {
super(ACTION_NAME, plugin.getName(), KeyBindingType.SHARED);
this.plugin = plugin;
public AlignmentAction(DataPlugin plugin) {
super(ACTION_NAME, plugin.getName(), KeyBindingType.SHARED);
this.plugin = plugin;

setPopupMenuData(new MenuData(CREATE_ALIGNMENT_POPUP_MENU, "BasicData"));
setEnabled(true);
setPopupMenuData(new MenuData(CREATE_ALIGNMENT_POPUP_MENU, "BasicData"));
setEnabled(true);

initKeyStroke(KEY_BINDING);
}
initKeyStroke(KEY_BINDING);
}

private void initKeyStroke(KeyStroke keyStroke) {
if (keyStroke == null) {
return;
}
private void initKeyStroke(KeyStroke keyStroke) {
if (keyStroke == null) {
return;
}

setKeyBindingData(new KeyBindingData(keyStroke));
}
setKeyBindingData(new KeyBindingData(keyStroke));
}

@Override
public void actionPerformed(ActionContext context) {
ListingActionContext listingContext = (ListingActionContext) context.getContextObject();
DataType dataType = new AlignmentDataType();
if (dataType != null) {
plugin.createData(dataType, listingContext, false);
}
}
@Override
public void actionPerformed(ActionContext context) {
ListingActionContext listingContext = (ListingActionContext) context.getContextObject();
DataType dataType = new AlignmentDataType();
if (dataType != null) {
Class<?> c = null;
try {
c = Class.forName("ghidra.app.plugin.core.data.DataPlugin");
} catch (ClassNotFoundException e) {
//TODO
}
Class[] cArg = new Class[3];
cArg[0] = DataType.class;
cArg[1] = ListingActionContext.class;
cArg[2] = boolean.class;
if (GhidraDI.isPriorToGhidraMinorVersion("10.2")) {
try
{
c.getDeclaredMethod("createData", cArg);
try {
c.getDeclaredMethod("createData").invoke(plugin, dataType, listingContext, false);
} catch (Exception e) {
//Msg.warn(this, "Error invoking function.");
}
} catch(NoSuchMethodException e) {
//Msg.warn(this, "Unable to locate createData with appropriate parameters. The GUI may be irresponsive.");
}
} else {
//plugin.createData(dataType, listingContext, false);
// for Ghidra 10.2+
try
{
c.getDeclaredMethod("createData");
try {
c.getDeclaredMethod("createData").invoke(plugin, dataType, listingContext, false, false);
} catch (Exception e) {
//Msg.warn(this, "Error invoking function.");
}
} catch(NoSuchMethodException e) {
//Msg.warn(this, "Unable to locate createData with appropriate parameters. The GUI may be irresponsive.");
}
}
}
}

@Override
public boolean isEnabledForContext(ActionContext context) {
Object contextObject = context.getContextObject();
if (contextObject instanceof ListingActionContext) {
return plugin.isCreateDataAllowed(((ListingActionContext) contextObject));
}
return false;
}
@Override
public boolean isEnabledForContext(ActionContext context) {
Object contextObject = context.getContextObject();
if (contextObject instanceof ListingActionContext) {
return plugin.isCreateDataAllowed(((ListingActionContext) contextObject));
}
return false;
}
}
Loading

0 comments on commit 0c54d33

Please sign in to comment.