Thread Cleanup
This commit is contained in:
parent
e2a8857499
commit
0a4f234841
3 changed files with 122 additions and 76 deletions
|
@ -1,11 +1,9 @@
|
||||||
package the.bytecode.club.bytecodeviewer;
|
package the.bytecode.club.bytecodeviewer;
|
||||||
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -13,7 +11,6 @@ import javax.swing.*;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import me.konloch.kontainer.io.HTTPRequest;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
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;
|
||||||
|
@ -128,46 +125,9 @@ public class BytecodeViewer
|
||||||
public static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
public static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
public static final boolean EXPERIMENTAL_TAB_CODE = false;
|
public static final boolean EXPERIMENTAL_TAB_CODE = false;
|
||||||
public static final boolean DEV_MODE = false; //if true error streams as preserved
|
public static final boolean DEV_MODE = false; //if true error streams as preserved
|
||||||
|
|
||||||
/**
|
|
||||||
* The version checker thread
|
|
||||||
*/
|
|
||||||
private static final Thread versionChecker = new Thread(new VersionChecker(), "Version Checker");
|
private static final Thread versionChecker = new Thread(new VersionChecker(), "Version Checker");
|
||||||
|
private static final Thread pingBack = new Thread(new PingBack(), "Pingback");
|
||||||
/**
|
private static final Thread installFatJar = new Thread(new InstallFatJar(), "Install Fat-Jar");
|
||||||
* Pings back to bytecodeviewer.com to be added into the total running statistics
|
|
||||||
*/
|
|
||||||
private static final Thread pingBack = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
new HTTPRequest(new URL("https://bytecodeviewer.com/add.php")).read();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Configuration.pingback = false;
|
|
||||||
}
|
|
||||||
}, "Pingback");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Downloads & installs the krakatau & enjarify zips
|
|
||||||
*/
|
|
||||||
private static final Thread installFatJar = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
if (OFFLINE_MODE) {
|
|
||||||
Boot.dropKrakatau();
|
|
||||||
Boot.dropEnjarify();
|
|
||||||
} else {
|
|
||||||
Boot.populateUrlList();
|
|
||||||
Boot.populateLibsDirectory();
|
|
||||||
Boot.downloadZipsOnly();
|
|
||||||
Boot.checkKrakatau();
|
|
||||||
Boot.checkEnjarify();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, "Install Fat-Jar");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to check incase booting failed for some reason, this kicks in as a fail safe
|
|
||||||
*/
|
|
||||||
private static final Thread bootCheck = new Thread(new BootCheck(), "Boot Check");
|
private static final Thread bootCheck = new Thread(new BootCheck(), "Boot Check");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,10 +138,15 @@ public class BytecodeViewer
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
BytecodeViewer.args = args;
|
BytecodeViewer.args = args;
|
||||||
|
|
||||||
|
//welcome message
|
||||||
System.out.println("https://the.bytecode.club - Created by @Konloch - Bytecode Viewer " + VERSION + ", " + "Fat-Jar: " + FAT_JAR);
|
System.out.println("https://the.bytecode.club - Created by @Konloch - Bytecode Viewer " + VERSION + ", " + "Fat-Jar: " + FAT_JAR);
|
||||||
|
|
||||||
|
//set the security manager
|
||||||
System.setSecurityManager(sm);
|
System.setSecurityManager(sm);
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//precache settings file
|
//precache settings file
|
||||||
SettingsSerializer.preloadSettingsFile();
|
SettingsSerializer.preloadSettingsFile();
|
||||||
//setup look and feel
|
//setup look and feel
|
||||||
|
@ -212,20 +177,25 @@ public class BytecodeViewer
|
||||||
if (CLI == CommandLineInput.STOP)
|
if (CLI == CommandLineInput.STOP)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!FAT_JAR) {
|
if (!FAT_JAR)
|
||||||
|
{
|
||||||
bootCheck.start();
|
bootCheck.start();
|
||||||
|
|
||||||
Boot.boot(args, CLI != CommandLineInput.OPEN_FILE);
|
Boot.boot(args, CLI != CommandLineInput.OPEN_FILE);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
installFatJar.start();
|
installFatJar.start();
|
||||||
|
|
||||||
if (CLI == CommandLineInput.OPEN_FILE)
|
if (CLI == CommandLineInput.OPEN_FILE)
|
||||||
BytecodeViewer.boot(false);
|
BytecodeViewer.boot(false);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
BytecodeViewer.boot(true);
|
BytecodeViewer.boot(true);
|
||||||
CommandLineInput.executeCommandLine(args);
|
CommandLineInput.executeCommandLine(args);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
|
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,37 +240,37 @@ public class BytecodeViewer
|
||||||
openFiles(new File[]{new File(s)}, true);
|
openFiles(new File[]{new File(s)}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* because Smali and Baksmali System.exit if it failed
|
|
||||||
*
|
|
||||||
* @param i
|
|
||||||
*/
|
|
||||||
public static void exit(int i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the java command it can use to launch the decompilers
|
* Returns the java command it can use to launch the decompilers
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static synchronized String getJavaCommand() {
|
public static synchronized String getJavaCommand()
|
||||||
try {
|
{
|
||||||
sm.stopBlocking();
|
sm.stopBlocking();
|
||||||
|
try
|
||||||
|
{
|
||||||
ProcessBuilder pb = new ProcessBuilder("java", "-version");
|
ProcessBuilder pb = new ProcessBuilder("java", "-version");
|
||||||
pb.start();
|
pb.start();
|
||||||
sm.setBlocking();
|
|
||||||
return "java"; //java is set
|
return "java"; //java is set
|
||||||
} catch (Exception e) { //ignore
|
}
|
||||||
|
catch (Exception e) //ignore
|
||||||
|
{
|
||||||
sm.setBlocking();
|
sm.setBlocking();
|
||||||
boolean empty = Configuration.java.isEmpty();
|
boolean empty = Configuration.java.isEmpty();
|
||||||
while (empty) {
|
while (empty)
|
||||||
showMessage("You need to set your Java path, this requires the JRE to be downloaded." + nl +
|
{
|
||||||
"(C:/Program Files/Java/JDK_xx/bin/java.exe)");
|
showMessage("You need to set your Java path, this requires the JRE to be downloaded." +
|
||||||
|
nl + "(C:/Program Files/Java/JDK_xx/bin/java.exe)");
|
||||||
viewer.selectJava();
|
viewer.selectJava();
|
||||||
empty = Configuration.java.isEmpty();
|
empty = Configuration.java.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
sm.setBlocking();
|
||||||
|
}
|
||||||
|
|
||||||
return Configuration.java;
|
return Configuration.java;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +289,8 @@ public class BytecodeViewer
|
||||||
* @param name the class name
|
* @param name the class name
|
||||||
* @return the ClassNode instance
|
* @return the ClassNode instance
|
||||||
*/
|
*/
|
||||||
public static ClassNode getClassNode(String name) {
|
public static ClassNode getClassNode(String name)
|
||||||
|
{
|
||||||
for (FileContainer container : files)
|
for (FileContainer container : files)
|
||||||
for (ClassNode c : container.classes)
|
for (ClassNode c : container.classes)
|
||||||
if (c.name.equals(name))
|
if (c.name.equals(name))
|
||||||
|
@ -328,7 +299,8 @@ public class BytecodeViewer
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileContainer getFileContainer(String name) {
|
public static FileContainer getFileContainer(String name)
|
||||||
|
{
|
||||||
for (FileContainer container : files)
|
for (FileContainer container : files)
|
||||||
if (container.name.equals(name))
|
if (container.name.equals(name))
|
||||||
return container;
|
return container;
|
||||||
|
@ -340,7 +312,8 @@ public class BytecodeViewer
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClassNode getClassNode(FileContainer container, String name) {
|
public static ClassNode getClassNode(FileContainer container, String name)
|
||||||
|
{
|
||||||
for (ClassNode c : container.classes)
|
for (ClassNode c : container.classes)
|
||||||
if (c.name.equals(name))
|
if (c.name.equals(name))
|
||||||
return c;
|
return c;
|
||||||
|
@ -549,6 +522,18 @@ public class BytecodeViewer
|
||||||
{
|
{
|
||||||
viewer.clearBusyStatus();
|
viewer.clearBusyStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes the title on all of the opened tabs
|
||||||
|
*/
|
||||||
|
public static void refreshAllTabTitles()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++)
|
||||||
|
{
|
||||||
|
ResourceViewer viewer = ((TabbedPane) BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i)).resource;
|
||||||
|
viewer.refreshTitle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the workspace with optional user input required
|
* Resets the workspace with optional user input required
|
||||||
|
@ -596,14 +581,9 @@ public class BytecodeViewer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refreshes the title on all of the opened tabs
|
* because Smali and Baksmali System.exit if it failed
|
||||||
|
*
|
||||||
|
* @param i
|
||||||
*/
|
*/
|
||||||
public static void refreshAllTabTitles()
|
public static void exit(int i) { }
|
||||||
{
|
|
||||||
for(int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++)
|
|
||||||
{
|
|
||||||
ResourceViewer viewer = ((TabbedPane) BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i)).resource;
|
|
||||||
viewer.refreshTitle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package the.bytecode.club.bytecodeviewer.util;
|
||||||
|
|
||||||
|
import the.bytecode.club.bootloader.Boot;
|
||||||
|
|
||||||
|
import static the.bytecode.club.bytecodeviewer.Constants.OFFLINE_MODE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads & installs the krakatau & enjarify zips
|
||||||
|
*
|
||||||
|
* Alternatively if OFFLINE_MODE is enabled it will drop the Krakatau and Enjarify versions supplied with BCV
|
||||||
|
*
|
||||||
|
* @author Konloch
|
||||||
|
* @since 7/6/2021
|
||||||
|
*/
|
||||||
|
public class InstallFatJar implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (OFFLINE_MODE)
|
||||||
|
{
|
||||||
|
Boot.dropKrakatau();
|
||||||
|
Boot.dropEnjarify();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Boot.populateUrlList();
|
||||||
|
Boot.populateLibsDirectory();
|
||||||
|
Boot.downloadZipsOnly();
|
||||||
|
Boot.checkKrakatau();
|
||||||
|
Boot.checkEnjarify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package the.bytecode.club.bytecodeviewer.util;
|
||||||
|
|
||||||
|
import me.konloch.kontainer.io.HTTPRequest;
|
||||||
|
import the.bytecode.club.bytecodeviewer.Configuration;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pings back to bytecodeviewer.com to be added into the total running statistics
|
||||||
|
*
|
||||||
|
* @author Konloch
|
||||||
|
* @since May 1, 2015
|
||||||
|
*/
|
||||||
|
public class PingBack implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
new HTTPRequest(new URL("https://bytecodeviewer.com/add.php")).read();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Configuration.pingback = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue