diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 461a5211..9739ff58 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -18,24 +18,18 @@ import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bootloader.Boot; import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader; -import the.bytecode.club.bytecodeviewer.compilers.Compiler; import the.bytecode.club.bytecodeviewer.gui.components.*; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane; import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; -import the.bytecode.club.bytecodeviewer.gui.resourcesearch.SearchBoxPane; -import the.bytecode.club.bytecodeviewer.gui.resourceviewer.WorkPaneMainComponent; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.util.*; import the.bytecode.club.bytecodeviewer.resources.importing.ImportResource; -import static javax.swing.JOptionPane.INFORMATION_MESSAGE; import static the.bytecode.club.bytecodeviewer.Constants.*; import static the.bytecode.club.bytecodeviewer.Settings.addRecentPlugin; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentTypes.JAVA; import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentTypes.JAVA_AND_BYTECODE; import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; @@ -440,7 +434,7 @@ public class BytecodeViewer * @return true if no errors, false if it failed to compile. */ public static boolean compile(boolean message, boolean successAlert) { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); boolean noErrors = true; boolean actuallyTried = false; @@ -479,7 +473,7 @@ public class BytecodeViewer } } - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); return true; } @@ -499,7 +493,7 @@ public class BytecodeViewer SettingsSerializer.saveSettingsAsync(); } - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Configuration.needsReDump = true; Thread t = new Thread(new ImportResource(files), "Import Resource"); t.start(); @@ -534,13 +528,29 @@ public class BytecodeViewer public static void showMessage(String message) { BetterJOptionPane.showMessageDialog(viewer, message); } + + /** + * Alerts the user the program is running something in the background + */ + public static void updateBusyStatus(boolean busyStatus) + { + viewer.updateBusyStatus(busyStatus); + } + + /** + * Clears all active busy status icons + */ + public static void clearBusyStatus() + { + viewer.clearBusyStatus(); + } /** * Resets the workspace with optional user input required * * @param ask if should require user input or not */ - public static void resetWorkSpace(boolean ask) + public static void resetWorkspace(boolean ask) { if (ask) { @@ -548,17 +558,12 @@ public class BytecodeViewer "Are you sure you want to reset the workspace?" + "\n\rIt will also reset your file navigator and search.", new String[]{"Yes", "No"}); - + if (dialogue.promptChoice() != 0) return; } - - files.clear(); - LazyNameUtil.reset(); - Objects.requireNonNull(MainViewerGUI.getComponent(ResourceListPane.class)).resetWorkspace(); - Objects.requireNonNull(MainViewerGUI.getComponent(WorkPaneMainComponent.class)).resetWorkspace(); - Objects.requireNonNull(MainViewerGUI.getComponent(SearchBoxPane.class)).resetWorkspace(); - the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().clear(); + + BCVResourceUtils.resetWorkspace(); } /** @@ -579,8 +584,7 @@ public class BytecodeViewer try { FileUtils.deleteDirectory(tempF); - } catch (Exception ignored) { - } + } catch (Exception ignored) { } while (!tempF.exists()) // keep making dirs tempF.mkdir(); @@ -615,12 +619,12 @@ public class BytecodeViewer if(file == null) return; - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); BytecodeViewer.openFiles(new File[]{file}, true); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { Configuration.lastHotKeyExecuted = System.currentTimeMillis(); - BytecodeViewer.resetWorkSpace(true); + BytecodeViewer.resetWorkspace(true); } else if ((e.getKeyCode() == KeyEvent.VK_T) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { Configuration.lastHotKeyExecuted = System.currentTimeMillis(); Thread t = new Thread(() -> BytecodeViewer.compile(true, false), "Compile"); @@ -664,11 +668,11 @@ public class BytecodeViewer final File file2 = file; - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Thread jarExport = new Thread(() -> { JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file2.getAbsolutePath()); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); }, "Jar Export"); jarExport.start(); } @@ -682,73 +686,4 @@ public class BytecodeViewer viewer.workPane.tabs.remove(viewer.workPane.getCurrentViewer()); } } - - public static File[] dumpTempFile(FileContainer container) - { - 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 (Configuration.krakatauTempJar != null && !Configuration.krakatauTempJar.exists()) { - Configuration.needsReDump = true; - } - - if (Configuration.needsReDump && Configuration.krakatauTempJar != null) { - Configuration.krakatauTempDir = null; - Configuration.krakatauTempJar = null; - } - - boolean passes = false; - - if (BytecodeViewer.viewer.viewPane1.getGroup().isSelected(BytecodeViewer.viewer.viewPane1.getKrakatau().getJava().getModel())) - passes = true; - else if (BytecodeViewer.viewer.viewPane1.getGroup().isSelected(BytecodeViewer.viewer.viewPane1.getKrakatau().getBytecode().getModel())) - passes = true; - else if (BytecodeViewer.viewer.viewPane2.getGroup().isSelected(BytecodeViewer.viewer.viewPane2.getKrakatau().getJava().getModel())) - passes = true; - else if (BytecodeViewer.viewer.viewPane2.getGroup().isSelected(BytecodeViewer.viewer.viewPane2.getKrakatau().getBytecode().getModel())) - passes = true; - else if (BytecodeViewer.viewer.viewPane3.getGroup().isSelected(BytecodeViewer.viewer.viewPane3.getKrakatau().getJava().getModel())) - passes = true; - else if (BytecodeViewer.viewer.viewPane3.getGroup().isSelected(BytecodeViewer.viewer.viewPane3.getKrakatau().getBytecode().getModel())) - passes = true; - - if (Configuration.krakatauTempJar != null || !passes) { - files[0] = Configuration.krakatauTempJar; - files[1] = Configuration.krakatauTempDir; - return files; - } - } - - 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, Configuration.krakatauTempJar.getAbsolutePath()); - Configuration.currentlyDumping = false; - - files[0] = Configuration.krakatauTempJar; - files[1] = Configuration.krakatauTempDir; - return files; - } - - 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/api/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java index 3ab4d66a..0815675c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java @@ -201,7 +201,7 @@ public class BytecodeViewer { * @param ask if it should ask the user about resetting the workspace */ public static void resetWorkSpace(boolean ask) { - the.bytecode.club.bytecodeviewer.BytecodeViewer.resetWorkSpace(ask); + the.bytecode.club.bytecodeviewer.BytecodeViewer.resetWorkspace(ask); } /** @@ -211,7 +211,7 @@ public class BytecodeViewer { * @param busy if it should display the busy icon or not */ public static void setBusy(boolean busy) { - the.bytecode.club.bytecodeviewer.BytecodeViewer.viewer.updateBusyStatus(busy); + the.bytecode.club.bytecodeviewer.BytecodeViewer.updateBusyStatus(busy); } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java index 136c853e..9280841d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java @@ -33,7 +33,7 @@ public abstract class Plugin extends Thread @Override public void run() { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); try { @@ -48,7 +48,7 @@ public abstract class Plugin extends Thread new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); } finally { finished = true; - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } } 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 0ad1b44c..278030d7 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 @@ -14,6 +14,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.util.BCVResourceUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.ZipUtils; @@ -70,7 +71,7 @@ public class KrakatauDecompiler extends InternalDecompiler BytecodeViewer.viewer.selectPythonC(); } - BytecodeViewer.rtCheck(); + BCVResourceUtils.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)"); @@ -243,7 +244,8 @@ public class KrakatauDecompiler extends InternalDecompiler BytecodeViewer.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path."); BytecodeViewer.viewer.selectPythonC(); } - BytecodeViewer.rtCheck(); + + BCVResourceUtils.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)"); 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 e6c2595b..88d0b250 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -332,7 +332,7 @@ public class MainViewerGUI extends JFrame saveAsZip.setActionCommand(""); addResource.addActionListener(e -> selectFile()); - newWorkSpace.addActionListener(e -> BytecodeViewer.resetWorkSpace(true)); + newWorkSpace.addActionListener(e -> BytecodeViewer.resetWorkspace(true)); reloadResources.addActionListener(arg0 -> reloadResources()); runButton.addActionListener(e -> runResources()); compileButton.addActionListener(arg0 -> compileOnNewThread()); @@ -840,9 +840,9 @@ public class MainViewerGUI extends JFrame if(file == null) return; - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); BytecodeViewer.openFiles(new File[]{file}, true); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } public void selectPythonC() @@ -932,9 +932,9 @@ public class MainViewerGUI extends JFrame if(file == null) return; - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); BytecodeViewer.startPlugin(file); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); SettingsSerializer.saveSettingsAsync(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java index f1c93255..efae12f0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java @@ -60,11 +60,11 @@ public class ExportJar extends JFrame btnNewButton.addActionListener(arg0 -> { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Thread t = new Thread(() -> { JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath, manifest.getText()); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); }, "Jar Export"); t.start(); dispose(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewProcessing.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewProcessing.java index bb53e896..f164f47d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewProcessing.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewProcessing.java @@ -62,7 +62,7 @@ public class ResourceViewProcessing extends PaneUpdaterThread { try { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); if (resourceViewPanel.decompiler != Decompiler.NONE) { @@ -138,7 +138,7 @@ public class ResourceViewProcessing extends PaneUpdaterThread finally { viewer.resetDivider(); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); SwingUtilities.invokeLater(() -> { if (button != null) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneRefresh.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneRefresh.java index fa519067..378709b1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneRefresh.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneRefresh.java @@ -35,13 +35,13 @@ public class WorkPaneRefresh implements Runnable if(tabComp == null) return; - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); if (tabComp instanceof ClassViewer) ((ClassViewer) tabComp).startPaneUpdater(src); else if (tabComp instanceof FileViewer) ((FileViewer) tabComp).refresh(src); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java index ca334129..22d9149f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java @@ -26,6 +26,7 @@ import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.SettingsSerializer; +import the.bytecode.club.bytecodeviewer.util.BCVResourceUtils; import the.bytecode.club.bytecodeviewer.util.FileContainer; import the.bytecode.club.bytecodeviewer.util.MethodParser; @@ -155,7 +156,8 @@ public class ClassViewer extends ResourceViewer Thread t = new Thread(() -> { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); + while (Configuration.currentlyDumping) { //wait until it's not dumping @@ -165,9 +167,10 @@ public class ClassViewer extends ResourceViewer e.printStackTrace(); } } - tempFiles = BytecodeViewer.dumpTempFile(container); + + tempFiles = BCVResourceUtils.dumpTempFile(container); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); if (resourceViewPanel1.decompiler != Decompiler.NONE) resourceViewPanel1.updateThread.startNewThread(); 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 5e6797ad..99c51f21 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java @@ -33,12 +33,12 @@ public abstract class JavaObfuscator extends Thread { @Override public void run() { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Configuration.runningObfuscation = true; obfuscate(); BytecodeViewer.refactorer.run(); Configuration.runningObfuscation = false; - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } public int getStringLength() { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/EZInjection.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/EZInjection.java index df167bca..d4262ccf 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/EZInjection.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/EZInjection.java @@ -143,7 +143,7 @@ public class EZInjection extends Plugin { @Override public void execute(ArrayList classNodeList) { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); gui.setText(""); if (console) @@ -315,6 +315,6 @@ public class EZInjection extends Plugin { } } - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java index b5466107..25652356 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java @@ -8,6 +8,7 @@ import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; import the.bytecode.club.bytecodeviewer.util.DialogueUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -72,7 +73,7 @@ public class ResourceDecompiling if (options[k].equals(obj)) result = k; - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); File tempZip = new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar"); if (tempZip.exists()) @@ -85,7 +86,7 @@ public class ResourceDecompiling try { Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), MiscUtils.append(javaSucks, "-proycon.zip")); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -93,10 +94,10 @@ public class ResourceDecompiling t12.start(); Thread t2 = new Thread(() -> { try { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), MiscUtils.append(javaSucks, "-CFR.zip")); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -104,10 +105,10 @@ public class ResourceDecompiling t2.start(); Thread t3 = new Thread(() -> { try { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), MiscUtils.append(javaSucks, "-fernflower.zip")); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -115,10 +116,10 @@ public class ResourceDecompiling t3.start(); Thread t4 = new Thread(() -> { try { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), MiscUtils.append(javaSucks, "-kraktau.zip")); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -129,7 +130,7 @@ public class ResourceDecompiling Thread t12 = new Thread(() -> { try { Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -140,7 +141,7 @@ public class ResourceDecompiling Thread t12 = new Thread(() -> { try { Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -151,7 +152,7 @@ public class ResourceDecompiling Thread t12 = new Thread(() -> { try { Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -163,7 +164,7 @@ public class ResourceDecompiling Thread t12 = new Thread(() -> { try { Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { new ExceptionUI(e); } @@ -172,7 +173,7 @@ public class ResourceDecompiling } if (result == 5) { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } } }, "Decompile Thread"); @@ -181,12 +182,20 @@ public class ResourceDecompiling public static void decompileSaveOpenedOnly() { - if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null) { + if (BytecodeViewer.getLoadedClasses().isEmpty()) + { BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); return; } - Thread decompileThread = new Thread(() -> { + if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) + { + BytecodeViewer.showMessage("First open a class file."); + return; + } + + Thread decompileThread = new Thread(() -> + { if (BytecodeViewer.autoCompileSuccessful()) return; @@ -195,7 +204,6 @@ public class ResourceDecompiling if (s == null) return; - JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), "Select Java Files", "Java Source Files", @@ -207,8 +215,8 @@ public class ResourceDecompiling Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); File file = fc.getSelectedFile(); - BytecodeViewer.viewer.updateBusyStatus(true); - final String path = MiscUtils.append(file, ".java"); // cheap hax because string is final + BytecodeViewer.updateBusyStatus(true); + final String path = MiscUtils.append(file, ".java"); if (!DialogueUtils.canOverwriteFile(path)) return; @@ -271,9 +279,9 @@ public class ResourceDecompiling e.printStackTrace(); } - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); new ExceptionUI(e); } }); @@ -296,9 +304,9 @@ public class ResourceDecompiling } String contents = Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); DiskWriter.replaceFile(path, contents, false); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); new ExceptionUI( e); } @@ -322,9 +330,9 @@ public class ResourceDecompiling } String contents = Decompiler.CFR_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); DiskWriter.replaceFile(path, contents, false); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); new ExceptionUI( e); } @@ -350,9 +358,9 @@ public class ResourceDecompiling String contents = Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); DiskWriter.replaceFile(path, contents, false); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); new ExceptionUI( e); } @@ -378,9 +386,9 @@ public class ResourceDecompiling String contents = Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); DiskWriter.replaceFile(path, contents, false); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } catch (Exception e) { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); new ExceptionUI( e); } @@ -388,7 +396,7 @@ public class ResourceDecompiling t1.start(); } if (result == 5) { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } } }, "Decompile Thread"); 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 d29bc3f4..66b26e7e 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 @@ -92,14 +92,14 @@ public class APKExport implements Exporter Thread saveThread = new Thread(() -> { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar"; JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input); Thread buildAPKThread = new Thread(() -> { APKTool.buildAPK(new File(input), file2, finalContainer); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); }, "Process APK"); buildAPKThread.start(); }, "Jar Export"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java index 500eaacd..b74e3a10 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java @@ -58,7 +58,7 @@ public class DexExport implements Exporter Thread saveAsJar = new Thread(() -> { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar"; JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input); @@ -66,7 +66,7 @@ public class DexExport implements Exporter { Dex2Jar.saveAsDex(new File(input), outputPath); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); }, "Process DEX"); saveAsDex.start(); }, "Jar Export"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java index 9397a4e4..b71e3586 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java @@ -50,11 +50,11 @@ public class ZipExport implements Exporter final File file2 = file; - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); Thread saveThread = new Thread(() -> { JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file2.getAbsolutePath()); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); }, "Jar Export"); saveThread.start(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java index 22544256..3329f07c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java @@ -99,7 +99,7 @@ public class ImportResource implements Runnable } finally { - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); if (update) try { 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 324ae5ef..8edee3cc 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,7 +22,7 @@ public class APKResourceImporter implements Importer public boolean open(File file) throws Exception { try { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk"); @@ -50,7 +50,7 @@ public class APKResourceImporter implements Importer container.classes = JarUtils.loadClasses(output); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); BytecodeViewer.files.add(container); } catch (final Exception e) { new ExceptionUI(e); 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 d14be645..492357b7 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,7 +21,7 @@ public class DEXResourceImporter implements Importer public boolean open(File file) throws Exception { try { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".dex"); @@ -39,7 +39,7 @@ public class DEXResourceImporter implements Importer container.classes = JarUtils.loadClasses(output); - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); BytecodeViewer.files.add(container); } catch (final Exception e) { new ExceptionUI(e); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/searching/BackgroundSearchThread.java b/src/main/java/the/bytecode/club/bytecodeviewer/searching/BackgroundSearchThread.java index dd5850d4..55523703 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/searching/BackgroundSearchThread.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/searching/BackgroundSearchThread.java @@ -41,9 +41,9 @@ public abstract class BackgroundSearchThread extends Thread @Override public void run() { - BytecodeViewer.viewer.updateBusyStatus(true); + BytecodeViewer.updateBusyStatus(true); search(); finished = true; - BytecodeViewer.viewer.updateBusyStatus(false); + BytecodeViewer.updateBusyStatus(false); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVResourceUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVResourceUtils.java new file mode 100644 index 00000000..50f2f823 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/BCVResourceUtils.java @@ -0,0 +1,104 @@ +package the.bytecode.club.bytecodeviewer.util; + +import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; +import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue; + +import java.io.File; + +import static the.bytecode.club.bytecodeviewer.Constants.*; +import static the.bytecode.club.bytecodeviewer.Constants.RT_JAR_DUMPED; + +/** + * @author Konloch + * @since 7/6/2021 + */ +public class BCVResourceUtils +{ + public static void resetWorkspace() + { + BytecodeViewer.files.clear(); + LazyNameUtil.reset(); + BytecodeViewer.viewer.resourcePane.resetWorkspace(); + BytecodeViewer.viewer.workPane.resetWorkspace(); + BytecodeViewer.viewer.searchBoxPane.resetWorkspace(); + the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().clear(); + } + + /** + * Dumps the loaded classes as a library to be used for Krakatau + */ + public static File[] dumpTempFile(FileContainer container) + { + 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 (Configuration.krakatauTempJar != null && !Configuration.krakatauTempJar.exists()) + Configuration.needsReDump = true; + + if (Configuration.needsReDump && Configuration.krakatauTempJar != null) + { + Configuration.krakatauTempDir = null; + Configuration.krakatauTempJar = null; + } + + boolean passes = false; + + if (BytecodeViewer.viewer.viewPane1.getGroup().isSelected(BytecodeViewer.viewer.viewPane1.getKrakatau().getJava().getModel())) + passes = true; + else if (BytecodeViewer.viewer.viewPane1.getGroup().isSelected(BytecodeViewer.viewer.viewPane1.getKrakatau().getBytecode().getModel())) + passes = true; + + else if (BytecodeViewer.viewer.viewPane2.getGroup().isSelected(BytecodeViewer.viewer.viewPane2.getKrakatau().getJava().getModel())) + passes = true; + else if (BytecodeViewer.viewer.viewPane2.getGroup().isSelected(BytecodeViewer.viewer.viewPane2.getKrakatau().getBytecode().getModel())) + passes = true; + + else if (BytecodeViewer.viewer.viewPane3.getGroup().isSelected(BytecodeViewer.viewer.viewPane3.getKrakatau().getJava().getModel())) + passes = true; + else if (BytecodeViewer.viewer.viewPane3.getGroup().isSelected(BytecodeViewer.viewer.viewPane3.getKrakatau().getBytecode().getModel())) + passes = true; + + if (Configuration.krakatauTempJar != null || !passes) + { + files[0] = Configuration.krakatauTempJar; + files[1] = Configuration.krakatauTempDir; + return files; + } + } + + 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, Configuration.krakatauTempJar.getAbsolutePath()); + Configuration.currentlyDumping = false; + + files[0] = Configuration.krakatauTempJar; + files[1] = Configuration.krakatauTempDir; + return files; + } + + //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(); + } + } + } +}