mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GT-2623 fixing GhidraJarMode
This commit is contained in:
parent
64deecced9
commit
e8f3694eb9
2 changed files with 34 additions and 31 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue