fix issues resulting from search for script directory

This commit is contained in:
Jason P. Leasure
2020-08-25 10:56:33 -04:00
parent 2fb156738a
commit 25fda75bfa
2 changed files with 19 additions and 6 deletions

View File

@@ -76,7 +76,7 @@ public class GhidraScriptUtil {
bundleHost.startFramework();
}
catch (OSGiException | IOException e) {
Msg.error(GhidraScript.class, "Failed to initialize BundleHost", e);
Msg.error(GhidraScriptUtil.class, "Failed to initialize BundleHost", e);
}
}
@@ -128,12 +128,20 @@ public class GhidraScriptUtil {
* @return the source directory if found, or null if not
*/
public static ResourceFile findSourceDirectoryContaining(ResourceFile sourceFile) {
String sourcePath = sourceFile.getAbsolutePath();
for (ResourceFile sourceDir : getScriptSourceDirectories()) {
if (sourcePath.startsWith(sourceDir.getAbsolutePath() + File.separatorChar)) {
return sourceDir;
String sourcePath;
try {
sourcePath = sourceFile.getCanonicalPath();
for (ResourceFile sourceDir : getScriptSourceDirectories()) {
if (sourcePath.startsWith(sourceDir.getCanonicalPath() + File.separatorChar)) {
return sourceDir;
}
}
}
catch (IOException e) {
Msg.error(GhidraScriptUtil.class,
"Failed to find script in any script directory: " + sourceFile.toString(),
e);
}
return null;
}
@@ -219,7 +227,8 @@ public class GhidraScriptUtil {
return false;
}
catch (IOException e) {
Msg.error(null, "Unexpected Exception: " + e.getMessage(), e);
Msg.error(GhidraScriptUtil.class,
"Failed to find file in system directories: " + file.toString(), e);
return true;
}
}

View File

@@ -113,6 +113,10 @@ public class JavaScriptProvider extends GhidraScriptProvider {
*/
public Class<?> loadClass(ResourceFile sourceFile, PrintWriter writer) throws Exception {
GhidraSourceBundle bundle = getBundleForSource(sourceFile);
if (bundle == null) {
throw new ClassNotFoundException(
"Failed to find source bundle containing script: " + sourceFile.toString());
}
bundleHost.activateAll(Collections.singletonList(bundle), TaskMonitor.DUMMY, writer);
String classname = bundle.classNameForScript(sourceFile);