From 21fe12b4a705889d0e00f394af59a7069277476d Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 11 Jul 2021 05:33:18 -0700 Subject: [PATCH] Lots Fixes, API Changes, Cleanup, etc. --- .../club/bootloader/InitialBootScreen.java | 6 +- .../club/bytecodeviewer/BytecodeViewer.java | 56 +--- .../club/bytecodeviewer/Configuration.java | 2 +- .../club/bytecodeviewer/Constants.java | 3 + .../bytecodeviewer/SettingsSerializer.java | 4 +- .../club/bytecodeviewer/api/ExceptionUI.java | 2 +- .../compilers/impl/JavaCompiler.java | 5 +- .../compilers/impl/KrakatauAssembler.java | 13 +- .../impl/FernFlowerDecompiler.java | 25 +- .../decompilers/impl/KrakatauDecompiler.java | 42 +-- .../impl/KrakatauDisassembler.java | 23 +- .../bytecodeviewer/gui/MainViewerGUI.java | 105 ++----- .../gui/components/AboutWindow.java | 6 +- .../gui/components/HTMLPane.java | 2 +- .../gui/components/JFrameConsole.java | 2 +- .../components/JFrameConsolePrintStream.java | 6 +- .../gui/components/RunOptions.java | 2 +- .../gui/components/SearchableJTextArea.java | 3 +- .../components/SearchableRSyntaxTextArea.java | 3 +- .../gui/components/WaitBusyIcon.java | 2 +- .../gui/plugins/GraphicalReflectionKit.java | 2 +- .../plugins/MaliciousCodeScannerOptions.java | 2 +- .../gui/plugins/ReplaceStringsOptions.java | 2 +- .../gui/resourcelist/ImageRenderer.java | 2 +- .../gui/resourcelist/ResourceListPane.java | 6 +- .../ResourceListRightClickRemove.java | 2 +- .../gui/resourcesearch/PerformSearch.java | 4 +- .../bytecodeviewer/plugin/PluginTemplate.java | 3 +- .../bytecodeviewer/plugin/PluginWriter.java | 3 +- .../preinstalled/AllatoriStringDecrypter.java | 2 +- .../preinstalled/CodeSequenceDiagram.java | 2 +- .../ViewAPKAndroidPermissions.java | 11 +- .../plugin/preinstalled/ViewManifest.java | 2 +- .../resources/ExternalResources.java | 281 ++++++++++++++++++ .../{ => resources}/Resources.java | 17 +- .../resources/exporting/impl/APKExport.java | 2 +- .../importing/impl/APKResourceImporter.java | 13 +- .../importing/impl/ClassResourceImporter.java | 2 +- .../importing/impl/DEXResourceImporter.java | 5 +- .../impl/DirectoryResourceImporter.java | 2 +- .../importing/impl/FileResourceImporter.java | 2 +- .../importing/impl/XAPKResourceImporter.java | 2 +- .../importing/impl/ZipResourceImporter.java | 2 +- .../bytecodeviewer/translation/Language.java | 2 +- .../bytecodeviewer/util/BCVFileUtils.java | 54 ---- .../bytecodeviewer/util/BCVResourceUtils.java | 53 ---- .../club/bytecodeviewer/util/Enjarify.java | 3 +- .../bytecodeviewer/util/JTextAreaUtils.java | 4 +- .../club/bytecodeviewer/util/JarUtils.java | 8 +- .../club/bytecodeviewer/util/SecurityMan.java | 1 + 50 files changed, 436 insertions(+), 372 deletions(-) create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/resources/ExternalResources.java rename src/main/java/the/bytecode/club/bytecodeviewer/{ => resources}/Resources.java (97%) delete mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/util/BCVFileUtils.java delete mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/util/BCVResourceUtils.java diff --git a/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java b/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java index 0a5958b0..d8958e1f 100644 --- a/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java +++ b/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java @@ -8,14 +8,12 @@ import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; -import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JProgressBar; import javax.swing.JScrollPane; -import javax.swing.text.html.HTMLEditorKit; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; + import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.gui.components.HTMLPane; import static the.bytecode.club.bytecodeviewer.Configuration.language; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 5881674e..f423e749 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -89,7 +89,9 @@ import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; * + Make zipfile not include the decode shit * + Add decompile as zip for krakatau-bytecode, jd-gui and smali for CLI * + Add decompile all as zip for CLI - * + Console on the UI + * + Console on the Main Viewer UI + * + Plugin Console/System/ETC needs ctrl + mouse wheel + * + Font settings * * TODO IDEAS: * + App Bundle Support @@ -116,7 +118,7 @@ public class BytecodeViewer public static MainViewerGUI viewer; //All of the opened resources (Files/Classes/Etc) - public static List files = new ArrayList<>(); + public static List resourceContainers = new ArrayList<>(); //All of the created processes (Decompilers/etc) public static List createdProcesses = new ArrayList<>(); @@ -264,47 +266,13 @@ public class BytecodeViewer for (String s : launchArgs) openFiles(new File[]{new File(s)}, true); } - - /** - * Returns the java command it can use to launch the decompilers - * - * @return - */ - public static synchronized String getJavaCommand() - { - sm.pauseBlocking(); - try - { - ProcessBuilder pb = new ProcessBuilder("java", "-version"); - pb.start(); - return "java"; //java is set - } - catch (Exception e) //ignore - { - sm.resumeBlocking(); - boolean empty = Configuration.java.isEmpty(); - while (empty) - { - showMessage("You need to set your Java path, this requires the JRE to be downloaded." + - nl + "(C:/Program Files/Java/JDK_xx/bin/java.exe)"); - viewer.selectJava(); - empty = Configuration.java.isEmpty(); - } - } - finally - { - sm.resumeBlocking(); - } - - return Configuration.java; - } /** * Returns true if there is at least one file resource loaded */ public static boolean hasResources() { - return !files.isEmpty(); + return !resourceContainers.isEmpty(); } /** @@ -353,7 +321,7 @@ public class BytecodeViewer @Deprecated public static ClassNode blindlySearchForClassNode(String name) { - for (ResourceContainer container : files) + for (ResourceContainer container : resourceContainers) { ClassNode node = container.getClassNode(name); if(node != null) @@ -368,7 +336,7 @@ public class BytecodeViewer */ public static ResourceContainer getFileContainer(String name) { - for (ResourceContainer container : files) + for (ResourceContainer container : resourceContainers) if (container.name.equals(name)) return container; @@ -378,8 +346,8 @@ public class BytecodeViewer /** * Returns all of the loaded File Containers */ - public static List getFiles() { - return files; + public static List getResourceContainers() { + return resourceContainers; } /** @@ -390,7 +358,7 @@ public class BytecodeViewer */ public static byte[] getFileContents(String name) { - for (ResourceContainer container : files) + for (ResourceContainer container : resourceContainers) if (container.resourceFiles.containsKey(name)) return container.resourceFiles.get(name); @@ -414,7 +382,7 @@ public class BytecodeViewer { ArrayList a = new ArrayList<>(); - for (ResourceContainer container : files) + for (ResourceContainer container : resourceContainers) for (ClassNode c : container.resourceClasses.values()) if (!a.contains(c)) a.add(c); @@ -631,7 +599,7 @@ public class BytecodeViewer */ public static void resetWorkspace() { - BytecodeViewer.files.clear(); + BytecodeViewer.resourceContainers.clear(); LazyNameUtil.reset(); BytecodeViewer.viewer.resourcePane.resetWorkspace(); BytecodeViewer.viewer.workPane.resetWorkspace(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java index df6faeef..84641403 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java @@ -14,7 +14,7 @@ import java.io.File; */ public class Configuration { - public static String python = ""; + public static String python2 = ""; public static String python3 = ""; public static String rt = ""; public static String library = ""; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java index dff7ba67..a981a96a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java @@ -17,11 +17,14 @@ public class Constants public static String krakatauVersion = "12"; public static String enjarifyVersion = "4"; public static final boolean BLOCK_TAB_MENU = true; + public static final boolean LAUNCH_DECOMPILERS_IN_NEW_PROCESS = false; //TODO public static final boolean FAT_JAR = true; //could be automatic by checking if it's loaded a class named whatever for a library public static final boolean OFFLINE_MODE = true; //disables the automatic updater public static final String fs = System.getProperty("file.separator"); public static final String nl = System.getProperty("line.separator"); + + //TODO check if $HOME/.local/share exists, if so reference from there instead - #250 public static final File BCVDir = new File(System.getProperty("user.home") + fs + ".Bytecode-Viewer"); public static final File RT_JAR = new File(System.getProperty("java.home") + fs + "lib" + fs + "rt.jar"); public static final File RT_JAR_DUMPED = new File(getBCVDirectory() + fs + "rt.jar"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java index da01c7a6..05287657 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java @@ -139,7 +139,7 @@ public class SettingsSerializer save("deprecated"); save("deprecated"); save(Configuration.lastDirectory); - save(Configuration.python); + save(Configuration.python2); save(Configuration.rt); save("deprecated"); save("deprecated"); @@ -301,7 +301,7 @@ public class SettingsSerializer //86 is deprecated //87 is deprecated Configuration.lastDirectory = asString(88); - Configuration.python = asString(89); + Configuration.python2 = asString(89); Configuration.rt = asString(90); BytecodeViewer.viewer.decodeAPKResources.setSelected(asBoolean(106)); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java index e4071f3a..2cb33214 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java @@ -10,7 +10,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import static the.bytecode.club.bytecodeviewer.Constants.*; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java index 0cb34702..86f0d176 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java @@ -9,6 +9,7 @@ import me.konloch.kontainer.io.DiskWriter; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.compilers.InternalCompiler; +import the.bytecode.club.bytecodeviewer.resources.ExternalResources; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -54,8 +55,8 @@ public class JavaCompiler extends InternalCompiler new File(fileStart2).mkdirs(); if (Configuration.javac.isEmpty() || !new File(Configuration.javac).exists()) { - BytecodeViewer.showMessage("You need to set your Javac path, this requires the JDK to be downloaded." + nl + "(C:/programfiles/Java/JDK_xx/bin/javac.exe)"); - BytecodeViewer.viewer.selectJavac(); + BytecodeViewer.showMessage("You need to set your Javac path, this requires the JDK to be downloaded." + nl + "(C:/Program Files/Java/JDK_xx/bin/javac.exe)"); + ExternalResources.getSingleton().selectJavac(); } if (Configuration.javac.isEmpty() || !new File(Configuration.javac).exists()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java index 927eb140..84f4bba1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java @@ -12,7 +12,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.compilers.InternalCompiler; -import the.bytecode.club.bytecodeviewer.util.BCVFileUtils; +import the.bytecode.club.bytecodeviewer.resources.ExternalResources; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -46,12 +46,12 @@ public class KrakatauAssembler extends InternalCompiler @Override public byte[] compile(String contents, String name) { - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); - BytecodeViewer.viewer.selectPythonC(); + ExternalResources.getSingleton().selectPython2(); } - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return null; } @@ -76,7 +76,7 @@ public class KrakatauAssembler extends InternalCompiler try { ProcessBuilder pb = new ProcessBuilder( - Configuration.python, + Configuration.python2, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "assemble.py", "-out", @@ -112,7 +112,8 @@ public class KrakatauAssembler extends InternalCompiler log.append(nl).append(nl).append("Exit Value is ").append(exitValue); System.err.println(log); - byte[] b = FileUtils.readFileToByteArray(Objects.requireNonNull(BCVFileUtils.findFile(tempDirectory, ".class"))); + byte[] b = FileUtils.readFileToByteArray(Objects.requireNonNull( + ExternalResources.getSingleton().findFile(tempDirectory, ".class"))); tempDirectory.delete(); tempJar.delete(); return b; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java index 85b15ede..8d124574 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java @@ -9,7 +9,8 @@ import me.konloch.kontainer.io.DiskReader; import org.apache.commons.lang3.ArrayUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.ExternalResources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.decompilers.InternalDecompiler; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; @@ -47,7 +48,8 @@ public class FernFlowerDecompiler extends InternalDecompiler { @Override - public void decompileToZip(String sourceJar, String zipName) { + public void decompileToZip(String sourceJar, String zipName) + { File tempZip = new File(sourceJar); File f = new File(tempDirectory + fs + "temp" + fs); @@ -55,9 +57,7 @@ public class FernFlowerDecompiler extends InternalDecompiler try { org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempZip.getAbsolutePath(), tempDirectory + "./temp/")); - } catch (StackOverflowError | Exception ignored) { - - } + } catch (StackOverflowError | Exception ignored) { } File tempZip2 = new File(tempDirectory + fs + "temp" + fs + tempZip.getName()); if (tempZip2.exists()) @@ -86,10 +86,12 @@ public class FernFlowerDecompiler extends InternalDecompiler } - if (!FAT_JAR) { - try { + if (LAUNCH_DECOMPILERS_IN_NEW_PROCESS) + { + try + { ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll( - new String[]{BytecodeViewer.getJavaCommand(), "-jar", Resources.findLibrary("fernflower")}, + new String[]{ExternalResources.getSingleton().getJavaCommand(true), "-jar", ExternalResources.getSingleton().findLibrary("fernflower")}, generateMainMethod(tempClass.getAbsolutePath(), new File(tempDirectory).getAbsolutePath()) )); @@ -102,9 +104,12 @@ public class FernFlowerDecompiler extends InternalDecompiler } finally { BytecodeViewer.sm.resumeBlocking(); } - } else { + } + else + { try { - org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempClass.getAbsolutePath(), new File(tempDirectory).getAbsolutePath())); + org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main( + generateMainMethod(tempClass.getAbsolutePath(), new File(tempDirectory).getAbsolutePath())); } catch (Throwable e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java index d0b2db54..9c291717 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java @@ -10,11 +10,12 @@ import java.util.Arrays; import java.util.stream.Collectors; import me.konloch.kontainer.io.DiskReader; import org.objectweb.asm.tree.ClassNode; +import the.bytecode.club.bootloader.resource.ExternalResource; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.decompilers.InternalDecompiler; -import the.bytecode.club.bytecodeviewer.util.BCVResourceUtils; +import the.bytecode.club.bytecodeviewer.resources.ExternalResources; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.ZipUtils; @@ -65,20 +66,19 @@ public class KrakatauDecompiler extends InternalDecompiler .map(File::getAbsolutePath).collect(Collectors.joining(";")); } - public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) { - if (Configuration.python.isEmpty()) { - BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); - BytecodeViewer.viewer.selectPythonC(); - } + public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) + { + if(!ExternalResources.getSingleton().hasSetPythonCommand()) + return "You need to set your Python 2.7 path!"; - BCVResourceUtils.rtCheck(); + ExternalResources.getSingleton().rtCheck(); if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage("You need to set your JRE RT Library.\r\n(C:\\Program Files (x86)" + "\\Java\\jre7\\lib\\rt.jar)"); - BytecodeViewer.viewer.selectJRERTLibrary(); + ExternalResources.getSingleton().selectJRERTLibrary(); } - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } @@ -94,7 +94,7 @@ public class KrakatauDecompiler extends InternalDecompiler BytecodeViewer.sm.pauseBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - Configuration.python, + Configuration.python2, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3 @@ -149,17 +149,17 @@ public class KrakatauDecompiler extends InternalDecompiler @Override public String decompileClassNode(ClassNode cn, byte[] b) { - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); - BytecodeViewer.viewer.selectPythonC(); + ExternalResources.getSingleton().selectPython2(); } if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage("You need to set your JRE RT Library." + "\r\n(C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar)"); - BytecodeViewer.viewer.selectJRERTLibrary(); + ExternalResources.getSingleton().selectJRERTLibrary(); } - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } @@ -182,7 +182,7 @@ public class KrakatauDecompiler extends InternalDecompiler try { ProcessBuilder pb = new ProcessBuilder( - Configuration.python, + Configuration.python2, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3 @@ -240,16 +240,16 @@ public class KrakatauDecompiler extends InternalDecompiler @Override public void decompileToZip(String sourceJar, String zipName) { - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); - BytecodeViewer.viewer.selectPythonC(); + ExternalResources.getSingleton().selectPython2(); } - - BCVResourceUtils.rtCheck(); + + ExternalResources.getSingleton().rtCheck(); if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage("You need to set your JRE RT Library." + "\r\n(C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar)"); - BytecodeViewer.viewer.selectJRERTLibrary(); + ExternalResources.getSingleton().selectJRERTLibrary(); } String ran = MiscUtils.randomString(32); @@ -263,7 +263,7 @@ public class KrakatauDecompiler extends InternalDecompiler try { ProcessBuilder pb = new ProcessBuilder( - Configuration.python, + Configuration.python2, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3 diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java index b158d31f..a161a560 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java @@ -12,6 +12,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.decompilers.InternalDecompiler; +import the.bytecode.club.bytecodeviewer.resources.ExternalResources; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.ZipUtils; @@ -46,12 +47,12 @@ public class KrakatauDisassembler extends InternalDecompiler { public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) { - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); - BytecodeViewer.viewer.selectPythonC(); + ExternalResources.getSingleton().selectPython2(); } - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } @@ -62,7 +63,7 @@ public class KrakatauDisassembler extends InternalDecompiler BytecodeViewer.sm.pauseBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - Configuration.python, + Configuration.python2, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "disassemble.py", "-path", @@ -115,12 +116,12 @@ public class KrakatauDisassembler extends InternalDecompiler @Override public String decompileClassNode(ClassNode cn, byte[] b) { - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); - BytecodeViewer.viewer.selectPythonC(); + ExternalResources.getSingleton().selectPython2(); } - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } @@ -136,7 +137,7 @@ public class KrakatauDisassembler extends InternalDecompiler BytecodeViewer.sm.pauseBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - Configuration.python, + Configuration.python2, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "disassemble.py", "-path", @@ -188,9 +189,9 @@ public class KrakatauDisassembler extends InternalDecompiler @Override public void decompileToZip(String sourceJar, String zipName) { - if (Configuration.python.isEmpty()) { + if (Configuration.python2.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); - BytecodeViewer.viewer.selectPythonC(); + ExternalResources.getSingleton().selectPython2(); } String ran = MiscUtils.randomString(32); @@ -202,7 +203,7 @@ public class KrakatauDisassembler extends InternalDecompiler BytecodeViewer.sm.pauseBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - Configuration.python, + Configuration.python2, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "disassemble.py", "-path", 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 271a099d..6a94942f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -25,7 +25,9 @@ import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameMethods; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.plugin.PluginTemplate; import the.bytecode.club.bytecodeviewer.plugin.preinstalled.*; +import the.bytecode.club.bytecodeviewer.resources.ExternalResources; import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.resources.exporting.Export; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJCheckBoxMenuItem; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJRadioButtonMenuItem; @@ -115,6 +117,8 @@ public class MainViewerGUI extends JFrame public final JMenuItem ZKMStringDecrypter = new TranslatedJMenuItem("ZKM String Decrypter", Translation.ZKM_STRING_DECRYPTER); public final JMenuItem allatoriStringDecrypter = new TranslatedJMenuItem("Allatori String Decrypter", Translation.ALLATORI_STRING_DECRYPTER); public final JMenuItem zStringArrayDecrypter = new TranslatedJMenuItem("ZStringArray Decrypter", Translation.ZSTRINGARRAY_DECRYPTER); + public final JMenuItem viewAPKAndroidPermissions = new JMenuItem("View Android Permissions"); + public final JMenuItem viewManifest = new JMenuItem("View Manifest"); //all of the settings main menu components public final ButtonGroup apkConversionGroup = new ButtonGroup(); @@ -560,11 +564,11 @@ public class MainViewerGUI extends JFrame deleteForeignOutdatedLibs.addActionListener(arg0 -> showForeignLibraryWarning()); forcePureAsciiAsText.addActionListener(arg0 -> SettingsSerializer.saveSettingsAsync()); - setPython2.addActionListener(arg0 -> selectPythonC()); - setJRERT.addActionListener(arg0 -> selectJRERTLibrary()); - setPython3.addActionListener(arg0 -> selectPythonC3()); - setOptionalLibrary.addActionListener(arg0 -> selectOpenalLibraryFolder()); - setJavac.addActionListener(arg0 -> selectJavac()); + setPython2.addActionListener(arg0 -> ExternalResources.getSingleton().selectPython2()); + setJRERT.addActionListener(arg0 -> ExternalResources.getSingleton().selectJRERTLibrary()); + setPython3.addActionListener(arg0 -> ExternalResources.getSingleton().selectPython3()); + setOptionalLibrary.addActionListener(arg0 -> ExternalResources.getSingleton().selectOptionalLibraryFolder()); + setJavac.addActionListener(arg0 -> ExternalResources.getSingleton().selectJavac()); showFileInTabTitle.addActionListener(arg0 -> { Configuration.displayParentInTab = BytecodeViewer.viewer.showFileInTabTitle.isSelected(); SettingsSerializer.saveSettingsAsync(); @@ -586,7 +590,10 @@ public class MainViewerGUI extends JFrame pluginsMainMenu.add(new JSeparator()); pluginsMainMenu.add(newJavaPlugin); pluginsMainMenu.add(newJavascriptPlugin); + pluginsMainMenu.add(new JSeparator()); //android specific plugins first + pluginsMainMenu.add(viewAPKAndroidPermissions); pluginsMainMenu.add(new JSeparator()); + pluginsMainMenu.add(viewManifest); pluginsMainMenu.add(codeSequenceDiagram); pluginsMainMenu.add(maliciousCodeScanner); pluginsMainMenu.add(showMainMethods); @@ -594,10 +601,11 @@ public class MainViewerGUI extends JFrame pluginsMainMenu.add(replaceStrings); pluginsMainMenu.add(stackFramesRemover); - //allatori and ZKM are disabled since they are just placeholders + //allatori is disabled since they are just placeholders + //ZKM and ZStringArray decrypter are disabled until deobfuscation has been extended //mnNewMenu_1.add(mntmNewMenuItem_2); //mnNewMenu_1.add(mntmStartZkmString); - pluginsMainMenu.add(zStringArrayDecrypter); + //pluginsMainMenu.add(zStringArrayDecrypter); openExternalPlugin.addActionListener(arg0 -> openExternalPlugin()); newJavaPlugin.addActionListener(arg0 -> PluginTemplate.JAVA.openEditorExceptionHandled()); @@ -611,6 +619,8 @@ public class MainViewerGUI extends JFrame allatoriStringDecrypter.addActionListener(e -> PluginManager.runPlugin(new AllatoriStringDecrypter.AllatoriStringDecrypterOptions())); ZKMStringDecrypter.addActionListener(e -> PluginManager.runPlugin(new ZKMStringDecrypter())); zStringArrayDecrypter.addActionListener(arg0 -> PluginManager.runPlugin(new ZStringArrayDecrypter())); + viewAPKAndroidPermissions.addActionListener(arg0 -> PluginManager.runPlugin(new ViewAPKAndroidPermissions())); + viewManifest.addActionListener(arg0 -> PluginManager.runPlugin(new ViewManifest())); } public void buildObfuscateMenu() @@ -803,7 +813,7 @@ public class MainViewerGUI extends JFrame LazyNameUtil.reset(); ArrayList reopen = new ArrayList<>(); - for (ResourceContainer container : BytecodeViewer.files) { + for (ResourceContainer container : BytecodeViewer.resourceContainers) { File newFile = new File(container.file.getParent() + fs + container.name); if (!container.file.getAbsolutePath().equals(newFile.getAbsolutePath()) && (container.file.getAbsolutePath().endsWith(".apk") || container.file.getAbsolutePath().endsWith(".dex"))) //APKs & dex get renamed @@ -814,7 +824,7 @@ public class MainViewerGUI extends JFrame reopen.add(container.file); } - BytecodeViewer.files.clear(); + BytecodeViewer.resourceContainers.clear(); for (File f : reopen) { BytecodeViewer.openFiles(new File[]{f}, false); @@ -837,83 +847,6 @@ public class MainViewerGUI extends JFrame BytecodeViewer.openFiles(new File[]{file}, true); BytecodeViewer.updateBusyStatus(false); } - - public void selectPythonC() - { - final File file = DialogueUtils.fileChooser("Select Python 2.7 Executable", - "Python (Or PyPy for speed) 2.7 Executable", - "everything"); - - if(file == null) - return; - - Configuration.python = file.getAbsolutePath(); - SettingsSerializer.saveSettingsAsync(); - } - - public void selectJavac() - { - final File file = DialogueUtils.fileChooser("Select Javac Executable", - "Javac Executable (Requires JDK 'C:/programfiles/Java/JDK_xx/bin/javac.exe)", - "everything"); - - if(file == null) - return; - - Configuration.javac = file.getAbsolutePath(); - SettingsSerializer.saveSettingsAsync(); - } - - public void selectJava() - { - final File file = DialogueUtils.fileChooser("Select Java Executable", - "Java Executable (Inside Of JRE/JDK 'C:/programfiles/Java/JDK_xx/bin/java.exe')", - "everything"); - - if(file == null) - return; - - Configuration.java = file.getAbsolutePath(); - SettingsSerializer.saveSettingsAsync(); - } - - public void selectPythonC3() - { - final File file = DialogueUtils.fileChooser("Select Python 3.x Executable", - "Python (Or PyPy for speed) 3.x Executable", - "everything"); - - if(file == null) - return; - - Configuration.python3 = file.getAbsolutePath(); - SettingsSerializer.saveSettingsAsync(); - } - - public void selectOpenalLibraryFolder() - { - final File file = DialogueUtils.fileChooser("Select Library Folder", - "Optional Library Folder", - "everything"); - - if(file == null) - return; - - Configuration.library = file.getAbsolutePath(); - SettingsSerializer.saveSettingsAsync(); - } - - public void selectJRERTLibrary() { - final File file = DialogueUtils.fileChooser("Select JRE RT Jar", - "JRE RT Library", - "everything"); - - if(file == null) - return; - - Configuration.rt = file.getAbsolutePath(); - SettingsSerializer.saveSettingsAsync(); - } public void openExternalPlugin() { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/AboutWindow.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/AboutWindow.java index 3f1065ba..001b3671 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/AboutWindow.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/AboutWindow.java @@ -4,15 +4,11 @@ import java.awt.*; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JScrollPane; -import javax.swing.JTextArea; import the.bytecode.club.bootloader.InitialBootScreen; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import static the.bytecode.club.bytecodeviewer.Configuration.*; -import static the.bytecode.club.bytecodeviewer.Constants.*; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java index 016b76de..abb070c5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java @@ -34,7 +34,7 @@ public class HTMLPane extends JEditorPane text = text.replace("{java}", Configuration.java); text = text.replace("{javac}", Configuration.javac); text = text.replace("{bcvDir}", BCVDir.getAbsolutePath()); - text = text.replace("{python}", Configuration.python); + text = text.replace("{python}", Configuration.python2); text = text.replace("{python3}", Configuration.python3); text = text.replace("{rt}", Configuration.rt); text = text.replace("{lib}", Configuration.library); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java index 25fcdc07..a6c6bd3c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java @@ -1,6 +1,6 @@ package the.bytecode.club.bytecodeviewer.gui.components; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsolePrintStream.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsolePrintStream.java index b586773c..37cadc35 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsolePrintStream.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsolePrintStream.java @@ -106,11 +106,7 @@ public class JFrameConsolePrintStream extends JFrameConsole String content = getTextArea().getText(); if(content.contains("File `")) { - String[] test; - if (content.split("\n").length >= 2) - test = content.split("\n"); - else - test = content.split("\r"); + String[] test = content.split("\r?\n"); StringBuilder replace = new StringBuilder(); for (String s : test) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java index 2f00fa71..a21cbb6d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java @@ -7,7 +7,7 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.api.ASMResourceUtil; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.plugin.preinstalled.EZInjection; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableJTextArea.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableJTextArea.java index 8fea293d..c809c836 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableJTextArea.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableJTextArea.java @@ -1,8 +1,7 @@ package the.bytecode.club.bytecodeviewer.gui.components; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.GlobalHotKeys; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.gui.components.listeners.PressKeyListener; import the.bytecode.club.bytecodeviewer.gui.components.listeners.ReleaseKeyListener; import the.bytecode.club.bytecodeviewer.translation.Translation; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java index 6d1cc377..57d6b8c9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java @@ -2,10 +2,9 @@ package the.bytecode.club.bytecodeviewer.gui.components; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rtextarea.RTextScrollPane; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.GlobalHotKeys; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.gui.components.listeners.PressKeyListener; import the.bytecode.club.bytecodeviewer.gui.components.listeners.ReleaseKeyListener; import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java index d748f25a..e02404fb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java @@ -1,6 +1,6 @@ package the.bytecode.club.bytecodeviewer.gui.components; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import javax.swing.*; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java index 1f2a8a0b..c421942a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java @@ -5,7 +5,7 @@ import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java index 04741343..0b43f40c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java @@ -1,7 +1,7 @@ package the.bytecode.club.bytecodeviewer.gui.plugins; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareScanModule; import the.bytecode.club.bytecodeviewer.malwarescanner.util.MaliciousCodeOptions; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java index 46e54f74..350c77f6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java @@ -8,7 +8,7 @@ import javax.swing.JLabel; import javax.swing.JTextField; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.plugin.preinstalled.ReplaceStrings; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java index 7fa505ee..f106524e 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java @@ -1,6 +1,6 @@ package the.bytecode.club.bytecodeviewer.gui.resourcelist; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import javax.swing.*; import javax.swing.tree.DefaultTreeCellRenderer; 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 3b7e03b4..d5815fcf 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 @@ -111,7 +111,7 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File //used to remove resources from the resource list public void removeFile(ResourceContainer resourceContainer) { - BytecodeViewer.files.remove(resourceContainer); + BytecodeViewer.resourceContainers.remove(resourceContainer); LazyNameUtil.removeName(resourceContainer.name); } @@ -160,7 +160,7 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File try { treeRoot.removeAllChildren(); - for (ResourceContainer container : BytecodeViewer.files) + for (ResourceContainer container : BytecodeViewer.resourceContainers) { ResourceTreeNode root = new ResourceTreeNode(container.name); treeRoot.add(root); @@ -301,7 +301,7 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File String cheapHax = path.getPathComponent(1).toString(); ResourceContainer container = null; - for (ResourceContainer c : BytecodeViewer.files) + for (ResourceContainer c : BytecodeViewer.resourceContainers) { if (c.name.equals(cheapHax)) container = c; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListRightClickRemove.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListRightClickRemove.java index 457a2459..cb64c7b9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListRightClickRemove.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListRightClickRemove.java @@ -44,7 +44,7 @@ public class ResourceListRightClickRemove extends AbstractAction DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot(); root.remove(node); - for (ResourceContainer resourceContainer : BytecodeViewer.files) + for (ResourceContainer resourceContainer : BytecodeViewer.resourceContainers) { if (resourceContainer.name.equals(selectNode.toString())) { 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 830c1cca..39715dab 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 @@ -2,7 +2,6 @@ package the.bytecode.club.bytecodeviewer.gui.resourcesearch; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread; import the.bytecode.club.bytecodeviewer.searching.RegexInsnFinder; import the.bytecode.club.bytecodeviewer.searching.impl.RegexSearch; @@ -11,7 +10,6 @@ import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; import javax.swing.tree.TreePath; -import java.util.Objects; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -42,7 +40,7 @@ class PerformSearch extends BackgroundSearchThread BytecodeViewer.showMessage("You have an error in your regex syntax."); } - for (ResourceContainer container : BytecodeViewer.files) + for (ResourceContainer container : BytecodeViewer.resourceContainers) 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/plugin/PluginTemplate.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginTemplate.java index 88f238f1..df40b9f6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginTemplate.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginTemplate.java @@ -2,8 +2,7 @@ package the.bytecode.club.bytecodeviewer.plugin; import org.apache.commons.io.FilenameUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Resources; -import the.bytecode.club.bytecodeviewer.api.ExceptionUI; +import the.bytecode.club.bytecodeviewer.resources.Resources; import java.io.IOException; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java index c73359b9..b8d652bf 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java @@ -4,8 +4,7 @@ import me.konloch.kontainer.io.DiskWriter; import org.apache.commons.compress.utils.FileNameUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.Resources; -import the.bytecode.club.bytecodeviewer.api.ExceptionUI; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.gui.components.SearchableRSyntaxTextArea; import the.bytecode.club.bytecodeviewer.translation.Translation; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java index adf72534..5afb4dbe 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java @@ -8,7 +8,7 @@ import java.util.ArrayList; import org.objectweb.asm.tree.*; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Constants; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.api.*; import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java index 65c7a465..4d63a00a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java @@ -13,7 +13,7 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java index 30bca2ba..41a6e3ec 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java @@ -34,7 +34,16 @@ public class ViewAPKAndroidPermissions extends Plugin String[] lines = manifest.split("\r?\n"); for(String line : lines) if(line.toLowerCase().contains("uses-permission")) - frame.appendText(line.trim()); + { + String cleaned = line.trim(); + if(cleaned.startsWith("<")) + cleaned = cleaned.substring(1); + if(cleaned.contains(" android:name=\"")) + cleaned = cleaned.replace(" android:name=\"", ": "); + if(cleaned.endsWith("\"/>")) + cleaned = cleaned.substring(0, cleaned.length()-3); + frame.appendText(cleaned); + } } else frame.appendText("Enable Settings>Decode APK Resources!"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java index 5357c8eb..ef30b731 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java @@ -36,7 +36,7 @@ public class ViewManifest extends Plugin if(jarManifest != null) { if(!frame.getTextArea().getText().isEmpty()) - frame.appendText("\r\r\r\r"); + frame.appendText("\r\n\r\n"); frame.appendText("Java Jar Manifest:\r"); frame.appendText(new String(jarManifest, StandardCharsets.UTF_8)); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ExternalResources.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ExternalResources.java new file mode 100644 index 00000000..e95853d6 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ExternalResources.java @@ -0,0 +1,281 @@ +package the.bytecode.club.bytecodeviewer.resources; + +import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; +import the.bytecode.club.bytecodeviewer.SettingsSerializer; +import the.bytecode.club.bytecodeviewer.util.DialogueUtils; +import the.bytecode.club.bytecodeviewer.util.JRTExtractor; + +import java.io.File; +import java.util.Objects; + +import static the.bytecode.club.bytecodeviewer.Constants.*; + +/*************************************************************************** + * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * + * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +/** + * Anything that isn't accessible from inside of the JVM is here + * + * @author Konloch + * @since 7/11/2021 + */ +public class ExternalResources +{ + private static final ExternalResources SINGLETON = new ExternalResources(); + + public static ExternalResources getSingleton() + { + return SINGLETON; + } + + /** + * Auto-detect the Java command + */ + public String getJavaCommand(boolean blockTillSelected) + { + boolean empty = Configuration.java.isEmpty(); + + if(!empty) + return Configuration.java; + + BytecodeViewer.sm.pauseBlocking(); + try + { + //TODO read the version output to verify it exists + ProcessBuilder pb = new ProcessBuilder("java", "-version"); + pb.start(); + + Configuration.java = "java"; //java is set + return Configuration.java; + } + catch (Exception e) { } //ignore + finally + { + BytecodeViewer.sm.resumeBlocking(); + } + + //TODO auto-detect the Java path + boolean block = true; + while (Configuration.java.isEmpty() && block) + { + BytecodeViewer.showMessage("You need to set your Java path, this requires the JRE to be downloaded." + + nl + "(C:/Program Files/Java/JDK_xx/bin/java.exe)"); + ExternalResources.getSingleton().selectJava(); + block = !blockTillSelected; //signal block flag off + } + + return Configuration.java; + } + + /** + * Check if the python command has been set + */ + public boolean hasSetPythonCommand() + { + return !getPythonCommand(false).isEmpty(); + } + + /** + * Auto-detect the Java command + */ + public String getPythonCommand(boolean blockTillSelected) + { + boolean empty = Configuration.java.isEmpty(); + + if(!empty) + return Configuration.java; + + BytecodeViewer.sm.pauseBlocking(); + + //check using python CLI flag + try + { + //TODO read the version output to verify python 2 + ProcessBuilder pb = new ProcessBuilder("python", "-2", "--version"); + pb.start(); + + Configuration.python2 = "python -2"; //python is set + return Configuration.python2; + } + catch (Exception e) { } //ignore + finally + { + BytecodeViewer.sm.resumeBlocking(); + } + + //check if 'python' command is bound as python 2.X + try + { + //TODO read the version output to verify python 2 + ProcessBuilder pb = new ProcessBuilder("python", "--version"); + pb.start(); + + Configuration.python2 = "python"; //python is set + return Configuration.python2; + } + catch (Exception e) { } //ignore + finally + { + BytecodeViewer.sm.resumeBlocking(); + } + + //TODO auto-detect the Python path + boolean block = true; + while (Configuration.python2.isEmpty() && block) + { + BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); + selectPython2(); + block = !blockTillSelected; //signal block flag off + } + + return Configuration.python2; + } + + //rt.jar check + public synchronized void rtCheck() + { + if (Configuration.rt.isEmpty()) + { + if (RT_JAR.exists()) + Configuration.rt = RT_JAR.getAbsolutePath(); + else if (RT_JAR_DUMPED.exists()) + Configuration.rt = RT_JAR_DUMPED.getAbsolutePath(); + else try { + JRTExtractor.extractRT(RT_JAR_DUMPED.getAbsolutePath()); + Configuration.rt = RT_JAR_DUMPED.getAbsolutePath(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + + public void selectPython2() + { + final File file = DialogueUtils.fileChooser("Select Python 2.7 Executable", + "Python (Or PyPy for speed) 2.7 Executable", + "everything"); + + if(file == null) + return; + + Configuration.python2 = file.getAbsolutePath(); + SettingsSerializer.saveSettingsAsync(); + } + + public void selectPython3() + { + final File file = DialogueUtils.fileChooser("Select Python 3.x Executable", + "Python (Or PyPy for speed) 3.x Executable", + "everything"); + + if(file == null) + return; + + Configuration.python3 = file.getAbsolutePath(); + SettingsSerializer.saveSettingsAsync(); + } + + public void selectJavac() + { + final File file = DialogueUtils.fileChooser("Select Javac Executable", + "Javac Executable (Requires JDK 'C:/Program Files/Java/JDK_xx/bin/javac.exe)", + "everything"); + + if(file == null) + return; + + Configuration.javac = file.getAbsolutePath(); + SettingsSerializer.saveSettingsAsync(); + } + + public void selectJava() + { + final File file = DialogueUtils.fileChooser("Select Java Executable", + "Java Executable (Inside Of JRE/JDK 'C:/Program Files/Java/JDK_xx/bin/java.exe')", + "everything"); + + if(file == null) + return; + + Configuration.java = file.getAbsolutePath(); + SettingsSerializer.saveSettingsAsync(); + } + + public void selectOptionalLibraryFolder() + { + final File file = DialogueUtils.fileChooser("Select Library Folder", + "Optional Library Folder", + "everything"); + + if(file == null) + return; + + Configuration.library = file.getAbsolutePath(); + SettingsSerializer.saveSettingsAsync(); + } + + public void selectJRERTLibrary() + { + final File file = DialogueUtils.fileChooser("Select JRE RT Jar", + "JRE RT Library", + "everything"); + + if(file == null) + return; + + Configuration.rt = file.getAbsolutePath(); + SettingsSerializer.saveSettingsAsync(); + } + + /** + * Finds a library from the library folder + */ + public String findLibrary(String nameContains) + { + for (File f : Objects.requireNonNull(new File(libsDirectory).listFiles())) + if (f.getName().contains(nameContains)) + return f.getAbsolutePath(); + + return null; + } + + /** + * Searches a directory until the extension is found + */ + public File findFile(File basePath, String extension) + { + for(File f : basePath.listFiles()) + { + if(f.isDirectory()) + { + File child = findFile(f, extension); + + if(child != null) + return child; + + continue; + } + + if(f.getName().endsWith(extension)) + return f; + } + + return null; + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Resources.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/Resources.java similarity index 97% rename from src/main/java/the/bytecode/club/bytecodeviewer/Resources.java rename to src/main/java/the/bytecode/club/bytecodeviewer/resources/Resources.java index 9729de35..4b6fcd1b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Resources.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/Resources.java @@ -1,6 +1,5 @@ -package the.bytecode.club.bytecodeviewer; +package the.bytecode.club.bytecodeviewer.resources; -import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.File; @@ -15,6 +14,7 @@ import javax.swing.*; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.imgscalr.Scalr; +import the.bytecode.club.bytecodeviewer.BytecodeViewer; import static the.bytecode.club.bytecodeviewer.Constants.libsDirectory; @@ -42,8 +42,8 @@ import static the.bytecode.club.bytecodeviewer.Constants.libsDirectory; * @author Konloch */ -public class Resources { - +public class Resources +{ public static List iconList; public static BufferedImage icon; public static ImageIcon nextIcon; @@ -134,13 +134,4 @@ public class Resources { return image; } - - public static String findLibrary(String nameContains) { - for (File f : Objects.requireNonNull(new File(libsDirectory).listFiles())) { - if (f.getName().contains(nameContains)) - return f.getAbsolutePath(); - } - - return null; - } } 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 edbdee32..27cfb474 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 @@ -28,7 +28,7 @@ public class APKExport implements Exporter if (BytecodeViewer.promptIfNoLoadedClasses()) return; - List containers = BytecodeViewer.getFiles(); + List containers = BytecodeViewer.getResourceContainers(); List validContainers = new ArrayList<>(); List validContainersNames = new ArrayList<>(); ResourceContainer container; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java index 44d0a1db..d9d82af2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java @@ -22,17 +22,15 @@ public class APKResourceImporter implements Importer @Override public void open(File file) throws Exception { - BytecodeViewer.updateBusyStatus(true); - File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk"); - FileUtils.copyFile(file, tempCopy); ResourceContainer container = new ResourceContainer(tempCopy, file.getName()); - if (BytecodeViewer.viewer.decodeAPKResources.isSelected()) { - File decodedResources = - new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk"); + //APK Resource Decoding Here + if (BytecodeViewer.viewer.decodeAPKResources.isSelected()) + { + File decodedResources = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk"); APKTool.decodeResources(tempCopy, decodedResources, container); container.resourceFiles = JarUtils.loadResources(decodedResources); } @@ -52,7 +50,6 @@ public class APKResourceImporter implements Importer container.copy(new ResourceContainerImporter( new ResourceContainer(output)).importAsZip().getContainer()); - BytecodeViewer.updateBusyStatus(false); - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ClassResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ClassResourceImporter.java index 43c53cd2..f2782006 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ClassResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ClassResourceImporter.java @@ -38,6 +38,6 @@ public class ClassResourceImporter implements Importer //TODO double check this container.resourceFiles.put(name, bytes); } - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DEXResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DEXResourceImporter.java index 73af8cd2..0fd928d2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DEXResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DEXResourceImporter.java @@ -21,8 +21,6 @@ public class DEXResourceImporter implements Importer @Override public void open(File file) throws Exception { - BytecodeViewer.updateBusyStatus(true); - File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".dex"); FileUtils.copyFile(file, tempCopy); //copy and rename to prevent unicode filenames @@ -41,7 +39,6 @@ public class DEXResourceImporter implements Importer container.copy(new ResourceContainerImporter( new ResourceContainer(output)).importAsZip().getContainer()); - BytecodeViewer.updateBusyStatus(false); - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java index ed2bc328..8c796920 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java @@ -88,6 +88,6 @@ public class DirectoryResourceImporter implements Importer container.resourceClasses.putAll(allDirectoryClasses); container.resourceFiles = allDirectoryFiles; - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/FileResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/FileResourceImporter.java index 73870abb..d3b35869 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/FileResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/FileResourceImporter.java @@ -23,6 +23,6 @@ public class FileResourceImporter implements Importer //import the file into the file container importer.importAsFile(); //add the file container to BCV's total loaded files - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java index 911c5db1..f0c4bfc6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java @@ -72,7 +72,7 @@ public class XAPKResourceImporter implements Importer Configuration.silenceExceptionGUI--; //turn exceptions back on BytecodeViewer.viewer.clearBusyStatus(); //clear errant busy signals from failed APK imports container.resourceFiles = allDirectoryFiles; //store the file resource - BytecodeViewer.files.add(container); //add the file container to BCV's total loaded files + BytecodeViewer.resourceContainers.add(container); //add the file container to BCV's total loaded files } public File exportTo(File original, String extension, byte[] bytes) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java index 2421465d..acddd4a7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java @@ -23,6 +23,6 @@ public class ZipResourceImporter implements Importer //import the file as zip into the file container importer.importAsZip(); //add the file container to BCV's total loaded files - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/translation/Language.java b/src/main/java/the/bytecode/club/bytecodeviewer/translation/Language.java index 61f69c22..4cbc62d3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/translation/Language.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/translation/Language.java @@ -4,7 +4,7 @@ import com.google.gson.reflect.TypeToken; import org.apache.commons.collections4.map.HashedMap; import org.apache.commons.collections4.map.LinkedMap; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.resources.Resources; import java.io.IOException; import java.util.Arrays; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVFileUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVFileUtils.java deleted file mode 100644 index ae3d8f25..00000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVFileUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -package the.bytecode.club.bytecodeviewer.util; - -import java.io.File; - -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -/** - * @author Konloch - * @since 7/4/2021 - */ -public class BCVFileUtils -{ - /** - * Searches a directory until the extension is found - */ - public static File findFile(File basePath, String extension) - { - for(File f : basePath.listFiles()) - { - if(f.isDirectory()) - { - File child = findFile(f, extension); - - if(child != null) - return child; - - continue; - } - - if(f.getName().endsWith(extension)) - { - return f; - } - } - - return null; - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVResourceUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVResourceUtils.java deleted file mode 100644 index ce559e58..00000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVResourceUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -package the.bytecode.club.bytecodeviewer.util; - -import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.api.BCV; - -import java.io.File; - -import static the.bytecode.club.bytecodeviewer.Constants.*; -import static the.bytecode.club.bytecodeviewer.Constants.RT_JAR_DUMPED; - -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -/** - * @author Konloch - * @since 7/6/2021 - */ -public class BCVResourceUtils -{ - //rt.jar check - public synchronized static void rtCheck() - { - if (Configuration.rt.isEmpty()) - { - if (RT_JAR.exists()) - Configuration.rt = RT_JAR.getAbsolutePath(); - else if (RT_JAR_DUMPED.exists()) - Configuration.rt = RT_JAR_DUMPED.getAbsolutePath(); - else try { - JRTExtractor.extractRT(RT_JAR_DUMPED.getAbsolutePath()); - Configuration.rt = RT_JAR_DUMPED.getAbsolutePath(); - } catch (Throwable t) { - t.printStackTrace(); - } - } - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/Enjarify.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/Enjarify.java index ac60e7ab..8a1b1f80 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/Enjarify.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/Enjarify.java @@ -3,6 +3,7 @@ package the.bytecode.club.bytecodeviewer.util; import java.io.File; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; +import the.bytecode.club.bytecodeviewer.resources.ExternalResources; import static the.bytecode.club.bytecodeviewer.Constants.enjarifyWorkingDirectory; @@ -41,7 +42,7 @@ public class Enjarify { public static synchronized void apk2Jar(File input, File output) { if (Configuration.python3.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 3.x executable path."); - BytecodeViewer.viewer.selectPythonC3(); + ExternalResources.getSingleton().selectPython3(); } if (Configuration.python3.isEmpty()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/JTextAreaUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/JTextAreaUtils.java index 024676b2..6779de54 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JTextAreaUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JTextAreaUtils.java @@ -56,9 +56,7 @@ public class JTextAreaUtils int currentLine = 1; boolean canSearch = false; - String[] test = (textArea.getText().split("\n").length >= 2 - ? textArea.getText().split("\n") - : textArea.getText().split("\r")); + String[] test = textArea.getText().split("\r?\n"); int lastGoodLine = -1; int firstPos = -1; 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 755d0ec1..922f6f34 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -103,7 +103,7 @@ public class JarUtils } jis.close(); container.resourceFiles = files; - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } @@ -152,7 +152,7 @@ public class JarUtils } container.resourceFiles = files; - BytecodeViewer.files.add(container); + BytecodeViewer.resourceContainers.add(container); } public static ArrayList loadClasses(final File jarFile) throws IOException @@ -262,7 +262,7 @@ public class JarUtils out.write((manifest.trim() + "\r\n\r\n").getBytes()); out.closeEntry(); - for (ResourceContainer container : BytecodeViewer.files) + for (ResourceContainer container : BytecodeViewer.resourceContainers) for (Entry entry : container.resourceFiles.entrySet()) { String filename = entry.getKey(); if (!filename.startsWith("META-INF")) { @@ -366,7 +366,7 @@ public class JarUtils } } - for (ResourceContainer container : BytecodeViewer.files) + for (ResourceContainer container : BytecodeViewer.resourceContainers) for (Entry entry : container.resourceFiles.entrySet()) { String filename = entry.getKey(); if (!filename.startsWith("META-INF")) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java index 7aa85883..f6d082b6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java @@ -49,6 +49,7 @@ public class SecurityMan extends SecurityManager executedClass.equals("the.bytecode.club.bytecodeviewer.decompilers.impl.FernFlowerDecompiler") || executedClass.equals("the.bytecode.club.bytecodeviewer.decompilers.impl.JDGUIDecompiler") || executedClass.equals("the.bytecode.club.bytecodeviewer.compilers.impl.KrakatauAssembler") || + executedClass.equals("the.bytecode.club.bytecodeviewer.resources.ExternalResources") || executedClass.equals("the.bytecode.club.bytecodeviewer.util.Enjarify") || executedClass.equals("the.bytecode.club.bytecodeviewer.util.APKTool") || executedClass.equals("the.bytecode.club.bytecodeviewer.BytecodeViewer") ||