diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index a04abc57..4ec0e569 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -2,8 +2,7 @@ package the.bytecode.club.bytecodeviewer; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import javax.swing.*; import com.google.gson.Gson; @@ -31,6 +30,7 @@ import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; import the.bytecode.club.bytecodeviewer.resources.importing.ImportResource; import the.bytecode.club.bytecodeviewer.util.*; +import static javax.swing.JOptionPane.QUESTION_MESSAGE; import static the.bytecode.club.bytecodeviewer.Constants.*; /*************************************************************************** @@ -137,7 +137,7 @@ public class BytecodeViewer public static MainViewerGUI viewer; //All of the opened resources (Files/Classes/Etc) - public static List resourceContainers = new ArrayList<>(); + public static LinkedHashMap resourceContainers = new LinkedHashMap<>(); //All of the created processes (Decompilers/etc) public static List createdProcesses = new ArrayList<>(); @@ -294,7 +294,7 @@ public class BytecodeViewer */ public static void addResourceContainer(ResourceContainer container) { - resourceContainers.add(container); + resourceContainers.put(container.name, container); SwingUtilities.invokeLater(() -> { try { @@ -359,7 +359,7 @@ public class BytecodeViewer @Deprecated public static ClassNode blindlySearchForClassNode(String name) { - for (ResourceContainer container : resourceContainers) + for (ResourceContainer container : resourceContainers.values()) { ClassNode node = container.getClassNode(name); @@ -375,7 +375,7 @@ public class BytecodeViewer */ public static ResourceContainer getFileContainer(String name) { - for (ResourceContainer container : resourceContainers) + for (ResourceContainer container : resourceContainers.values()) if (container.name.equals(name)) return container; @@ -385,9 +385,9 @@ public class BytecodeViewer /** * Returns all of the loaded resource containers */ - public static List getResourceContainers() + public static Collection getResourceContainers() { - return resourceContainers; + return resourceContainers.values(); } /** @@ -401,7 +401,7 @@ public class BytecodeViewer @Deprecated public static byte[] getFileContents(String name) { - for (ResourceContainer container : resourceContainers) + for (ResourceContainer container : resourceContainers.values()) if (container.resourceFiles.containsKey(name)) return container.resourceFiles.get(name); @@ -431,7 +431,7 @@ public class BytecodeViewer { ArrayList a = new ArrayList<>(); - for (ResourceContainer container : resourceContainers) + for (ResourceContainer container : resourceContainers.values()) for (ClassNode c : container.resourceClasses.values()) if (!a.contains(c)) a.add(c); @@ -571,14 +571,21 @@ public class BytecodeViewer /** * Send a message to alert the user - * - * @param message the message you need to send */ public static String showInput(String message) { return ExtendedJOptionPane.showInputDialog(viewer, message); } + /** + * Send a message to alert the user + */ + public static String showInput(String message, String title, String initialMessage) + { + return (String) ExtendedJOptionPane.showInputDialog(viewer, message, title, + QUESTION_MESSAGE, null, null, initialMessage); + } + /** * Alerts the user the program is running something in the background */ @@ -644,7 +651,7 @@ public class BytecodeViewer */ public static void updateAllClassNodeByteArrays() { - resourceContainers.forEach(ResourceContainer::updateClassNodeBytes); + resourceContainers.values().forEach(ResourceContainer::updateClassNodeBytes); } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 374f4ed6..15a0cb21 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -863,7 +863,7 @@ public class MainViewerGUI extends JFrame LazyNameUtil.reset(); ArrayList reopen = new ArrayList<>(); - for (ResourceContainer container : BytecodeViewer.resourceContainers) + for (ResourceContainer container : BytecodeViewer.resourceContainers.values()) { File newFile = new File(container.file.getParent() + fs + container.name); if (!container.file.getAbsolutePath().equals(newFile.getAbsolutePath()) && diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java index 07ea9460..4cb46c73 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java @@ -302,7 +302,7 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File String cheapHax = path.getPathComponent(1).toString(); ResourceContainer container = null; - for (ResourceContainer c : BytecodeViewer.resourceContainers) + for (ResourceContainer c : BytecodeViewer.resourceContainers.values()) { if (c.name.equals(cheapHax)) container = c; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/PerformSearch.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/PerformSearch.java index 3a117071..0ce6766a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/PerformSearch.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/PerformSearch.java @@ -58,7 +58,7 @@ class PerformSearch extends BackgroundSearchThread BytecodeViewer.showMessage("You have an error in your regex syntax."); } - for (ResourceContainer container : BytecodeViewer.resourceContainers) + for (ResourceContainer container : BytecodeViewer.resourceContainers.values()) for (ClassNode c : container.resourceClasses.values()) searchBoxPane.searchType.details.search(container, c, srn, searchBoxPane.exact.isSelected()); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java index f70a4eb8..47fb8647 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java @@ -11,6 +11,7 @@ import the.bytecode.club.bytecodeviewer.util.*; import javax.swing.*; import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import static the.bytecode.club.bytecodeviewer.Constants.fs; @@ -47,7 +48,7 @@ public class APKExport implements Exporter if (BytecodeViewer.promptIfNoLoadedResources()) return; - List containers = BytecodeViewer.getResourceContainers(); + Collection containers = BytecodeViewer.getResourceContainers(); List validContainers = new ArrayList<>(); List validContainersNames = new ArrayList<>(); ResourceContainer container; @@ -72,7 +73,8 @@ public class APKExport implements Exporter "Which file would you like to export as an APK?", validContainersNames.toArray(new String[0])); - container = containers.get(dialog.promptChoice()); + //TODO may be off by one + container = (ResourceContainer) containers.stream().skip(dialog.promptChoice()); } } else { BytecodeViewer.showMessage("You can only export as APK from a valid APK file. Make sure Settings>Decode Resources is ticked on." + diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java index 0ec2df33..633fae68 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -262,7 +262,7 @@ public class JarUtils out.write((manifest.trim() + "\r\n\r\n").getBytes()); out.closeEntry(); - for (ResourceContainer container : BytecodeViewer.resourceContainers) { + for (ResourceContainer container : BytecodeViewer.resourceContainers.values()) { for (Entry entry : container.resourceFiles.entrySet()) { String filename = entry.getKey(); if (!filename.startsWith("META-INF")) { @@ -363,7 +363,7 @@ public class JarUtils } } - for (ResourceContainer container : BytecodeViewer.resourceContainers) { + for (ResourceContainer container : BytecodeViewer.resourceContainers.values()) { for (Entry entry : container.resourceFiles.entrySet()) { String filename = entry.getKey(); if (!filename.startsWith("META-INF")) {