From 00a1bb539f5450f0eac813eb8b128eb7826062a5 Mon Sep 17 00:00:00 2001 From: Konloch Date: Mon, 21 Jun 2021 04:13:11 -0700 Subject: [PATCH] Added a Configuration class Moved the rest of the config-like variables from the main BytecodeViewer class to a new Configuration class --- .../club/bootloader/InitialBootScreen.java | 3 +- .../club/bytecodeviewer/BytecodeViewer.java | 122 ++++++------------ .../club/bytecodeviewer/CommandLineInput.java | 2 +- .../club/bytecodeviewer/Configuration.java | 31 +++++ .../club/bytecodeviewer/Settings.java | 44 +++---- .../compilers/JavaCompiler.java | 13 +- .../compilers/KrakatauAssembler.java | 7 +- .../decompilers/KrakatauDecompiler.java | 45 +++---- .../decompilers/KrakatauDisassembler.java | 19 +-- .../bytecode/InstructionPrinter.java | 2 +- .../club/bytecodeviewer/gui/AboutWindow.java | 2 +- .../club/bytecodeviewer/gui/ClassViewer.java | 7 +- .../bytecodeviewer/gui/MainViewerGUI.java | 84 ++++-------- .../club/bytecodeviewer/gui/WorkPane.java | 5 +- .../obfuscators/JavaObfuscator.java | 8 +- .../club/bytecodeviewer/util/Enjarify.java | 7 +- .../club/bytecodeviewer/util/MiscUtils.java | 15 +++ .../club/bytecodeviewer/util/SecurityMan.java | 4 +- .../club/bytecodeviewer/util/ZipUtils.java | 4 +- 19 files changed, 205 insertions(+), 219 deletions(-) create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java diff --git a/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java b/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java index b10584ac..1207a778 100644 --- a/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java +++ b/src/main/java/the/bytecode/club/bootloader/InitialBootScreen.java @@ -14,6 +14,7 @@ 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; /*************************************************************************** @@ -49,7 +50,7 @@ public class InitialBootScreen extends JFrame { addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { - BytecodeViewer.canExit = true; + Configuration.canExit = true; System.exit(0); } }); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index f765c321..202372d0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -80,6 +80,7 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * Finish right-click tab menu detection * make it use that global last used inside of export as jar * Add https://github.com/ptnkjke/Java-Bytecode-Editor visualize as a plugin + * Add https://github.com/exbin/bined as the replacement Hed Viewer/Editor * make zipfile not include the decode shit * add stackmapframes to bytecode decompiler * make ez-injection plugin console show all sys.out calls @@ -96,28 +97,6 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; public class BytecodeViewer { - public static String python = ""; - public static String python3 = ""; - public static String rt = ""; - public static String library = ""; - public static String javac = ""; - public static String java = ""; - private static File krakatauTempDir; - private static File krakatauTempJar; - public static boolean displayParentInTab = false; //also change in the main GUI - public static boolean currentlyDumping = false; - public static boolean needsReDump = true; - public static boolean warnForEditing = false; - public static boolean runningObfuscation = false; - private static final long start = System.currentTimeMillis(); - public static String lastDirectory = "."; - public static boolean pingback = false; - public static boolean deleteForeignLibraries = true; - public static boolean canExit = false; - - private static long last = System.currentTimeMillis(); - - public static boolean verify = false; //eventually may be a setting public static String[] args; public static MainViewerGUI viewer = null; @@ -126,8 +105,7 @@ public class BytecodeViewer public static Refactorer refactorer = new Refactorer(); public static List files = new ArrayList<>(); //all of BCV's loaded files/classes/etc public static List createdProcesses = new ArrayList<>(); - - + /** * The version checker thread */ @@ -140,7 +118,7 @@ public class BytecodeViewer try { new HTTPRequest(new URL("https://bytecodeviewer.com/add.php")).read(); } catch (Exception e) { - pingback = false; + Configuration.pingback = false; } }); @@ -248,9 +226,9 @@ public class BytecodeViewer viewer.calledAfterLoad(); resetRecentFilesMenu(); - if (!pingback) { + if (!Configuration.pingback) { PingBack.start(); - pingback = true; + Configuration.pingback = true; } if (viewer.chckbxmntmNewCheckItem_12.isSelected()) @@ -259,13 +237,12 @@ public class BytecodeViewer if (!cli) viewer.setVisible(true); - System.out.println("Start up took " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); + System.out.println("Start up took " + ((System.currentTimeMillis() - Configuration.start) / 1000) + " seconds"); if (!cli) if (args.length >= 1) - for (String s : args) { + for (String s : args) openFiles(new File[]{new File(s)}, true); - } } /** @@ -291,15 +268,15 @@ public class BytecodeViewer return "java"; //java is set } catch (Exception e) { //ignore sm.setBlocking(); - boolean empty = java.isEmpty(); + boolean empty = Configuration.java.isEmpty(); while (empty) { showMessage("You need to set your Java path, this requires the JRE to be downloaded." + nl + - "(C:/programfiles/Java/JDK_xx/bin/java.exe)"); + "(C:/Program Files/Java/JDK_xx/bin/java.exe)"); viewer.java(); - empty = java.isEmpty(); + empty = Configuration.java.isEmpty(); } } - return java; + return Configuration.java; } /** @@ -518,7 +495,7 @@ public class BytecodeViewer BytecodeViewer.addRecentFile(f); BytecodeViewer.viewer.setIcon(true); - needsReDump = true; + Configuration.needsReDump = true; Thread t = new Thread(new OpenFile(files)); t.start(); } @@ -687,16 +664,15 @@ public class BytecodeViewer * @param e */ public static void checkHotKey(KeyEvent e) { - if (System.currentTimeMillis() - last <= (4000)) + if (System.currentTimeMillis() - Configuration.lastHotKeyExecuted <= (4000)) return; if ((e.getKeyCode() == KeyEvent.VK_O) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); + Configuration.lastHotKeyExecuted = System.currentTimeMillis(); JFileChooser fc = new JFileChooser(); try { - fc.setSelectedFile(new File(BytecodeViewer.lastDirectory)); + fc.setSelectedFile(new File(Configuration.lastDirectory)); } catch (Exception ignored) { - } fc.setFileFilter(new FileFilter() { @Override @@ -721,7 +697,7 @@ public class BytecodeViewer int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - BytecodeViewer.lastDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); try { BytecodeViewer.viewer.setIcon(true); BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true); @@ -731,21 +707,21 @@ public class BytecodeViewer } } } else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); + Configuration.lastHotKeyExecuted = System.currentTimeMillis(); BytecodeViewer.resetWorkSpace(true); } else if ((e.getKeyCode() == KeyEvent.VK_T) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); + Configuration.lastHotKeyExecuted = System.currentTimeMillis(); Thread t = new Thread(() -> BytecodeViewer.compile(true)); t.start(); } else if ((e.getKeyCode() == KeyEvent.VK_R) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); + Configuration.lastHotKeyExecuted = System.currentTimeMillis(); if (BytecodeViewer.getLoadedClasses().isEmpty()) { BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); return; } new RunOptions().setVisible(true); } else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); + Configuration.lastHotKeyExecuted = System.currentTimeMillis(); if (BytecodeViewer.getLoadedClasses().isEmpty()) { BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); @@ -809,7 +785,7 @@ public class BytecodeViewer }); t.start(); } else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); + Configuration.lastHotKeyExecuted = System.currentTimeMillis(); if (viewer.workPane.getCurrentViewer() != null) viewer.workPane.tabs.remove(viewer.workPane.getCurrentViewer()); } @@ -819,13 +795,13 @@ public class BytecodeViewer File[] files = new File[2]; //currently won't optimize if you've got two containers with the same name, will need to add this later if (!LazyNameUtil.SAME_NAME_JAR_WORKSPACE) { - if (krakatauTempJar != null && !krakatauTempJar.exists()) { - needsReDump = true; + if (Configuration.krakatauTempJar != null && !Configuration.krakatauTempJar.exists()) { + Configuration.needsReDump = true; } - if (needsReDump && krakatauTempJar != null) { - krakatauTempDir = null; - krakatauTempJar = null; + if (Configuration.needsReDump && Configuration.krakatauTempJar != null) { + Configuration.krakatauTempDir = null; + Configuration.krakatauTempJar = null; } boolean passes = false; @@ -843,54 +819,42 @@ public class BytecodeViewer else if (BytecodeViewer.viewer.panelGroup3.isSelected(BytecodeViewer.viewer.panel3KrakatauBytecode.getModel())) passes = true; - if (krakatauTempJar != null || !passes) { - files[0] = krakatauTempJar; - files[1] = krakatauTempDir; + if (Configuration.krakatauTempJar != null || !passes) { + files[0] = Configuration.krakatauTempJar; + files[1] = Configuration.krakatauTempDir; return files; } } - - currentlyDumping = true; - needsReDump = false; - krakatauTempDir = new File(tempDirectory + fs + MiscUtils.randomString(32) + fs); - krakatauTempDir.mkdir(); - krakatauTempJar = new File(tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".jar"); + + Configuration.currentlyDumping = true; + Configuration.needsReDump = false; + Configuration.krakatauTempDir = new File(tempDirectory + fs + MiscUtils.randomString(32) + fs); + Configuration.krakatauTempDir.mkdir(); + Configuration.krakatauTempJar = new File(tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".jar"); //krakatauTempJar = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + "temp" + MiscUtils // .randomString(32) + ".jar."+container.name); - JarUtils.saveAsJarClassesOnly(container.classes, krakatauTempJar.getAbsolutePath()); - currentlyDumping = false; + JarUtils.saveAsJarClassesOnly(container.classes, Configuration.krakatauTempJar.getAbsolutePath()); + Configuration.currentlyDumping = false; - files[0] = krakatauTempJar; - files[1] = krakatauTempDir; + files[0] = Configuration.krakatauTempJar; + files[1] = Configuration.krakatauTempDir; return files; } public synchronized static void rtCheck() { - if (rt.equals("")) { + if (Configuration.rt.isEmpty()) { if (RT_JAR.exists()) { - rt = RT_JAR.getAbsolutePath(); + Configuration.rt = RT_JAR.getAbsolutePath(); } else if (RT_JAR_DUMPED.exists()) { - rt = RT_JAR_DUMPED.getAbsolutePath(); + Configuration.rt = RT_JAR_DUMPED.getAbsolutePath(); } else { try { JRTExtractor.extractRT(RT_JAR_DUMPED.getAbsolutePath()); - rt = RT_JAR_DUMPED.getAbsolutePath(); + Configuration.rt = RT_JAR_DUMPED.getAbsolutePath(); } catch (Throwable t) { t.printStackTrace(); } } } } - - public static int fileContainersHash(ArrayList fileContainers) { - StringBuilder block = new StringBuilder(); - for (FileContainer container : fileContainers) { - block.append(container.name); - for (ClassNode node : container.classes) { - block.append(node.name); - } - } - - return block.hashCode(); - } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java index 7aa5512d..136b3b1d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java @@ -327,7 +327,7 @@ public class CommandLineInput { System.out.println("Finished."); System.out.println("Bytecode Viewer CLI v" + VERSION + " by @Konloch - " + "https://bytecodeviewer.com"); - BytecodeViewer.canExit = true; + Configuration.canExit = true; System.exit(0); } catch (Exception e) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java new file mode 100644 index 00000000..47073a6c --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java @@ -0,0 +1,31 @@ +package the.bytecode.club.bytecodeviewer; + +import java.io.File; + +/** + * @author Konloch + * @since 6/21/2021 + */ +public class Configuration +{ + public static String python = ""; + public static String python3 = ""; + public static String rt = ""; + public static String library = ""; + public static String javac = ""; + public static String java = ""; + public static File krakatauTempDir; + public static File krakatauTempJar; + public static boolean displayParentInTab = false; //also change in the main GUI + public static boolean currentlyDumping = false; + public static boolean needsReDump = true; + public static boolean warnForEditing = false; + public static boolean runningObfuscation = false; + public static final long start = System.currentTimeMillis(); + public static String lastDirectory = "."; + public static boolean pingback = false; + public static boolean deleteForeignLibraries = true; + public static boolean canExit = false; + + public static long lastHotKeyExecuted = System.currentTimeMillis(); +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java index 056d7c6f..9eb4894f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java @@ -281,11 +281,11 @@ public class Settings { DiskWriter.writeNewLine(settingsName, "deprecated", false); DiskWriter.writeNewLine(settingsName, - BytecodeViewer.lastDirectory, false); + Configuration.lastDirectory, false); DiskWriter.writeNewLine(settingsName, - BytecodeViewer.python, false); + Configuration.python, false); DiskWriter.writeNewLine(settingsName, - BytecodeViewer.rt, false); + Configuration.rt, false); DiskWriter.writeNewLine(settingsName, String.valueOf(BytecodeViewer.viewer.panel1Proc_E.isSelected()), false); DiskWriter.writeNewLine(settingsName, @@ -319,9 +319,9 @@ public class Settings { DiskWriter.writeNewLine(settingsName, String.valueOf(BytecodeViewer.viewer.decodeAPKResources.isSelected()), false); DiskWriter.writeNewLine(settingsName, - BytecodeViewer.library, false); + Configuration.library, false); DiskWriter.writeNewLine(settingsName, - String.valueOf(BytecodeViewer.pingback), false); + String.valueOf(Configuration.pingback), false); DiskWriter.writeNewLine(settingsName, String.valueOf(BytecodeViewer.viewer.panel1JDGUI_E.isSelected()), false); DiskWriter.writeNewLine(settingsName, @@ -331,7 +331,7 @@ public class Settings { DiskWriter.writeNewLine(settingsName, String.valueOf(BytecodeViewer.viewer.fontSpinner.getValue()), false); DiskWriter.writeNewLine(settingsName, - String.valueOf(BytecodeViewer.deleteForeignLibraries), false); + String.valueOf(Configuration.deleteForeignLibraries), false); if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel())) DiskWriter.writeNewLine(settingsName, "0", false); @@ -339,17 +339,17 @@ public class Settings { DiskWriter.writeNewLine(settingsName, "1", false); DiskWriter.writeNewLine(settingsName, - BytecodeViewer.python3, false); + Configuration.python3, false); DiskWriter.writeNewLine(settingsName, - BytecodeViewer.javac, false); + Configuration.javac, false); DiskWriter.writeNewLine(settingsName, - BytecodeViewer.java, false); + Configuration.java, false); DiskWriter.writeNewLine(settingsName, String.valueOf(BytecodeViewer.viewer.compileOnSave.isSelected()), false); DiskWriter.writeNewLine(settingsName, String.valueOf(BytecodeViewer.viewer.autoCompileOnRefresh.isSelected()), false); DiskWriter.writeNewLine(settingsName, - String.valueOf(BytecodeViewer.warnForEditing), false); + String.valueOf(Configuration.warnForEditing), false); DiskWriter.writeNewLine(settingsName, String.valueOf(BytecodeViewer.viewer.showFileInTabTitle.isSelected()), false); DiskWriter.writeNewLine(settingsName, @@ -534,9 +534,9 @@ public class Settings { } //86 is deprecated //87 is deprecated - BytecodeViewer.lastDirectory = DiskReader.loadString(settingsName, 88, false); - BytecodeViewer.python = DiskReader.loadString(settingsName, 89, false); - BytecodeViewer.rt = DiskReader.loadString(settingsName, 90, false); + Configuration.lastDirectory = DiskReader.loadString(settingsName, 88, false); + Configuration.python = DiskReader.loadString(settingsName, 89, false); + Configuration.rt = DiskReader.loadString(settingsName, 90, false); BytecodeViewer.viewer.panel1Proc_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 91, false))); BytecodeViewer.viewer.panel1CFR_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 92, false))); BytecodeViewer.viewer.panel1Fern_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 93, false))); @@ -553,28 +553,28 @@ public class Settings { BytecodeViewer.viewer.panel3Krakatau_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 104, false))); BytecodeViewer.viewer.panel3Smali_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 105, false))); BytecodeViewer.viewer.decodeAPKResources.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 106, false))); - BytecodeViewer.library = DiskReader.loadString(settingsName, 107, false); - BytecodeViewer.pingback = Boolean.parseBoolean(DiskReader.loadString(settingsName, 108, false)); + Configuration.library = DiskReader.loadString(settingsName, 107, false); + Configuration.pingback = Boolean.parseBoolean(DiskReader.loadString(settingsName, 108, false)); BytecodeViewer.viewer.panel1JDGUI_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 109, false))); BytecodeViewer.viewer.panel2JDGUI_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 110, false))); BytecodeViewer.viewer.panel3JDGUI_E.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 111, false))); BytecodeViewer.viewer.fontSpinner.setValue(Integer.parseInt(DiskReader.loadString(settingsName, 112, false))); - BytecodeViewer.deleteForeignLibraries = Boolean.parseBoolean(DiskReader.loadString(settingsName, 113, false)); + Configuration.deleteForeignLibraries = Boolean.parseBoolean(DiskReader.loadString(settingsName, 113, false)); decompiler = Integer.parseInt(DiskReader.loadString(settingsName, 114, false)); if (decompiler == 0) BytecodeViewer.viewer.apkConversionGroup.setSelected(BytecodeViewer.viewer.apkConversionDex.getModel(), true); else if (decompiler == 1) BytecodeViewer.viewer.apkConversionGroup.setSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel(), true); - - BytecodeViewer.python3 = DiskReader.loadString(settingsName, 115, false); - BytecodeViewer.javac = DiskReader.loadString(settingsName, 116, false); - BytecodeViewer.java = DiskReader.loadString(settingsName, 117, false); + + Configuration.python3 = DiskReader.loadString(settingsName, 115, false); + Configuration.javac = DiskReader.loadString(settingsName, 116, false); + Configuration.java = DiskReader.loadString(settingsName, 117, false); BytecodeViewer.viewer.compileOnSave.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 118, false))); BytecodeViewer.viewer.autoCompileOnRefresh.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 119, false))); - BytecodeViewer.warnForEditing = Boolean.parseBoolean(DiskReader.loadString(settingsName, 120, false)); + Configuration.warnForEditing = Boolean.parseBoolean(DiskReader.loadString(settingsName, 120, false)); BytecodeViewer.viewer.showFileInTabTitle.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 121, false))); - BytecodeViewer.displayParentInTab = BytecodeViewer.viewer.showFileInTabTitle.isSelected(); + Configuration.displayParentInTab = BytecodeViewer.viewer.showFileInTabTitle.isSelected(); BytecodeViewer.viewer.forcePureAsciiAsText.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 122, false))); BytecodeViewer.viewer.synchronizedViewing.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 123, false))); BytecodeViewer.viewer.showClassMethods.setSelected(Boolean.parseBoolean(DiskReader.loadString(settingsName, 124, false))); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java index edca690e..de0f75c7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java @@ -7,6 +7,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import me.konloch.kontainer.io.DiskWriter; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -50,12 +51,12 @@ public class JavaCompiler extends Compiler { tempD.mkdirs(); new File(fileStart2).mkdirs(); - if (BytecodeViewer.javac.equals("") || !new File(BytecodeViewer.javac).exists()) { + 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.javac(); } - if (BytecodeViewer.javac.equals("") || !new File(BytecodeViewer.javac).exists()) { + if (Configuration.javac.isEmpty() || !new File(Configuration.javac).exists()) { BytecodeViewer.showMessage("You need to set Javac!"); return null; } @@ -69,19 +70,19 @@ public class JavaCompiler extends Compiler { StringBuilder log = new StringBuilder(); ProcessBuilder pb; - if (BytecodeViewer.library.isEmpty()) { + if (Configuration.library.isEmpty()) { pb = new ProcessBuilder( - BytecodeViewer.javac, + Configuration.javac, "-d", fileStart2, "-classpath", cp.getAbsolutePath(), java.getAbsolutePath() ); } else { pb = new ProcessBuilder( - BytecodeViewer.javac, + Configuration.javac, "-d", fileStart2, "-classpath", - cp.getAbsolutePath() + System.getProperty("path.separator") + BytecodeViewer.library, + cp.getAbsolutePath() + System.getProperty("path.separator") + Configuration.library, java.getAbsolutePath() ); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java index 294ddffd..759ed4db 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import me.konloch.kontainer.io.DiskWriter; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -39,12 +40,12 @@ public class KrakatauAssembler extends Compiler { @Override public byte[] compile(String contents, String name) { - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.pythonC(); } - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return null; } @@ -68,7 +69,7 @@ public class KrakatauAssembler extends Compiler { StringBuilder log = new StringBuilder(); try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python, + Configuration.python, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "assemble.py", "-out", diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java index e8f0a11d..4bdd5f2b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDecompiler.java @@ -9,6 +9,7 @@ import java.io.StringWriter; import me.konloch.kontainer.io.DiskReader; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -42,31 +43,31 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; public class KrakatauDecompiler extends Decompiler { public String quick() { - if (BytecodeViewer.library.isEmpty()) + if (Configuration.library.isEmpty()) return ""; else - return ";" + BytecodeViewer.library; + return ";" + Configuration.library; } public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) { - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.pythonC(); } BytecodeViewer.rtCheck(); - if (BytecodeViewer.rt.equals("")) { + 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.rtC(); } - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } - if (BytecodeViewer.rt.equals("")) { + if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage("You need to set RT.jar!"); return "Set your paths"; } @@ -77,13 +78,13 @@ public class KrakatauDecompiler extends Decompiler { BytecodeViewer.sm.stopBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python, + Configuration.python, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3 "-nauto", "-path", - BytecodeViewer.rt + ";" + krakatauTempJar.getAbsolutePath() + quick(), + Configuration.rt + ";" + krakatauTempJar.getAbsolutePath() + quick(), "-out", krakatauTempDir.getAbsolutePath(), cn.name + ".class" @@ -132,22 +133,22 @@ public class KrakatauDecompiler extends Decompiler { @Override public String decompileClassNode(ClassNode cn, byte[] b) { - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.pythonC(); } - if (BytecodeViewer.rt.equals("")) { - BytecodeViewer.showMessage("You need to set your JRE RT Library.\r\n(C:\\Program Files (x86)" - + "\\Java\\jre7\\lib\\rt.jar)"); + 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.rtC(); } - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } - if (BytecodeViewer.rt.equals("")) { + if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage("You need to set RT.jar!"); return "Set your paths"; } @@ -165,13 +166,13 @@ public class KrakatauDecompiler extends Decompiler { try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python, + Configuration.python, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3 "-nauto", "-path", - BytecodeViewer.rt + ";" + tempJar.getAbsolutePath() + quick(), + Configuration.rt + ";" + tempJar.getAbsolutePath() + quick(), "-out", tempDirectory.getAbsolutePath(), cn.name + ".class" @@ -223,14 +224,14 @@ public class KrakatauDecompiler extends Decompiler { @Override public void decompileToZip(String sourceJar, String zipName) { - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.pythonC(); } BytecodeViewer.rtCheck(); - if (BytecodeViewer.rt.equals("")) { - BytecodeViewer.showMessage("You need to set your JRE RT Library.\r\n(C:\\Program Files (x86)" - + "\\Java\\jre7\\lib\\rt.jar)"); + 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.rtC(); } @@ -245,13 +246,13 @@ public class KrakatauDecompiler extends Decompiler { try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python, + Configuration.python, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3 "-nauto", "-path", - BytecodeViewer.rt + ";" + tempJar.getAbsolutePath(), + Configuration.rt + ";" + tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), tempJar.getAbsolutePath() diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDisassembler.java index d5207d7e..ac2e6dba 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/KrakatauDisassembler.java @@ -9,6 +9,7 @@ import java.io.StringWriter; import me.konloch.kontainer.io.DiskReader; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -43,12 +44,12 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; public class KrakatauDisassembler extends Decompiler { public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) { - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.pythonC(); } - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } @@ -59,7 +60,7 @@ public class KrakatauDisassembler extends Decompiler { BytecodeViewer.sm.stopBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python, + Configuration.python, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "disassemble.py", "-path", @@ -112,12 +113,12 @@ public class KrakatauDisassembler extends Decompiler { @Override public String decompileClassNode(ClassNode cn, byte[] b) { - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.pythonC(); } - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return "Set your paths"; } @@ -133,7 +134,7 @@ public class KrakatauDisassembler extends Decompiler { BytecodeViewer.sm.stopBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python, + Configuration.python, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "disassemble.py", "-path", @@ -185,7 +186,7 @@ public class KrakatauDisassembler extends Decompiler { @Override public void decompileToZip(String sourceJar, String zipName) { - if (BytecodeViewer.python.equals("")) { + if (Configuration.python.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.pythonC(); } @@ -199,11 +200,11 @@ public class KrakatauDisassembler extends Decompiler { BytecodeViewer.sm.stopBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python, + Configuration.python, "-O", //love you storyyeller <3 krakatauWorkingDirectory + fs + "disassemble.py", "-path", - BytecodeViewer.rt + ";" + tempJar.getAbsolutePath(), + Configuration.rt + ";" + tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), tempJar.getAbsolutePath() diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java index 75c2f416..8aa3c3a0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java @@ -152,7 +152,7 @@ public class InstructionPrinter { line += "UNADDED OPCODE: " + nameOpcode(ain.getOpcode()) + " " + ain; } - if (!line.equals("")) { + if (!line.isEmpty()) { if (match) if (matchedInsns.contains(ain)) line = " -> " + line; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java index fb97a1e7..dd96fa0f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java @@ -10,7 +10,7 @@ import javax.swing.JTextArea; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Resources; -import static the.bytecode.club.bytecodeviewer.BytecodeViewer.*; +import static the.bytecode.club.bytecodeviewer.Configuration.*; import static the.bytecode.club.bytecodeviewer.Constants.*; /*************************************************************************** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/ClassViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/ClassViewer.java index 50efd288..d8d54d27 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/ClassViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/ClassViewer.java @@ -47,6 +47,7 @@ import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Type; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Resources; import the.bytecode.club.bytecodeviewer.Settings; import the.bytecode.club.bytecodeviewer.decompilers.Decompilers; @@ -1620,7 +1621,7 @@ public class ClassViewer extends Viewer { Thread t = new Thread(() -> { BytecodeViewer.viewer.setIcon(true); - while (BytecodeViewer.currentlyDumping) { + while (Configuration.currentlyDumping) { //wait until it's not dumping try { Thread.sleep(100); @@ -1642,8 +1643,8 @@ public class ClassViewer extends Viewer { t.start(); if (isPanel1Editable() || isPanel2Editable() || isPanel3Editable()) { - if (!BytecodeViewer.warnForEditing) { - BytecodeViewer.warnForEditing = true; + if (!Configuration.warnForEditing) { + Configuration.warnForEditing = true; if (!BytecodeViewer.viewer.autoCompileOnRefresh.isSelected() && !BytecodeViewer.viewer.compileOnSave.isSelected()) { BytecodeViewer.showMessage("Make sure to compile (File>Compile or Ctrl + T) whenever you want to " + "test or export your changes.\nYou can set compile automatically on refresh or on save " 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 f262fc61..b8a9ce7d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -35,6 +35,7 @@ import me.konloch.kontainer.io.DiskWriter; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Resources; import the.bytecode.club.bytecodeviewer.Settings; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; @@ -412,14 +413,13 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { public final JRadioButtonMenuItem asmText3 = new JRadioButtonMenuItem("ASM Textify"); public final JSpinner fontSpinner = new JSpinner(); - private final JCheckBoxMenuItem chckbxmntmDeleteForeignOutdatedLibs = new JCheckBoxMenuItem("Delete " - + "Foreign/Outdated Libs"); + private final JCheckBoxMenuItem chckbxmntmDeleteForeignOutdatedLibs = new JCheckBoxMenuItem("Delete Foreign/Outdated Libs"); public final ButtonGroup apkConversionGroup = new ButtonGroup(); public final JRadioButtonMenuItem apkConversionDex = new JRadioButtonMenuItem("Dex2Jar"); public final JRadioButtonMenuItem apkConversionEnjarify = new JRadioButtonMenuItem("Enjarify"); public void calledAfterLoad() { - chckbxmntmDeleteForeignOutdatedLibs.setSelected(BytecodeViewer.deleteForeignLibraries); + chckbxmntmDeleteForeignOutdatedLibs.setSelected(Configuration.deleteForeignLibraries); } public MainViewerGUI() { @@ -463,7 +463,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { - BytecodeViewer.canExit = true; + Configuration.canExit = true; System.exit(0); } }); @@ -483,7 +483,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { final JFileChooser fc = new JFileChooser(); try { - File f = new File(BytecodeViewer.lastDirectory); + File f = new File(Configuration.lastDirectory); if (f.exists()) fc.setSelectedFile(f); } catch (Exception ignored) { @@ -515,7 +515,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - BytecodeViewer.lastDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); try { BytecodeViewer.viewer.setIcon(true); BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true); @@ -1345,7 +1345,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { result = k; if (result == 0) { - BytecodeViewer.canExit = true; + Configuration.canExit = true; System.exit(0); } }); @@ -1410,22 +1410,21 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { panel1Fern.addActionListener(listener); mnFernflower.add(separator_20); - mnFernflower.add(panel1Fern_E); mnNewMenu_7.add(mnKrakatau); mnKrakatau.add(panel1Krakatau); + panel1Krakatau.addActionListener(listener); mnKrakatau.add(panel1KrakatauBytecode); panel1KrakatauBytecode.addActionListener(listener); mnKrakatau.add(separator_21); - mnKrakatau.add(panel1Krakatau_E); mnNewMenu_7.add(separator_8); - mnNewMenu_7.add(mnSmalidex); + mnSmalidex.add(panel1Smali); panel1Smali.addActionListener(listener); @@ -1435,35 +1434,25 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { panel1Bytecode.addActionListener(listener); mnNewMenu_7.add(separator_15); - mnNewMenu_7.add(panel1Bytecode); - mnNewMenu_7.add(panel1Hexcode); - mnNewMenu_7.add(asmText1); mnNewMenu_6.add(mnPane); mnPane.add(panel2None); - mnPane.add(separator_9); - mnPane.add(menu_1); menu_1.add(panel2Proc); - menu_1.add(separator_10); - menu_1.add(panel2Proc_E); mnPane.add(menu_2); - mnPane.add(jadx2); menu_2.add(panel2CFR); - menu_2.add(separator_11); - menu_2.add(panel2CFR_E); JMenu menu = new JMenu("JD-GUI"); @@ -1471,45 +1460,32 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { menu.add(panel2JDGUI); - JSeparator separator_34 = new JSeparator(); - menu.add(separator_34); - + menu.add(new JSeparator()); menu.add(panel2JDGUI_E); mnPane.add(menu_3); menu_3.add(panel2Fern); - menu_3.add(separator_12); - menu_3.add(panel2Fern_E); mnPane.add(menu_4); menu_4.add(panel2Krakatau); - menu_4.add(panel2KrakatauBytecode); - menu_4.add(separator_16); - menu_4.add(panel2Krakatau_E); - + mnPane.add(separator_17); - mnPane.add(menu_5); menu_5.add(panel2Smali); - menu_5.add(separator_23); - menu_5.add(panel2Smali_E); mnPane.add(separator_24); - mnPane.add(panel2Bytecode); - mnPane.add(panel2Hexcode); - mnPane.add(asmText2); mnNewMenu_6.add(mnPane_1); @@ -1622,7 +1598,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { BytecodeViewer.showMessage("WARNING: With this being toggled off outdated libraries will NOT be " + "removed. It's also a security issue. ONLY TURN IT OFF IF YOU KNOW WHAT YOU'RE DOING."); } - BytecodeViewer.deleteForeignLibraries = chckbxmntmDeleteForeignOutdatedLibs.isSelected(); + Configuration.deleteForeignLibraries = chckbxmntmDeleteForeignOutdatedLibs.isSelected(); }); mnSettings.add(forcePureAsciiAsText); forcePureAsciiAsText.setSelected(true); @@ -1874,9 +1850,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { menuBar.add(mnNewMenu_5); mntmNewMenuItem_6.addActionListener(arg0 -> { - if (BytecodeViewer.runningObfuscation) { - BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" - + "."); + if (Configuration.runningObfuscation) { + BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish."); return; } new RenameFields().start(); @@ -1895,7 +1870,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { mnNewMenu_5.add(mntmNewMenuItem_6); mntmNewMenuItem_7.addActionListener(arg0 -> { - if (BytecodeViewer.runningObfuscation) { + if (Configuration.runningObfuscation) { BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" + "."); return; @@ -1907,7 +1882,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { mnNewMenu_5.add(mntmNewMenuItem_7); mntmNewMenuItem_11.addActionListener(arg0 -> { - if (BytecodeViewer.runningObfuscation) { + if (Configuration.runningObfuscation) { BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" + "."); return; @@ -1919,10 +1894,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { mnNewMenu_5.add(mntmNewMenuItem_11); mntmNewMenuItem_9.setEnabled(false); - mnNewMenu_5.add(mntmNewMenuItem_9); mntmNewMenuItem_10.setEnabled(false); - mnNewMenu_5.add(mntmNewMenuItem_10); menuBar.add(mnNewMenu_1); @@ -1957,7 +1930,6 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { //mnNewMenu_1.add(mntmStartZkmString); mntmZstringarrayDecrypter.addActionListener(arg0 -> PluginManager.runPlugin(new ZStringArrayDecrypter())); - mntmStackFramesRemover.addActionListener(e -> PluginManager.runPlugin(new StackFramesRemover())); mnNewMenu_1.add(mntmZstringarrayDecrypter); @@ -1997,19 +1969,15 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { new MaliciousCodeScannerOptions().setVisible(true); }); mntmShowAllStrings.addActionListener(e -> PluginManager.runPlugin(new ShowAllStrings())); - mntmShowMainMethods.addActionListener(e -> PluginManager.runPlugin(new ShowMainMethods())); setSize(new Dimension(800, 400)); if (PREVIEW_COPY) - setTitle("Bytecode Viewer " + VERSION + " Preview - https://bytecodeviewer.com | " - + "https://the.bytecode.club - @Konloch"); + setTitle("Bytecode Viewer " + VERSION + " Preview - https://bytecodeviewer.com | https://the.bytecode.club - @Konloch"); else - setTitle("Bytecode Viewer " + VERSION + " - https://bytecodeviewer.com | https://the" - + ".bytecode.club - @Konloch"); + setTitle("Bytecode Viewer " + VERSION + " - https://bytecodeviewer.com | https://the.bytecode.club - @Konloch"); - getContentPane().setLayout( - new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); + getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); // scrollPane.setViewportView(tree); cn.setMinimumSize(new Dimension(200, 50)); @@ -2087,7 +2055,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { visualSettings.add(showFileInTabTitle); showFileInTabTitle.setSelected(false); showFileInTabTitle.addActionListener(arg0 -> { - BytecodeViewer.displayParentInTab = BytecodeViewer.viewer.showFileInTabTitle.isSelected(); + Configuration.displayParentInTab = BytecodeViewer.viewer.showFileInTabTitle.isSelected(); Settings.saveSettings(); }); @@ -2146,7 +2114,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { if (returnVal == JFileChooser.APPROVE_OPTION) try { - BytecodeViewer.python = fc.getSelectedFile().getAbsolutePath(); + Configuration.python = fc.getSelectedFile().getAbsolutePath(); } catch (Exception e1) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); } @@ -2171,7 +2139,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { if (returnVal == JFileChooser.APPROVE_OPTION) try { - BytecodeViewer.javac = fc.getSelectedFile().getAbsolutePath(); + Configuration.javac = fc.getSelectedFile().getAbsolutePath(); } catch (Exception e1) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); } @@ -2196,7 +2164,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { if (returnVal == JFileChooser.APPROVE_OPTION) try { - BytecodeViewer.java = fc.getSelectedFile().getAbsolutePath(); + Configuration.java = fc.getSelectedFile().getAbsolutePath(); } catch (Exception e1) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); } @@ -2221,7 +2189,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { if (returnVal == JFileChooser.APPROVE_OPTION) try { - BytecodeViewer.python3 = fc.getSelectedFile().getAbsolutePath(); + Configuration.python3 = fc.getSelectedFile().getAbsolutePath(); } catch (Exception e1) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); } @@ -2247,7 +2215,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { if (returnVal == JFileChooser.APPROVE_OPTION) try { - BytecodeViewer.library = fc.getSelectedFile().getAbsolutePath(); + Configuration.library = fc.getSelectedFile().getAbsolutePath(); } catch (Exception e1) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); } @@ -2273,7 +2241,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { if (returnVal == JFileChooser.APPROVE_OPTION) try { - BytecodeViewer.rt = fc.getSelectedFile().getAbsolutePath(); + Configuration.rt = fc.getSelectedFile().getAbsolutePath(); } catch (Exception e1) { new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/WorkPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/WorkPane.java index fcd8278b..6cc727fb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/WorkPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/WorkPane.java @@ -19,6 +19,7 @@ import javax.swing.JPopupMenu; import javax.swing.JTabbedPane; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.util.FileChangeNotifier; import the.bytecode.club.bytecodeviewer.util.FileContainer; @@ -204,7 +205,7 @@ public class WorkPane extends VisibleComponent implements ActionListener { String workingName = container.name + ">" + name; String containerName = name; - if (BytecodeViewer.displayParentInTab) + if (Configuration.displayParentInTab) containerName = container.name + ">" + name; if (!workingOn.containsKey(workingName)) { @@ -224,7 +225,7 @@ public class WorkPane extends VisibleComponent implements ActionListener { public void addFile(final FileContainer container, String name, byte[] contents) { String workingName = container.name + ">" + name; - if (BytecodeViewer.displayParentInTab) + if (Configuration.displayParentInTab) name = container.name + ">" + name; if (contents == null) //a directory diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java index a2b30c68..e31cba32 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java @@ -2,6 +2,7 @@ package the.bytecode.club.bytecodeviewer.obfuscators; import java.util.ArrayList; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.util.MiscUtils; /*************************************************************************** @@ -33,16 +34,15 @@ public abstract class JavaObfuscator extends Thread { @Override public void run() { BytecodeViewer.viewer.setIcon(true); - BytecodeViewer.runningObfuscation = true; + Configuration.runningObfuscation = true; obfuscate(); BytecodeViewer.refactorer.run(); - BytecodeViewer.runningObfuscation = false; + Configuration.runningObfuscation = false; BytecodeViewer.viewer.setIcon(false); } public int getStringLength() { - if (BytecodeViewer.viewer.obfuscatorGroup - .isSelected(BytecodeViewer.viewer.strongObf.getModel())) { + if (BytecodeViewer.viewer.obfuscatorGroup.isSelected(BytecodeViewer.viewer.strongObf.getModel())) { return MAX_STRING_LENGTH; } else { // if(BytecodeViewer.viewer.obfuscatorGroup.isSelected(BytecodeViewer.viewer.lightObf.getModel())) // { 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 d16cb111..f5e037af 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/Enjarify.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/Enjarify.java @@ -2,6 +2,7 @@ package the.bytecode.club.bytecodeviewer.util; import java.io.File; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import static the.bytecode.club.bytecodeviewer.Constants.enjarifyWorkingDirectory; @@ -38,12 +39,12 @@ public class Enjarify { * @param output the output .jar file */ public static synchronized void apk2Jar(File input, File output) { - if (BytecodeViewer.python3.equals("")) { + if (Configuration.python3.isEmpty()) { BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 3.x executable path."); BytecodeViewer.viewer.pythonC3(); } - if (BytecodeViewer.python3.equals("")) { + if (Configuration.python3.isEmpty()) { BytecodeViewer.showMessage("You need to set Python!"); return; } @@ -51,7 +52,7 @@ public class Enjarify { BytecodeViewer.sm.stopBlocking(); try { ProcessBuilder pb = new ProcessBuilder( - BytecodeViewer.python3, + Configuration.python3, "-O", "-m", "enjarify.main", diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java index b0c06651..2aa1c9d6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java @@ -1,5 +1,7 @@ package the.bytecode.club.bytecodeviewer.util; +import org.objectweb.asm.tree.ClassNode; + import java.io.BufferedReader; import java.io.File; import java.io.InputStream; @@ -158,6 +160,18 @@ public class MiscUtils { return path; } + public static int fileContainersHash(ArrayList fileContainers) { + StringBuilder block = new StringBuilder(); + for (FileContainer container : fileContainers) { + block.append(container.name); + for (ClassNode node : container.classes) { + block.append(node.name); + } + } + + return block.hashCode(); + } + /** * Converts an array list to a string * @@ -167,6 +181,7 @@ public class MiscUtils { public static String listToString(List a) { return gson.toJson(a); } + /** * @author JoshTheWolfe */ 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 22098594..5df1a659 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java @@ -1,6 +1,6 @@ package the.bytecode.club.bytecodeviewer.util; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import java.io.FileDescriptor; import java.net.InetAddress; @@ -126,7 +126,7 @@ public class SecurityMan extends SecurityManager { @Override public void checkExit(int status) { - if (!BytecodeViewer.canExit) { + if (!Configuration.canExit) { throw new SecurityException("BCV is awesome, blocking System.exit(" + status + ");"); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java index eeb57d5c..c1b206d8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java @@ -201,7 +201,7 @@ public final class ZipUtils { File folder = new File(srcFolder); for (String fileName : Objects.requireNonNull(folder.list())) { - if (path.equals("")) { + if (path.isEmpty()) { addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, ignore); } else { addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, ignore); @@ -213,7 +213,7 @@ public final class ZipUtils { File folder = new File(srcFolder); for (String fileName : Objects.requireNonNull(folder.list())) { - if (path.equals("")) { + if (path.isEmpty()) { addFileToZipAPKTool(folder.getName(), srcFolder + "/" + fileName, zip); } else { addFileToZipAPKTool(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);