Cleaning up the main BytecodeViewer class file
This commit is contained in:
parent
21f8bf8382
commit
cb1c27f46c
7 changed files with 45 additions and 46 deletions
|
@ -115,6 +115,8 @@ public class BytecodeViewer
|
||||||
public static boolean deleteForeignLibraries = true;
|
public static boolean deleteForeignLibraries = true;
|
||||||
public static boolean canExit = false;
|
public static boolean canExit = false;
|
||||||
|
|
||||||
|
private static long last = System.currentTimeMillis();
|
||||||
|
|
||||||
|
|
||||||
public static boolean verify = false; //eventually may be a setting
|
public static boolean verify = false; //eventually may be a setting
|
||||||
public static String[] args;
|
public static String[] args;
|
||||||
|
@ -605,7 +607,7 @@ public class BytecodeViewer
|
||||||
recentFiles.remove(maxRecentFiles - 1); // zero indexing
|
recentFiles.remove(maxRecentFiles - 1); // zero indexing
|
||||||
|
|
||||||
recentFiles.add(0, f.getAbsolutePath());
|
recentFiles.add(0, f.getAbsolutePath());
|
||||||
DiskWriter.replaceFile(filesName, quickConvert(recentFiles), false);
|
DiskWriter.replaceFile(filesName, MiscUtils.listToString(recentFiles), false);
|
||||||
resetRecentFilesMenu();
|
resetRecentFilesMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +636,7 @@ public class BytecodeViewer
|
||||||
recentPlugins.remove(maxRecentFiles - 1); // zero indexing
|
recentPlugins.remove(maxRecentFiles - 1); // zero indexing
|
||||||
|
|
||||||
recentPlugins.add(0, f.getAbsolutePath());
|
recentPlugins.add(0, f.getAbsolutePath());
|
||||||
DiskWriter.replaceFile(pluginsName, quickConvert(recentPlugins), false);
|
DiskWriter.replaceFile(pluginsName, MiscUtils.listToString(recentPlugins), false);
|
||||||
resetRecentFilesMenu();
|
resetRecentFilesMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,39 +681,6 @@ public class BytecodeViewer
|
||||||
tempF.mkdir();
|
tempF.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> createdRandomizedNames = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensures it will only return a uniquely generated names, contains a dupe checker to be sure
|
|
||||||
*
|
|
||||||
* @return the unique randomized name of 25 characters.
|
|
||||||
*/
|
|
||||||
public static String getRandomizedName() {
|
|
||||||
boolean generated = false;
|
|
||||||
String name = "";
|
|
||||||
while (!generated) {
|
|
||||||
String randomizedName = MiscUtils.randomString(25);
|
|
||||||
if (!createdRandomizedNames.contains(randomizedName)) {
|
|
||||||
createdRandomizedNames.add(randomizedName);
|
|
||||||
name = randomizedName;
|
|
||||||
generated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts an array list to a string
|
|
||||||
*
|
|
||||||
* @param a array
|
|
||||||
* @return string with newline per array object
|
|
||||||
*/
|
|
||||||
private static String quickConvert(List<String> a) {
|
|
||||||
return gson.toJson(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long last = System.currentTimeMillis();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the hotkeys
|
* Checks the hotkeys
|
||||||
*
|
*
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import the.bytecode.club.bytecodeviewer.decompilers.Decompilers;
|
import the.bytecode.club.bytecodeviewer.decompilers.Decompilers;
|
||||||
import the.bytecode.club.bytecodeviewer.util.JarUtils;
|
import the.bytecode.club.bytecodeviewer.util.JarUtils;
|
||||||
|
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
|
||||||
|
|
||||||
import static the.bytecode.club.bytecodeviewer.Constants.*;
|
import static the.bytecode.club.bytecodeviewer.Constants.*;
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ public class CommandLineInput {
|
||||||
//if its just class allow any
|
//if its just class allow any
|
||||||
|
|
||||||
File tempZip =
|
File tempZip =
|
||||||
new File(tempDirectory + fs + "temp_" + BytecodeViewer.getRandomizedName() + ".jar");
|
new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar");
|
||||||
if (tempZip.exists())
|
if (tempZip.exists())
|
||||||
tempZip.delete();
|
tempZip.delete();
|
||||||
|
|
||||||
|
|
|
@ -770,7 +770,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
||||||
|
|
||||||
Thread t16 = new Thread(() -> {
|
Thread t16 = new Thread(() -> {
|
||||||
BytecodeViewer.viewer.setIcon(true);
|
BytecodeViewer.viewer.setIcon(true);
|
||||||
final String input = tempDirectory + fs + BytecodeViewer.getRandomizedName() + ".jar";
|
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
|
||||||
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
|
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
|
||||||
|
|
||||||
Thread t15 = new Thread(() -> {
|
Thread t15 = new Thread(() -> {
|
||||||
|
@ -880,7 +880,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
||||||
|
|
||||||
Thread t14 = new Thread(() -> {
|
Thread t14 = new Thread(() -> {
|
||||||
BytecodeViewer.viewer.setIcon(true);
|
BytecodeViewer.viewer.setIcon(true);
|
||||||
final String input = tempDirectory + fs + BytecodeViewer.getRandomizedName() + ".jar";
|
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
|
||||||
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
|
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
|
||||||
|
|
||||||
Thread t13 = new Thread(() -> {
|
Thread t13 = new Thread(() -> {
|
||||||
|
@ -969,7 +969,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
||||||
|
|
||||||
BytecodeViewer.viewer.setIcon(true);
|
BytecodeViewer.viewer.setIcon(true);
|
||||||
|
|
||||||
File tempZip = new File(tempDirectory + fs + "temp_" + BytecodeViewer.getRandomizedName() + ".jar");
|
File tempZip = new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar");
|
||||||
if (tempZip.exists())
|
if (tempZip.exists())
|
||||||
tempZip.delete();
|
tempZip.delete();
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class APKTool {
|
||||||
|
|
||||||
public static synchronized void buildAPK(File input, File output, FileContainer container) {
|
public static synchronized void buildAPK(File input, File output, FileContainer container) {
|
||||||
String temp = tempDirectory + fs;
|
String temp = tempDirectory + fs;
|
||||||
File tempDir = new File(temp + fs + BytecodeViewer.getRandomizedName() + fs);
|
File tempDir = new File(temp + fs + MiscUtils.getRandomizedName() + fs);
|
||||||
tempDir.mkdirs();
|
tempDir.mkdirs();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@ import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.Random;
|
|
||||||
|
import static the.bytecode.club.bytecodeviewer.Constants.gson;
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
||||||
|
@ -36,6 +37,7 @@ public class MiscUtils {
|
||||||
private static final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
private static final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
private static final String AN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
private static final String AN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
private static final Random rnd = new Random();
|
private static final Random rnd = new Random();
|
||||||
|
private static HashSet<String> createdRandomizedNames = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random string without numbers
|
* Returns a random string without numbers
|
||||||
|
@ -49,6 +51,25 @@ public class MiscUtils {
|
||||||
sb.append(AB.charAt(rnd.nextInt(AB.length())));
|
sb.append(AB.charAt(rnd.nextInt(AB.length())));
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures it will only return a uniquely generated names, contains a dupe checker to be sure
|
||||||
|
*
|
||||||
|
* @return the unique randomized name of 25 characters.
|
||||||
|
*/
|
||||||
|
public static String getRandomizedName() {
|
||||||
|
boolean generated = false;
|
||||||
|
String name = "";
|
||||||
|
while (!generated) {
|
||||||
|
String randomizedName = MiscUtils.randomString(25);
|
||||||
|
if (!createdRandomizedNames.contains(randomizedName)) {
|
||||||
|
createdRandomizedNames.add(randomizedName);
|
||||||
|
name = randomizedName;
|
||||||
|
generated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public static void printProcess(Process process) throws Exception {
|
public static void printProcess(Process process) throws Exception {
|
||||||
//Read out dir output
|
//Read out dir output
|
||||||
|
@ -136,7 +157,16 @@ public class MiscUtils {
|
||||||
path = path + extension;
|
path = path + extension;
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an array list to a string
|
||||||
|
*
|
||||||
|
* @param a array
|
||||||
|
* @return string with newline per array object
|
||||||
|
*/
|
||||||
|
public static String listToString(List<String> a) {
|
||||||
|
return gson.toJson(a);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @author JoshTheWolfe
|
* @author JoshTheWolfe
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -149,7 +149,7 @@ public class OpenFile implements Runnable
|
||||||
Objects.requireNonNull(container.files).putAll(JarUtils.loadResources(tempCopy)); //copy and rename
|
Objects.requireNonNull(container.files).putAll(JarUtils.loadResources(tempCopy)); //copy and rename
|
||||||
// to prevent unicode filenames
|
// to prevent unicode filenames
|
||||||
|
|
||||||
String name = BytecodeViewer.getRandomizedName() + ".jar";
|
String name = MiscUtils.getRandomizedName() + ".jar";
|
||||||
File output = new File(tempDirectory + fs + name);
|
File output = new File(tempDirectory + fs + name);
|
||||||
|
|
||||||
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
|
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
|
||||||
|
@ -176,7 +176,7 @@ public class OpenFile implements Runnable
|
||||||
|
|
||||||
FileContainer container = new FileContainer(tempCopy, f.getName());
|
FileContainer container = new FileContainer(tempCopy, f.getName());
|
||||||
|
|
||||||
String name = BytecodeViewer.getRandomizedName() + ".jar";
|
String name = MiscUtils.getRandomizedName() + ".jar";
|
||||||
File output = new File(tempDirectory + fs + name);
|
File output = new File(tempDirectory + fs + name);
|
||||||
|
|
||||||
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
|
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
|
||||||
|
|
|
@ -50,7 +50,6 @@ public class VersionChecker implements Runnable
|
||||||
try {
|
try {
|
||||||
int simplemaths = Integer.parseInt(version.replace(".", ""));
|
int simplemaths = Integer.parseInt(version.replace(".", ""));
|
||||||
int simplemaths2 = Integer.parseInt(localVersion.replace(".", ""));
|
int simplemaths2 = Integer.parseInt(localVersion.replace(".", ""));
|
||||||
System.out.println("DEBUG: " + simplemaths + " vs " + simplemaths2);
|
|
||||||
if (simplemaths2 > simplemaths)
|
if (simplemaths2 > simplemaths)
|
||||||
return; //developer version
|
return; //developer version
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
|
Loading…
Reference in a new issue