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