Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1066: Making Framework Utility Java 1.8 compatible again

Ryan Kurtzc270a5d31e8f
diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraJarApplicationLayout.java b/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraJarApplicationLayout.java
index 16fb854b87..21b6922301 100644
--- a/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraJarApplicationLayout.java
+++ b/Ghidra/Framework/Utility/src/main/java/ghidra/GhidraJarApplicationLayout.java
@@ -15,11 +15,9 @@
*/
package ghidra;
-import java.io.FileNotFoundException;
-import java.io.IOException;
+import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
import java.util.*;
import generic.jar.ResourceFile;
@@ -93,6 +91,17 @@ public class GhidraJarApplicationLayout extends GhidraApplicationLayout {
* @return A {@link ResourceFile} from the given {@link URL}
*/
private ResourceFile fromUrl(URL url) {
- return new ResourceFile(URLDecoder.decode(url.toExternalForm(), StandardCharsets.UTF_8));
+ String urlString = url.toExternalForm();
+ try {
+ // Decode the URL to replace things like %20 with real spaces.
+ // Note: can't use URLDecoder.decode(String, Charset) because Utility must be
+ // Java 1.8 compatible.
+ urlString = URLDecoder.decode(urlString, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e) {
+ // Shouldn't happen, but failed to find UTF-8 encoding.
+ // Proceed without decoding, and hope for the best.
+ }
+ return new ResourceFile(urlString);
}
}