mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GT-2623 fixing GhidraJarMode
This commit is contained in:
@@ -67,14 +67,10 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
public GhidraJarBuilder(List<File> rootDirs) throws IOException {
|
public GhidraJarBuilder(List<File> rootDirs) throws IOException {
|
||||||
for (File file : rootDirs) {
|
for (File file : rootDirs) {
|
||||||
File rgd = file.getCanonicalFile();
|
File rgd = file.getCanonicalFile();
|
||||||
if (!isValidRootDir(rgd)) {
|
|
||||||
throw new IOException("Invalid Ghidra directory: " + rgd);
|
|
||||||
}
|
|
||||||
rootGhidraDirs.add(rgd);
|
rootGhidraDirs.add(rgd);
|
||||||
}
|
}
|
||||||
allModules = findAllModules();
|
allModules = findAllModules();
|
||||||
Collections.sort(allModules);
|
Collections.sort(allModules);
|
||||||
|
|
||||||
for (ApplicationModule module : allModules) {
|
for (ApplicationModule module : allModules) {
|
||||||
if (includeByDefault(module)) {
|
if (includeByDefault(module)) {
|
||||||
includedModules.add(module);
|
includedModules.add(module);
|
||||||
@@ -197,6 +193,7 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
Jar jar = new Jar(outputFile, manifest, monitor);
|
Jar jar = new Jar(outputFile, manifest, monitor);
|
||||||
|
|
||||||
List<ApplicationModule> moduleList = new ArrayList<>(includedModules);
|
List<ApplicationModule> moduleList = new ArrayList<>(includedModules);
|
||||||
|
|
||||||
Collections.sort(moduleList);
|
Collections.sort(moduleList);
|
||||||
createClassLoader(moduleList);
|
createClassLoader(moduleList);
|
||||||
|
|
||||||
@@ -373,11 +370,12 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
processExternalLibs(jar, module);
|
processExternalLibs(jar, module);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// NOTE: This only works in a distribution where the 3rd party jars live in each
|
||||||
File binDir = new File(module.getModuleDir(), "bin");
|
// module's libs directory
|
||||||
|
File binDir = new File(module.getModuleDir(), "bin/main");
|
||||||
writeDirRecursively(jar, binDir.getAbsolutePath(), binDir, module);
|
writeDirRecursively(jar, binDir.getAbsolutePath(), binDir, module);
|
||||||
File resourceDir = new File(module.getModuleDir(), "resources");
|
File resourceDir = new File(module.getModuleDir(), "src/main/resources");
|
||||||
writeDirRecursively(jar, resourceDir.getParentFile().getAbsolutePath(), resourceDir, null);
|
writeDirRecursively(jar, resourceDir.getAbsolutePath(), resourceDir, null);
|
||||||
|
|
||||||
processLibDir(jar, module);
|
processLibDir(jar, module);
|
||||||
}
|
}
|
||||||
@@ -427,7 +425,7 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
// Log4j scatters .dat files around in modules that use the log4j
|
// Log4j scatters .dat files around in modules that use the log4j
|
||||||
// plugin construct. Each one contains the plugins that that module
|
// plugin construct. Each one contains the plugins that that module
|
||||||
// requires. The problem is that each of these has the exact same path:
|
// requires. The problem is that each of these has the exact same path:
|
||||||
//
|
//
|
||||||
// META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
|
// META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
|
||||||
//
|
//
|
||||||
// If we just blindly copy all of them to our new jar, we risk overwriting the
|
// If we just blindly copy all of them to our new jar, we risk overwriting the
|
||||||
@@ -437,9 +435,9 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
//
|
//
|
||||||
// NOTE: The above statement obviously means that we're dropping the information
|
// NOTE: The above statement obviously means that we're dropping the information
|
||||||
// contained in the 'other' .dat files. This could cause a problem at some
|
// contained in the 'other' .dat files. This could cause a problem at some
|
||||||
// point, even though it doesn't now. As such, we may want to try to merge
|
// point, even though it doesn't now. As such, we may want to try to merge
|
||||||
// all the .dat files together at some point.
|
// all the .dat files together at some point.
|
||||||
//
|
//
|
||||||
if (jarEntry.getName().contains("Log4j2Plugins.dat")) {
|
if (jarEntry.getName().contains("Log4j2Plugins.dat")) {
|
||||||
if (jarFile.getName().contains("log4j-core")) {
|
if (jarFile.getName().contains("log4j-core")) {
|
||||||
jar.addJarEntry(jarFile, jarEntry, module);
|
jar.addJarEntry(jarFile, jarEntry, module);
|
||||||
@@ -494,7 +492,7 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
}
|
}
|
||||||
writeDirRecursively(jar, moduleDir.getAbsolutePath(), new File(helpDir, "shared"), null);
|
writeDirRecursively(jar, moduleDir.getAbsolutePath(), new File(helpDir, "shared"), null);
|
||||||
writeDirRecursively(jar, moduleDir.getAbsolutePath(), new File(helpDir, "topics"), null);
|
writeDirRecursively(jar, moduleDir.getAbsolutePath(), new File(helpDir, "topics"), null);
|
||||||
File helpBinDir = new File(helpDir, "bin");
|
File helpBinDir = new File(helpDir, "bin/main");
|
||||||
jar.setPathPrefix("help/");
|
jar.setPathPrefix("help/");
|
||||||
writeDirRecursively(jar, helpBinDir.getAbsolutePath(), helpBinDir, null);
|
writeDirRecursively(jar, helpBinDir.getAbsolutePath(), helpBinDir, null);
|
||||||
jar.setPathPrefix(null);
|
jar.setPathPrefix(null);
|
||||||
@@ -549,10 +547,10 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
private void writeNonModuleFiles(Jar jar) throws IOException, CancelledException {
|
private void writeNonModuleFiles(Jar jar) throws IOException, CancelledException {
|
||||||
jar.setPathPrefix(ROOT);
|
jar.setPathPrefix(ROOT);
|
||||||
|
|
||||||
File rootGhidraDir = rootGhidraDirs.get(0);
|
File rootDir = findRootDir();
|
||||||
File rootDir = rootGhidraDir.getParentFile();
|
File applicatonProperties = getApplicationPropertyFile(rootDir);
|
||||||
File applicatonProperties = getApplicationPropertyFile(rootGhidraDir);
|
String jarPath =
|
||||||
String jarPath = getPathFromRoot(rootDir.getAbsolutePath(), applicatonProperties);
|
getPathFromRoot(rootDir.getParentFile().getAbsolutePath(), applicatonProperties);
|
||||||
jar.addFile(jarPath, applicatonProperties, null);
|
jar.addFile(jarPath, applicatonProperties, null);
|
||||||
|
|
||||||
File whatsNew = new File(rootDir, "docs/WhatsNew.html");
|
File whatsNew = new File(rootDir, "docs/WhatsNew.html");
|
||||||
@@ -568,6 +566,15 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File findRootDir() {
|
||||||
|
for (File root : rootGhidraDirs) {
|
||||||
|
if (getApplicationPropertyFile(root).exists()) {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new AssertException("Can't find application property file!");
|
||||||
|
}
|
||||||
|
|
||||||
private Manifest createManifest() {
|
private Manifest createManifest() {
|
||||||
Manifest manifest = new Manifest();
|
Manifest manifest = new Manifest();
|
||||||
Attributes mainAttributes = manifest.getMainAttributes();
|
Attributes mainAttributes = manifest.getMainAttributes();
|
||||||
@@ -650,7 +657,7 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
/**
|
/**
|
||||||
* Puts a directory in the jar for Ghidra Extensions. This may be empty (if
|
* Puts a directory in the jar for Ghidra Extensions. This may be empty (if
|
||||||
* no extensions are installed) but should exist nonetheless.
|
* no extensions are installed) but should exist nonetheless.
|
||||||
*
|
*
|
||||||
* @throws IOException if there's an error writing to the jar
|
* @throws IOException if there's an error writing to the jar
|
||||||
*/
|
*/
|
||||||
public void writeGhidraExtensionsDir() throws IOException {
|
public void writeGhidraExtensionsDir() throws IOException {
|
||||||
@@ -731,8 +738,15 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
*/
|
*/
|
||||||
public void addFile(String jarPath, File file, ApplicationModule module)
|
public void addFile(String jarPath, File file, ApplicationModule module)
|
||||||
throws IOException, CancelledException {
|
throws IOException, CancelledException {
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new AssertException(
|
||||||
|
"Attempted to write a file that does not exist to the jar! File = " +
|
||||||
|
file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
if (!file.isFile()) {
|
if (!file.isFile()) {
|
||||||
throw new AssertException("Attempted to write a directory to the jar file");
|
throw new AssertException(
|
||||||
|
"Attempted to write a directory to the jar! File = " + file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
jarPath = jarPath.replaceAll("\\\\", "/"); // handle windows separators
|
jarPath = jarPath.replaceAll("\\\\", "/"); // handle windows separators
|
||||||
@@ -1044,13 +1058,6 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
System.out.println("Extra Bin Dir = " + extraBinDir);
|
System.out.println("Extra Bin Dir = " + extraBinDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File ghidraDir : ghidraDirs) {
|
|
||||||
if (!isValidRootDir(ghidraDir)) {
|
|
||||||
System.err.println("Invalid Ghidra directory: " + ghidraDir);
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GhidraJarBuilder builder = new GhidraJarBuilder(ghidraDirs);
|
GhidraJarBuilder builder = new GhidraJarBuilder(ghidraDirs);
|
||||||
if (mainClassArg != null) {
|
if (mainClassArg != null) {
|
||||||
@@ -1090,10 +1097,6 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
|||||||
return new File(ghidraRootDir, "application.properties");
|
return new File(ghidraRootDir, "application.properties");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isValidRootDir(File ghidraRootDir) {
|
|
||||||
return getApplicationPropertyFile(ghidraRootDir).isFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setGradleMode() {
|
private void setGradleMode() {
|
||||||
inGradleMode = true;
|
inGradleMode = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ public class GClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static URL[] findUrls(List<File> moduleDirs) {
|
private static URL[] findUrls(List<File> moduleDirs) {
|
||||||
List<URL> urls = new ArrayList<URL>();
|
List<URL> urls = new ArrayList<>();
|
||||||
|
|
||||||
for (File moduleDir : moduleDirs) {
|
for (File moduleDir : moduleDirs) {
|
||||||
File binDir = new File(moduleDir, "bin/");
|
File binDir = new File(moduleDir, "bin/main");
|
||||||
if (binDir.exists()) {
|
if (binDir.exists()) {
|
||||||
addFileURL(urls, binDir);
|
addFileURL(urls, binDir);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user