Busy Status Cleanup

This commit is contained in:
Konloch 2021-07-06 15:57:42 -07:00
parent 9e5b4527ed
commit b99f6bf98a
20 changed files with 212 additions and 160 deletions

View file

@ -18,24 +18,18 @@ import org.apache.commons.io.FileUtils;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bootloader.Boot; import the.bytecode.club.bootloader.Boot;
import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader; 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.components.*;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; 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.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.gui.resourceviewer.viewer.ResourceViewer;
import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer; import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer;
import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
import the.bytecode.club.bytecodeviewer.util.*; import the.bytecode.club.bytecodeviewer.util.*;
import the.bytecode.club.bytecodeviewer.resources.importing.ImportResource; 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.Constants.*;
import static the.bytecode.club.bytecodeviewer.Settings.addRecentPlugin; 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.gui.components.DecompilerViewComponent.DecompilerComponentTypes.JAVA_AND_BYTECODE;
import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; 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. * @return true if no errors, false if it failed to compile.
*/ */
public static boolean compile(boolean message, boolean successAlert) { public static boolean compile(boolean message, boolean successAlert) {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
boolean noErrors = true; boolean noErrors = true;
boolean actuallyTried = false; boolean actuallyTried = false;
@ -479,7 +473,7 @@ public class BytecodeViewer
} }
} }
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
return true; return true;
} }
@ -499,7 +493,7 @@ public class BytecodeViewer
SettingsSerializer.saveSettingsAsync(); SettingsSerializer.saveSettingsAsync();
} }
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Configuration.needsReDump = true; Configuration.needsReDump = true;
Thread t = new Thread(new ImportResource(files), "Import Resource"); Thread t = new Thread(new ImportResource(files), "Import Resource");
t.start(); t.start();
@ -535,12 +529,28 @@ public class BytecodeViewer
BetterJOptionPane.showMessageDialog(viewer, 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 * Resets the workspace with optional user input required
* *
* @param ask if should require user input or not * @param ask if should require user input or not
*/ */
public static void resetWorkSpace(boolean ask) public static void resetWorkspace(boolean ask)
{ {
if (ask) if (ask)
{ {
@ -553,12 +563,7 @@ public class BytecodeViewer
return; return;
} }
files.clear(); BCVResourceUtils.resetWorkspace();
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();
} }
/** /**
@ -579,8 +584,7 @@ public class BytecodeViewer
try { try {
FileUtils.deleteDirectory(tempF); FileUtils.deleteDirectory(tempF);
} catch (Exception ignored) { } catch (Exception ignored) { }
}
while (!tempF.exists()) // keep making dirs while (!tempF.exists()) // keep making dirs
tempF.mkdir(); tempF.mkdir();
@ -615,12 +619,12 @@ public class BytecodeViewer
if(file == null) if(file == null)
return; return;
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
BytecodeViewer.openFiles(new File[]{file}, 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)) { } else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
Configuration.lastHotKeyExecuted = System.currentTimeMillis(); Configuration.lastHotKeyExecuted = System.currentTimeMillis();
BytecodeViewer.resetWorkSpace(true); BytecodeViewer.resetWorkspace(true);
} else if ((e.getKeyCode() == KeyEvent.VK_T) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { } else if ((e.getKeyCode() == KeyEvent.VK_T) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
Configuration.lastHotKeyExecuted = System.currentTimeMillis(); Configuration.lastHotKeyExecuted = System.currentTimeMillis();
Thread t = new Thread(() -> BytecodeViewer.compile(true, false), "Compile"); Thread t = new Thread(() -> BytecodeViewer.compile(true, false), "Compile");
@ -664,11 +668,11 @@ public class BytecodeViewer
final File file2 = file; final File file2 = file;
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Thread jarExport = new Thread(() -> { Thread jarExport = new Thread(() -> {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(),
file2.getAbsolutePath()); file2.getAbsolutePath());
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Jar Export"); }, "Jar Export");
jarExport.start(); jarExport.start();
} }
@ -682,73 +686,4 @@ public class BytecodeViewer
viewer.workPane.tabs.remove(viewer.workPane.getCurrentViewer()); 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();
}
}
}
}
} }

View file

@ -201,7 +201,7 @@ public class BytecodeViewer {
* @param ask if it should ask the user about resetting the workspace * @param ask if it should ask the user about resetting the workspace
*/ */
public static void resetWorkSpace(boolean ask) { 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 * @param busy if it should display the busy icon or not
*/ */
public static void setBusy(boolean busy) { public static void setBusy(boolean busy) {
the.bytecode.club.bytecodeviewer.BytecodeViewer.viewer.updateBusyStatus(busy); the.bytecode.club.bytecodeviewer.BytecodeViewer.updateBusyStatus(busy);
} }
/** /**

View file

@ -33,7 +33,7 @@ public abstract class Plugin extends Thread
@Override @Override
public void run() public void run()
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
try try
{ {
@ -48,7 +48,7 @@ public abstract class Plugin extends Thread
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} finally { } finally {
finished = true; finished = true;
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
} }

View file

@ -14,6 +14,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.decompilers.InternalDecompiler; 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.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.ZipUtils; import the.bytecode.club.bytecodeviewer.util.ZipUtils;
@ -70,7 +71,7 @@ public class KrakatauDecompiler extends InternalDecompiler
BytecodeViewer.viewer.selectPythonC(); BytecodeViewer.viewer.selectPythonC();
} }
BytecodeViewer.rtCheck(); BCVResourceUtils.rtCheck();
if (Configuration.rt.isEmpty()) { if (Configuration.rt.isEmpty()) {
BytecodeViewer.showMessage("You need to set your JRE RT Library.\r\n(C:\\Program Files (x86)" BytecodeViewer.showMessage("You need to set your JRE RT Library.\r\n(C:\\Program Files (x86)"
+ "\\Java\\jre7\\lib\\rt.jar)"); + "\\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.showMessage("You need to set your Python (or PyPy for speed) 2.7 executable path.");
BytecodeViewer.viewer.selectPythonC(); BytecodeViewer.viewer.selectPythonC();
} }
BytecodeViewer.rtCheck();
BCVResourceUtils.rtCheck();
if (Configuration.rt.isEmpty()) { if (Configuration.rt.isEmpty()) {
BytecodeViewer.showMessage("You need to set your JRE RT Library." + BytecodeViewer.showMessage("You need to set your JRE RT Library." +
"\r\n(C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar)"); "\r\n(C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar)");

View file

@ -332,7 +332,7 @@ public class MainViewerGUI extends JFrame
saveAsZip.setActionCommand(""); saveAsZip.setActionCommand("");
addResource.addActionListener(e -> selectFile()); addResource.addActionListener(e -> selectFile());
newWorkSpace.addActionListener(e -> BytecodeViewer.resetWorkSpace(true)); newWorkSpace.addActionListener(e -> BytecodeViewer.resetWorkspace(true));
reloadResources.addActionListener(arg0 -> reloadResources()); reloadResources.addActionListener(arg0 -> reloadResources());
runButton.addActionListener(e -> runResources()); runButton.addActionListener(e -> runResources());
compileButton.addActionListener(arg0 -> compileOnNewThread()); compileButton.addActionListener(arg0 -> compileOnNewThread());
@ -840,9 +840,9 @@ public class MainViewerGUI extends JFrame
if(file == null) if(file == null)
return; return;
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
BytecodeViewer.openFiles(new File[]{file}, true); BytecodeViewer.openFiles(new File[]{file}, true);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
public void selectPythonC() public void selectPythonC()
@ -932,9 +932,9 @@ public class MainViewerGUI extends JFrame
if(file == null) if(file == null)
return; return;
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
BytecodeViewer.startPlugin(file); BytecodeViewer.startPlugin(file);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
SettingsSerializer.saveSettingsAsync(); SettingsSerializer.saveSettingsAsync();
} }

View file

@ -60,11 +60,11 @@ public class ExportJar extends JFrame
btnNewButton.addActionListener(arg0 -> btnNewButton.addActionListener(arg0 ->
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Thread t = new Thread(() -> Thread t = new Thread(() ->
{ {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath, manifest.getText()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath, manifest.getText());
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Jar Export"); }, "Jar Export");
t.start(); t.start();
dispose(); dispose();

View file

@ -62,7 +62,7 @@ public class ResourceViewProcessing extends PaneUpdaterThread
{ {
try try
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
if (resourceViewPanel.decompiler != Decompiler.NONE) if (resourceViewPanel.decompiler != Decompiler.NONE)
{ {
@ -138,7 +138,7 @@ public class ResourceViewProcessing extends PaneUpdaterThread
finally finally
{ {
viewer.resetDivider(); viewer.resetDivider();
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
SwingUtilities.invokeLater(() -> SwingUtilities.invokeLater(() ->
{ {
if (button != null) if (button != null)

View file

@ -35,13 +35,13 @@ public class WorkPaneRefresh implements Runnable
if(tabComp == null) if(tabComp == null)
return; return;
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
if (tabComp instanceof ClassViewer) if (tabComp instanceof ClassViewer)
((ClassViewer) tabComp).startPaneUpdater(src); ((ClassViewer) tabComp).startPaneUpdater(src);
else if (tabComp instanceof FileViewer) else if (tabComp instanceof FileViewer)
((FileViewer) tabComp).refresh(src); ((FileViewer) tabComp).refresh(src);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
} }

View file

@ -26,6 +26,7 @@ import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.SettingsSerializer; 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.FileContainer;
import the.bytecode.club.bytecodeviewer.util.MethodParser; import the.bytecode.club.bytecodeviewer.util.MethodParser;
@ -155,7 +156,8 @@ public class ClassViewer extends ResourceViewer
Thread t = new Thread(() -> Thread t = new Thread(() ->
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
while (Configuration.currentlyDumping) while (Configuration.currentlyDumping)
{ {
//wait until it's not dumping //wait until it's not dumping
@ -165,9 +167,10 @@ public class ClassViewer extends ResourceViewer
e.printStackTrace(); e.printStackTrace();
} }
} }
tempFiles = BytecodeViewer.dumpTempFile(container);
BytecodeViewer.viewer.updateBusyStatus(false); tempFiles = BCVResourceUtils.dumpTempFile(container);
BytecodeViewer.updateBusyStatus(false);
if (resourceViewPanel1.decompiler != Decompiler.NONE) if (resourceViewPanel1.decompiler != Decompiler.NONE)
resourceViewPanel1.updateThread.startNewThread(); resourceViewPanel1.updateThread.startNewThread();

View file

@ -33,12 +33,12 @@ public abstract class JavaObfuscator extends Thread {
@Override @Override
public void run() { public void run() {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Configuration.runningObfuscation = true; Configuration.runningObfuscation = true;
obfuscate(); obfuscate();
BytecodeViewer.refactorer.run(); BytecodeViewer.refactorer.run();
Configuration.runningObfuscation = false; Configuration.runningObfuscation = false;
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
public int getStringLength() { public int getStringLength() {

View file

@ -143,7 +143,7 @@ public class EZInjection extends Plugin {
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) public void execute(ArrayList<ClassNode> classNodeList)
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
gui.setText(""); gui.setText("");
if (console) if (console)
@ -315,6 +315,6 @@ public class EZInjection extends Plugin {
} }
} }
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
} }

View file

@ -8,6 +8,7 @@ import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; 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.DialogueUtils;
import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils;
@ -72,7 +73,7 @@ public class ResourceDecompiling
if (options[k].equals(obj)) if (options[k].equals(obj))
result = k; result = k;
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
File tempZip = new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar"); File tempZip = new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar");
if (tempZip.exists()) if (tempZip.exists())
@ -85,7 +86,7 @@ public class ResourceDecompiling
try { try {
Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
MiscUtils.append(javaSucks, "-proycon.zip")); MiscUtils.append(javaSucks, "-proycon.zip"));
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -93,10 +94,10 @@ public class ResourceDecompiling
t12.start(); t12.start();
Thread t2 = new Thread(() -> { Thread t2 = new Thread(() -> {
try { try {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
MiscUtils.append(javaSucks, "-CFR.zip")); MiscUtils.append(javaSucks, "-CFR.zip"));
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -104,10 +105,10 @@ public class ResourceDecompiling
t2.start(); t2.start();
Thread t3 = new Thread(() -> { Thread t3 = new Thread(() -> {
try { try {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
MiscUtils.append(javaSucks, "-fernflower.zip")); MiscUtils.append(javaSucks, "-fernflower.zip"));
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -115,10 +116,10 @@ public class ResourceDecompiling
t3.start(); t3.start();
Thread t4 = new Thread(() -> { Thread t4 = new Thread(() -> {
try { try {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
MiscUtils.append(javaSucks, "-kraktau.zip")); MiscUtils.append(javaSucks, "-kraktau.zip"));
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -129,7 +130,7 @@ public class ResourceDecompiling
Thread t12 = new Thread(() -> { Thread t12 = new Thread(() -> {
try { try {
Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -140,7 +141,7 @@ public class ResourceDecompiling
Thread t12 = new Thread(() -> { Thread t12 = new Thread(() -> {
try { try {
Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -151,7 +152,7 @@ public class ResourceDecompiling
Thread t12 = new Thread(() -> { Thread t12 = new Thread(() -> {
try { try {
Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -163,7 +164,7 @@ public class ResourceDecompiling
Thread t12 = new Thread(() -> { Thread t12 = new Thread(() -> {
try { try {
Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path); Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
new ExceptionUI(e); new ExceptionUI(e);
} }
@ -172,7 +173,7 @@ public class ResourceDecompiling
} }
if (result == 5) { if (result == 5) {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
} }
}, "Decompile Thread"); }, "Decompile Thread");
@ -181,12 +182,20 @@ public class ResourceDecompiling
public static void decompileSaveOpenedOnly() 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."); BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return; 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()) if (BytecodeViewer.autoCompileSuccessful())
return; return;
@ -195,7 +204,6 @@ public class ResourceDecompiling
if (s == null) if (s == null)
return; return;
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(), JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
"Select Java Files", "Select Java Files",
"Java Source Files", "Java Source Files",
@ -207,8 +215,8 @@ public class ResourceDecompiling
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile(); File file = fc.getSelectedFile();
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
final String path = MiscUtils.append(file, ".java"); // cheap hax because string is final final String path = MiscUtils.append(file, ".java");
if (!DialogueUtils.canOverwriteFile(path)) if (!DialogueUtils.canOverwriteFile(path))
return; return;
@ -271,9 +279,9 @@ public class ResourceDecompiling
e.printStackTrace(); e.printStackTrace();
} }
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
new ExceptionUI(e); new ExceptionUI(e);
} }
}); });
@ -296,9 +304,9 @@ public class ResourceDecompiling
} }
String contents = Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); String contents = Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(path, contents, false); DiskWriter.replaceFile(path, contents, false);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
new ExceptionUI( new ExceptionUI(
e); e);
} }
@ -322,9 +330,9 @@ public class ResourceDecompiling
} }
String contents = Decompiler.CFR_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); String contents = Decompiler.CFR_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
DiskWriter.replaceFile(path, contents, false); DiskWriter.replaceFile(path, contents, false);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
new ExceptionUI( new ExceptionUI(
e); e);
} }
@ -350,9 +358,9 @@ public class ResourceDecompiling
String contents = Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileClassNode(cn, String contents = Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileClassNode(cn,
cw.toByteArray()); cw.toByteArray());
DiskWriter.replaceFile(path, contents, false); DiskWriter.replaceFile(path, contents, false);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
new ExceptionUI( new ExceptionUI(
e); e);
} }
@ -378,9 +386,9 @@ public class ResourceDecompiling
String contents = Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileClassNode(cn, String contents = Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileClassNode(cn,
cw.toByteArray()); cw.toByteArray());
DiskWriter.replaceFile(path, contents, false); DiskWriter.replaceFile(path, contents, false);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} catch (Exception e) { } catch (Exception e) {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
new ExceptionUI( new ExceptionUI(
e); e);
} }
@ -388,7 +396,7 @@ public class ResourceDecompiling
t1.start(); t1.start();
} }
if (result == 5) { if (result == 5) {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
} }
}, "Decompile Thread"); }, "Decompile Thread");

View file

@ -92,14 +92,14 @@ public class APKExport implements Exporter
Thread saveThread = new Thread(() -> Thread saveThread = new Thread(() ->
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar"; final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread buildAPKThread = new Thread(() -> Thread buildAPKThread = new Thread(() ->
{ {
APKTool.buildAPK(new File(input), file2, finalContainer); APKTool.buildAPK(new File(input), file2, finalContainer);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Process APK"); }, "Process APK");
buildAPKThread.start(); buildAPKThread.start();
}, "Jar Export"); }, "Jar Export");

View file

@ -58,7 +58,7 @@ public class DexExport implements Exporter
Thread saveAsJar = new Thread(() -> Thread saveAsJar = new Thread(() ->
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar"; final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
@ -66,7 +66,7 @@ public class DexExport implements Exporter
{ {
Dex2Jar.saveAsDex(new File(input), outputPath); Dex2Jar.saveAsDex(new File(input), outputPath);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Process DEX"); }, "Process DEX");
saveAsDex.start(); saveAsDex.start();
}, "Jar Export"); }, "Jar Export");

View file

@ -50,11 +50,11 @@ public class ZipExport implements Exporter
final File file2 = file; final File file2 = file;
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Thread saveThread = new Thread(() -> Thread saveThread = new Thread(() ->
{ {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file2.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file2.getAbsolutePath());
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Jar Export"); }, "Jar Export");
saveThread.start(); saveThread.start();
} }

View file

@ -99,7 +99,7 @@ public class ImportResource implements Runnable
} }
finally finally
{ {
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
if (update) if (update)
try { try {

View file

@ -22,7 +22,7 @@ public class APKResourceImporter implements Importer
public boolean open(File file) throws Exception public boolean open(File file) throws Exception
{ {
try { try {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk"); File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk");
@ -50,7 +50,7 @@ public class APKResourceImporter implements Importer
container.classes = JarUtils.loadClasses(output); container.classes = JarUtils.loadClasses(output);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
BytecodeViewer.files.add(container); BytecodeViewer.files.add(container);
} catch (final Exception e) { } catch (final Exception e) {
new ExceptionUI(e); new ExceptionUI(e);

View file

@ -21,7 +21,7 @@ public class DEXResourceImporter implements Importer
public boolean open(File file) throws Exception public boolean open(File file) throws Exception
{ {
try { try {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".dex"); File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".dex");
@ -39,7 +39,7 @@ public class DEXResourceImporter implements Importer
container.classes = JarUtils.loadClasses(output); container.classes = JarUtils.loadClasses(output);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
BytecodeViewer.files.add(container); BytecodeViewer.files.add(container);
} catch (final Exception e) { } catch (final Exception e) {
new ExceptionUI(e); new ExceptionUI(e);

View file

@ -41,9 +41,9 @@ public abstract class BackgroundSearchThread extends Thread
@Override @Override
public void run() public void run()
{ {
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
search(); search();
finished = true; finished = true;
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
} }
} }

View file

@ -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();
}
}
}
}