Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1211: More fixes

Ryan Kurtz04021847b2d1
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java
index c4f8383f27..2b82f0f754 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Application.java
@@ -459,7 +459,7 @@ public class Application {
GModule module = app.layout.getModules().get(moduleName);
if (module == null) {
- return null;
+ throw new OSFileNotFoundException(moduleName, exactFilename);
}
File file = getModuleFile(module,
@@ -481,7 +481,7 @@ public class Application {
}
if (file == null) {
- throw new OSFileNotFoundException(exactFilename);
+ throw new OSFileNotFoundException(moduleName, exactFilename);
}
return file;
@@ -906,37 +906,37 @@ public class Application {
/**
* Returns the OS specific file within the given module with the given name.
+ *
* @param moduleName the name of the module
* @param exactFilename the name of the OS file within the module.
+ * @return the OS specific file.
* @throws OSFileNotFoundException if the file does not exist.
*/
public static File getOSFile(String moduleName, String exactFilename)
throws OSFileNotFoundException {
- File osFile = app.getModuleOSFile(exactFilename, moduleName);
- if (osFile != null) {
- return osFile;
- }
- throw new OSFileNotFoundException(moduleName, exactFilename);
+ return app.getModuleOSFile(exactFilename, moduleName);
}
/**
- * Returns the OS specific file in the calling class's module.
+ * Returns the specified OS specific file. It is first searched for in the calling class's
+ * module. If it is not found there, it is searched for in all modules.
+ *
* @param exactFilename the name of the OS specific file.
+ * @return the OS specific file.
* @throws OSFileNotFoundException if the file does not exist.
*/
public static File getOSFile(String exactFilename) throws OSFileNotFoundException {
ResourceFile myModuleRootDirectory = getMyModuleRootDirectory();
- if (myModuleRootDirectory == null) {
- // not in a module; may be in a script?
- return app.getOSFileInAnyModule(exactFilename);
- }
-
- File moduleOSFile = app.getModuleOSFile(exactFilename, myModuleRootDirectory.getName());
- if (moduleOSFile != null) {
- return moduleOSFile;
+ if (myModuleRootDirectory != null) {
+ try {
+ return app.getModuleOSFile(exactFilename, myModuleRootDirectory.getName());
+ }
+ catch (OSFileNotFoundException e) {
+ // not found in my module...fall through
+ }
}
-
- // not in my module; check all modules
+
+ // We are either not in a module (perhaps script?) or it was not found in my module
return app.getOSFileInAnyModule(exactFilename);
}
}