Slightly Better Container API
Allows for quick look ups based on container name
This commit is contained in:
parent
a4f01151d5
commit
f0580df2d6
6 changed files with 29 additions and 20 deletions
|
@ -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<ResourceContainer> resourceContainers = new ArrayList<>();
|
||||
public static LinkedHashMap<String,ResourceContainer> resourceContainers = new LinkedHashMap<>();
|
||||
|
||||
//All of the created processes (Decompilers/etc)
|
||||
public static List<Process> 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<ResourceContainer> getResourceContainers()
|
||||
public static Collection<ResourceContainer> 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<ClassNode> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -863,7 +863,7 @@ public class MainViewerGUI extends JFrame
|
|||
LazyNameUtil.reset();
|
||||
ArrayList<File> 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()) &&
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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<ResourceContainer> containers = BytecodeViewer.getResourceContainers();
|
||||
Collection<ResourceContainer> containers = BytecodeViewer.getResourceContainers();
|
||||
List<ResourceContainer> validContainers = new ArrayList<>();
|
||||
List<String> 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." +
|
||||
|
|
|
@ -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<String, byte[]> 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<String, byte[]> entry : container.resourceFiles.entrySet()) {
|
||||
String filename = entry.getKey();
|
||||
if (!filename.startsWith("META-INF")) {
|
||||
|
|
Loading…
Reference in a new issue