GP-4294 - Fixed exception looking for extensions when running headlessly in fat jar mode

This commit is contained in:
dragonmacher 2024-02-06 17:01:02 -05:00
parent dffb5fd859
commit 359faba77a
3 changed files with 49 additions and 35 deletions

View file

@ -62,9 +62,12 @@ public class BuildGhidraJarScript extends GhidraScript {
builder.addExcludedFileExtension(".pdf");
File installDir = Application.getInstallationDirectory().getFile(true);
builder.buildJar(new File(installDir, "ghidra.jar"), null, monitor);
File file = new File(installDir, "ghidra.jar");
builder.buildJar(file, null, monitor);
// uncomment the following line to create a src zip for debugging.
// builder.buildSrcZip(new File(installDir, "GhidraSrc.zip"), monitor);
println("Finsished writing jar: " + file);
}
}

View file

@ -185,8 +185,10 @@ public class HeadlessAnalyzer {
layout = new GhidraApplicationLayout();
}
catch (IOException e) {
Msg.debug(HeadlessAnalyzer.class,
"Unable to load the standard Ghidra application layout. " + e.getMessage() +
". Attempting to load the Ghidra Jar application layout.");
layout = new GhidraJarApplicationLayout();
}
return layout;
}

View file

@ -23,7 +23,7 @@ import java.util.*;
import generic.jar.ResourceFile;
import ghidra.framework.ApplicationProperties;
import ghidra.framework.GModule;
import utility.application.ApplicationLayout;
import ghidra.util.Msg;
import utility.module.ModuleUtilities;
/**
@ -51,7 +51,11 @@ public class GhidraJarApplicationLayout extends GhidraApplicationLayout {
protected Collection<ResourceFile> findGhidraApplicationRootDirs() {
List<ResourceFile> dirs = new ArrayList<>();
String appPropPath = "/_Root/Ghidra/" + ApplicationProperties.PROPERTY_FILE;
URL appPropUrl = ApplicationLayout.class.getResource(appPropPath);
URL appPropUrl = getClass().getResource(appPropPath);
if (appPropUrl == null) {
throw new IllegalStateException(
"The Ghidra Jar must have an application.properties file at " + appPropPath);
}
ResourceFile rootDir = fromUrl(appPropUrl).getParentFile();
dirs.add(rootDir);
return dirs;
@ -79,7 +83,12 @@ public class GhidraJarApplicationLayout extends GhidraApplicationLayout {
@Override
protected List<ResourceFile> findExtensionInstallationDirectories() {
URL extensionInstallUrl = ApplicationLayout.class.getResource("/_Root/Ghidra/Extensions");
String path = "/_Root/Ghidra/Extensions";
URL extensionInstallUrl = getClass().getResource(path);
if (extensionInstallUrl == null) {
Msg.debug(this, "No Extensions dir found at " + path);
return List.of();
}
ResourceFile extensionInstallDir = fromUrl(extensionInstallUrl);
return Collections.singletonList(extensionInstallDir);
}