Code Style Update

This commit is contained in:
Konloch 2024-09-25 23:39:22 -06:00
parent fda1ecab66
commit 0e7bd2bba1

AI 샘플 코드 생성 중입니다

Loading...
78 changed files with 708 additions and 569 deletions

View File

@ -7,7 +7,7 @@ import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialog
import java.lang.reflect.Field
import static the.bytecode.club.bytecodeviewer.Constants.nl
import static the.bytecode.club.bytecodeviewer.Constants.NL
/**
** This is an example of a String Decrypter Groovy Plugin for BCV.
@ -22,7 +22,7 @@ class ExampleStringDecrypter extends Plugin {
MultipleChoiceDialog dialog = new MultipleChoiceDialog("Bytecode Viewer - WARNING",
"WARNING: This will load the classes into the JVM and execute the initialize function"
+ nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.",
+ NL + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.",
new String[]{"Continue", "Cancel"})
if (dialog.promptChoice() == 0) {

View File

@ -141,13 +141,13 @@ public class BytecodeViewer
public static Refactorer refactorer = new Refactorer();
//GSON Reference
public static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
public static Gson gson = new GsonBuilder().setPrettyPrinting().create();
//Threads
private static final Thread versionChecker = new Thread(new UpdateCheck(), "Version Checker");
private static final Thread pingBack = new Thread(new PingBack(), "Pingback");
private static final Thread installFatJar = new Thread(new InstallFatJar(), "Install Fat-Jar");
private static final Thread bootCheck = new Thread(new BootCheck(), "Boot Check");
private static final Thread VERSION_CHECKER = new Thread(new UpdateCheck(), "Version Checker");
private static final Thread PING_BACK = new Thread(new PingBack(), "Pingback");
private static final Thread INSTALL_FAT_JAR = new Thread(new InstallFatJar(), "Install Fat-Jar");
private static final Thread BOOT_CHECK = new Thread(new BootCheck(), "Boot Check");
/**
* Main startup
@ -202,23 +202,23 @@ public class BytecodeViewer
MiscUtils.setLanguage(MiscUtils.guessLanguage());
//handle CLI
int CLI = CommandLineInput.parseCommandLine(args);
if (CLI == CommandLineInput.STOP)
int isCLI = CommandLineInput.parseCommandLine(args);
if (isCLI == CommandLineInput.STOP)
return;
//load with shaded libraries
if (FAT_JAR)
{
installFatJar.start();
INSTALL_FAT_JAR.start();
}
else //load through bootloader
{
bootCheck.start();
Boot.boot(args, CLI != CommandLineInput.GUI);
BOOT_CHECK.start();
Boot.boot(args, isCLI != CommandLineInput.GUI);
}
//CLI arguments say spawn the GUI
if (CLI == CommandLineInput.GUI)
if (isCLI == CommandLineInput.GUI)
{
BytecodeViewer.boot(false);
Configuration.bootState = BootState.GUI_SHOWING;
@ -264,20 +264,20 @@ public class BytecodeViewer
//ping back once on first boot to add to global user count
if (!Configuration.pingback)
{
pingBack.start();
PING_BACK.start();
Configuration.pingback = true;
}
//version checking
if (viewer.updateCheck.isSelected() && !DEV_MODE)
versionChecker.start();
VERSION_CHECKER.start();
//show the main UI
if (!cli)
viewer.setVisible(true);
//print startup time
System.out.println("Start up took " + ((System.currentTimeMillis() - Configuration.start) / 1000) + " seconds");
System.out.println("Start up took " + ((System.currentTimeMillis() - Configuration.BOOT_TIMESTAMP) / 1000) + " seconds");
//request focus on GUI for hotkeys on start
if (!cli)
@ -677,11 +677,13 @@ public class BytecodeViewer
new Thread(() ->
{
updateBusyStatus(true);
for (int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++)
{
ResourceViewer viewer = (ResourceViewer) BytecodeViewer.viewer.workPane.tabs.getComponentAt(i);
viewer.refresh(null);
}
updateBusyStatus(false);
}, "Refresh All Tabs").start();
}
@ -695,7 +697,8 @@ public class BytecodeViewer
{
if (ask)
{
MultipleChoiceDialog dialog = new MultipleChoiceDialog(TranslatedStrings.RESET_TITLE.toString(), TranslatedStrings.RESET_CONFIRM.toString(), new String[]{TranslatedStrings.YES.toString(), TranslatedStrings.NO.toString()});
MultipleChoiceDialog dialog = new MultipleChoiceDialog(TranslatedStrings.RESET_TITLE.toString(), TranslatedStrings.RESET_CONFIRM.toString(),
new String[]{TranslatedStrings.YES.toString(), TranslatedStrings.NO.toString()});
if (dialog.promptChoice() != 0)
return;
@ -732,7 +735,7 @@ public class BytecodeViewer
*/
public static void cleanup()
{
File tempF = new File(tempDirectory);
File tempF = new File(TEMP_DIRECTORY);
try
{
@ -767,6 +770,7 @@ public class BytecodeViewer
{
Object key = enumeration.nextElement();
Object value = UIManager.get(key);
if (value instanceof Font)
UIManager.put(key, font);
}

View File

@ -43,23 +43,23 @@ import static the.bytecode.club.bytecodeviewer.Constants.*;
public class CommandLineInput
{
private static final Options options = new Options();
private static final CommandLineParser parser = new DefaultParser();
private static final Options OPTIONS = new Options();
private static final CommandLineParser PARSER = new DefaultParser();
/*BECAUSE WHO DOESN'T LOVE MAGIC NUMBERS*/
public static int STOP = -1;
public static int GUI = 0;
public static int CLI = 1;
public static final int STOP = -1;
public static final int GUI = 0;
public static final int CLI = 1;
static
{
options.addOption("help", false, "prints the help menu.");
options.addOption("list", false, "lists all the available decompilers for BCV " + VERSION + ".");
options.addOption("decompiler", true, "sets the decompiler, procyon by default.");
options.addOption("i", true, "sets the input.");
options.addOption("o", true, "sets the output.");
options.addOption("t", true, "sets the target class to decompile, append all to decomp all as zip.");
options.addOption("nowait", true, "won't wait the 5 seconds to allow the user to read the CLI.");
OPTIONS.addOption("help", false, "prints the help menu.");
OPTIONS.addOption("list", false, "lists all the available decompilers for BCV " + VERSION + ".");
OPTIONS.addOption("decompiler", true, "sets the decompiler, procyon by default.");
OPTIONS.addOption("i", true, "sets the input.");
OPTIONS.addOption("o", true, "sets the output.");
OPTIONS.addOption("t", true, "sets the target class to decompile, append all to decomp all as zip.");
OPTIONS.addOption("nowait", true, "won't wait the 5 seconds to allow the user to read the CLI.");
}
public static boolean containsCommand(String[] args)
@ -69,8 +69,17 @@ public class CommandLineInput
try
{
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("help") || cmd.hasOption("clean") || cmd.hasOption("english") || cmd.hasOption("list") || cmd.hasOption("decompiler") || cmd.hasOption("i") || cmd.hasOption("o") || cmd.hasOption("t") || cmd.hasOption("nowait"))
CommandLine cmd = PARSER.parse(OPTIONS, args);
if (cmd.hasOption("help")
|| cmd.hasOption("clean")
|| cmd.hasOption("english")
|| cmd.hasOption("list")
|| cmd.hasOption("decompiler")
|| cmd.hasOption("i")
|| cmd.hasOption("o")
|| cmd.hasOption("t")
|| cmd.hasOption("nowait"))
{
return true;
}
@ -89,7 +98,8 @@ public class CommandLineInput
return GUI;
try
{
CommandLine cmd = parser.parse(options, args);
CommandLine cmd = PARSER.parse(OPTIONS, args);
if (cmd.hasOption("list"))
{
System.out.println("Procyon");
@ -100,12 +110,16 @@ public class CommandLineInput
System.out.println("JD-GUI");
System.out.println("Smali");
System.out.println("ASMifier");
return STOP;
}
else if (cmd.hasOption("clean"))
{
new File(Constants.getBCVDirectory()).delete();
if (cmd.getOptionValue("i") == null && cmd.getOptionValue("o") == null && cmd.getOptionValue("t") == null)
if (cmd.getOptionValue("i") == null
&& cmd.getOptionValue("o") == null
&& cmd.getOptionValue("t") == null)
return GUI;
}
else if (cmd.hasOption("english"))
@ -115,7 +129,15 @@ public class CommandLineInput
}
else if (cmd.hasOption("help"))
{
for (String s : new String[]{"-help Displays the help menu", "-clean Deletes the BCV directory", "-english Forces English language translations", "-list Displays the available decompilers", "-decompiler <decompiler> Selects the decompiler, procyon by default", "-i <input file> Selects the input file", "-o <output file> Selects the output file", "-t <target classname> Must either be the fully qualified classname or \"all\" to decompile all as zip", "-nowait Doesn't wait for the user to read the CLI messages"})
for (String s : new String[]{"-help Displays the help menu",
"-clean Deletes the BCV directory",
"-english Forces English language translations",
"-list Displays the available decompilers",
"-decompiler <decompiler> Selects the decompiler, procyon by default",
"-i <input file> Selects the input file",
"-o <output file> Selects the output file",
"-t <target classname> Must either be the fully qualified classname or \"all\" to decompile all as zip",
"-nowait Doesn't wait for the user to read the CLI messages"})
System.out.println(s);
return STOP;
}
@ -181,7 +203,7 @@ public class CommandLineInput
{
try
{
CommandLine cmd = parser.parse(options, args);
CommandLine cmd = PARSER.parse(OPTIONS, args);
String decompiler = cmd.getOptionValue("decompiler");
File input = new File(cmd.getOptionValue("i"));
File output = new File(cmd.getOptionValue("o"));
@ -197,7 +219,7 @@ public class CommandLineInput
//if its zip/jar/apk/dex attempt unzip as whole zip
//if its just class allow any
File tempZip = new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar");
File tempZip = new File(TEMP_DIRECTORY + FS + "temp_" + MiscUtils.getRandomizedName() + ".jar");
if (tempZip.exists())
tempZip.delete();

View File

@ -70,7 +70,7 @@ public class Configuration
public static boolean needsReDump = true;
public static boolean warnForEditing = false;
public static boolean runningObfuscation = false;
public static final long start = System.currentTimeMillis();
public static final long BOOT_TIMESTAMP = System.currentTimeMillis();
public static String lastOpenDirectory = ".";
public static String lastSaveDirectory = ".";
public static String lastPluginDirectory = ".";
@ -80,7 +80,7 @@ public class Configuration
public static int silenceExceptionGUI = 0;
public static int pauseExceptionGUI = 0;
public static final int maxRecentFiles = 25; //eventually may be a setting
public static int maxRecentFiles = 25; //eventually may be a setting
public static boolean verifyCorruptedStateOnBoot = false; //eventually may be a setting
public static BootState bootState = BootState.START_UP;

View File

@ -66,31 +66,31 @@ public class Constants
//if true the version checker will prompt and ask how you would like to proceed
public static final boolean FORCE_VERSION_CHECKER_PROMPT = false;
public static final String fs = System.getProperty("file.separator");
public static final String nl = System.getProperty("line.separator");
public static final File BCVDir = resolveBCVRoot();
public static final File RT_JAR = new File(System.getProperty("java.home") + fs + "lib" + fs + "rt.jar");
public static final File JAVA_BINARY = new File(System.getProperty("java.home") + fs + "bin" + fs + "java.exe");
public static final File JAVA_BINARY_NIX = new File(System.getProperty("java.home") + fs + "bin" + fs + "java");
public static final File RT_JAR_DUMPED = new File(getBCVDirectory() + fs + "rt.jar");
public static final String filesName = getBCVDirectory() + fs + "recentfiles.json";
public static final String pluginsName = getBCVDirectory() + fs + "recentplugins.json";
public static final String settingsName = getBCVDirectory() + fs + "settings.bcv";
public static final String tempDirectory = getBCVDirectory() + fs + "bcv_temp" + fs;
public static final String systemTempDirectory = System.getProperty("java.io.tmpdir");
public static final String libsDirectory = getBCVDirectory() + fs + "libs" + fs;
public static String krakatauWorkingDirectory = getBCVDirectory() + fs + "krakatau_" + krakatauVersion;
public static String enjarifyWorkingDirectory = getBCVDirectory() + fs + "enjarify_" + enjarifyVersion;
public static final String FS = System.getProperty("file.separator");
public static final String NL = System.getProperty("line.separator");
public static final String[] SUPPORTED_FILE_EXTENSIONS = ResourceType.supportedBCVExtensionMap.keySet().toArray(new String[0]);
public static final int ASM_VERSION = Opcodes.ASM9;
public static final File BCVDir = resolveBCVRoot();
public static final File RT_JAR = new File(System.getProperty("java.home") + FS + "lib" + FS + "rt.jar");
public static final File JAVA_BINARY = new File(System.getProperty("java.home") + FS + "bin" + FS + "java.exe");
public static final File JAVA_BINARY_NIX = new File(System.getProperty("java.home") + FS + "bin" + FS + "java");
public static final File RT_JAR_DUMPED = new File(getBCVDirectory() + FS + "rt.jar");
public static final String FILES_NAME = getBCVDirectory() + FS + "recentfiles.json";
public static final String PLUGINS_NAME = getBCVDirectory() + FS + "recentplugins.json";
public static final String SETTINGS_NAME = getBCVDirectory() + FS + "settings.bcv";
public static final String TEMP_DIRECTORY = getBCVDirectory() + FS + "bcv_temp" + FS;
public static final String SYSTEM_TEMP_DIRECTORY = System.getProperty("java.io.tmpdir");
public static final String LIBS_DIRECTORY = getBCVDirectory() + FS + "libs" + FS;
public static String krakatauWorkingDirectory = getBCVDirectory() + FS + "krakatau_" + krakatauVersion;
public static String enjarifyWorkingDirectory = getBCVDirectory() + FS + "enjarify_" + enjarifyVersion;
public static final PrintStream ERR = System.err;
public static final PrintStream OUT = System.out;
public static File resolveBCVRoot()
{
File defaultLocation = new File(System.getProperty("user.home") + fs + ".Bytecode-Viewer");
File defaultLocation = new File(System.getProperty("user.home") + FS + ".Bytecode-Viewer");
//if BCV was previously installed using the default directory, continue to use that
if (defaultLocation.exists())
@ -99,11 +99,11 @@ public class Constants
//handle XDG Base Directory - https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if (isNix())
{
File homeLocal = new File(System.getProperty("user.home") + fs + ".local");
File homeLocal = new File(System.getProperty("user.home") + FS + ".local");
if (homeLocal.exists())
return new File(homeLocal, "share" + fs + ".Bytecode-Viewer");
return new File(homeLocal, "share" + FS + ".Bytecode-Viewer");
File homeConfig = new File(System.getProperty("user.home") + fs + ".config");
File homeConfig = new File(System.getProperty("user.home") + FS + ".config");
if (homeConfig.exists())
return new File(homeConfig, ".Bytecode-Viewer");
}

View File

@ -47,15 +47,15 @@ public class Settings
{
try
{
if (new File(filesName).exists())
recentFiles = gson.fromJson(DiskReader.loadAsString(filesName), new TypeToken<ArrayList<String>>() {}.getType());
if (new File(FILES_NAME).exists())
recentFiles = gson.fromJson(DiskReader.loadAsString(FILES_NAME), new TypeToken<ArrayList<String>>() {}.getType());
else
recentFiles = DiskReader.loadArrayList(getBCVDirectory() + fs + "recentfiles.bcv", false);
recentFiles = DiskReader.loadArrayList(getBCVDirectory() + FS + "recentfiles.bcv", false);
if (new File(pluginsName).exists())
recentPlugins = gson.fromJson(DiskReader.loadAsString(pluginsName), new TypeToken<ArrayList<String>>() {}.getType());
if (new File(PLUGINS_NAME).exists())
recentPlugins = gson.fromJson(DiskReader.loadAsString(PLUGINS_NAME), new TypeToken<ArrayList<String>>() {}.getType());
else
recentPlugins = DiskReader.loadArrayList(getBCVDirectory() + fs + "recentplugins.bcv", false);
recentPlugins = DiskReader.loadArrayList(getBCVDirectory() + FS + "recentplugins.bcv", false);
MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles);
MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles);
@ -76,7 +76,7 @@ public class Settings
recentFiles.remove(f.getAbsolutePath()); // already added on the list
recentFiles.add(0, f.getAbsolutePath());
MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles);
DiskWriter.replaceFile(filesName, MiscUtils.listToString(recentFiles), false);
DiskWriter.replaceFile(FILES_NAME, MiscUtils.listToString(recentFiles), false);
resetRecentFilesMenu();
}
@ -84,7 +84,7 @@ public class Settings
{
if (recentFiles.remove(f.getAbsolutePath()))
{
DiskWriter.replaceFile(filesName, MiscUtils.listToString(recentFiles), false);
DiskWriter.replaceFile(FILES_NAME, MiscUtils.listToString(recentFiles), false);
resetRecentFilesMenu();
}
}
@ -107,7 +107,7 @@ public class Settings
recentPlugins.remove(f.getAbsolutePath()); // already added on the list
recentPlugins.add(0, f.getAbsolutePath());
MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles);
DiskWriter.replaceFile(pluginsName, MiscUtils.listToString(recentPlugins), false);
DiskWriter.replaceFile(PLUGINS_NAME, MiscUtils.listToString(recentPlugins), false);
resetRecentFilesMenu();
}
@ -115,7 +115,7 @@ public class Settings
{
if (recentPlugins.remove(f.getAbsolutePath()))
{
DiskWriter.replaceFile(pluginsName, MiscUtils.listToString(recentPlugins), false);
DiskWriter.replaceFile(PLUGINS_NAME, MiscUtils.listToString(recentPlugins), false);
resetRecentFilesMenu();
}
}

View File

@ -29,7 +29,7 @@ import javax.swing.*;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.VERSION;
import static the.bytecode.club.bytecodeviewer.Constants.settingsName;
import static the.bytecode.club.bytecodeviewer.Constants.SETTINGS_NAME;
/**
* Used to handle loading/saving the GUI (options).
@ -51,7 +51,7 @@ public class SettingsSerializer
{
try
{
DiskWriter.replaceFile(settingsName, "BCV: " + VERSION, false);
DiskWriter.replaceFile(SETTINGS_NAME, "BCV: " + VERSION, false);
save(BytecodeViewer.viewer.rbr.isSelected());
save(BytecodeViewer.viewer.rsy.isSelected());
save(BytecodeViewer.viewer.din.isSelected());
@ -167,9 +167,9 @@ public class SettingsSerializer
save(Configuration.deleteForeignLibraries);
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
DiskWriter.writeNewLine(settingsName, "0");
DiskWriter.writeNewLine(SETTINGS_NAME, "0");
else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel()))
DiskWriter.writeNewLine(settingsName, "1");
DiskWriter.writeNewLine(SETTINGS_NAME, "1");
save(Configuration.python3);
save(Configuration.javac);
@ -216,13 +216,13 @@ public class SettingsSerializer
{
try
{
settingsFileExists = new File(settingsName).exists();
settingsFileExists = new File(SETTINGS_NAME).exists();
if (!settingsFileExists)
return;
//precache the file
DiskReader.loadString(settingsName, 0, true);
DiskReader.loadString(SETTINGS_NAME, 0, true);
//process the cached file
Configuration.lafTheme = LAFTheme.valueOf(asString(127));
@ -416,21 +416,21 @@ public class SettingsSerializer
public static void save(Object o)
{
DiskWriter.writeNewLine(settingsName, String.valueOf(o), false);
DiskWriter.writeNewLine(SETTINGS_NAME, String.valueOf(o), false);
}
public static String asString(int lineNumber) throws Exception
{
return DiskReader.loadString(settingsName, lineNumber, false);
return DiskReader.loadString(SETTINGS_NAME, lineNumber, false);
}
public static boolean asBoolean(int lineNumber) throws Exception
{
return Boolean.parseBoolean(DiskReader.loadString(settingsName, lineNumber, false));
return Boolean.parseBoolean(DiskReader.loadString(SETTINGS_NAME, lineNumber, false));
}
public static int asInt(int lineNumber) throws Exception
{
return Integer.parseInt(DiskReader.loadString(settingsName, lineNumber, false));
return Integer.parseInt(DiskReader.loadString(SETTINGS_NAME, lineNumber, false));
}
}

View File

@ -41,16 +41,15 @@ public final class ASMResourceUtil
MethodNode m = (MethodNode) o;
if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V"))
{
return cn.name + "." + m.name;
}
}
}
return defaultFQN;
}
public static void renameFieldNode(String originalParentName, String originalFieldName, String originalFieldDesc, String newFieldParent, String newFieldName, String newFieldDesc)
public static void renameFieldNode(String originalParentName, String originalFieldName, String originalFieldDesc,
String newFieldParent, String newFieldName, String newFieldDesc)
{
for (ClassNode c : BytecodeViewer.getLoadedClasses())
{
@ -78,7 +77,8 @@ public final class ASMResourceUtil
}
}
public static void renameMethodNode(String originalParentName, String originalMethodName, String originalMethodDesc, String newParent, String newName, String newDesc)
public static void renameMethodNode(String originalParentName, String originalMethodName, String originalMethodDesc,
String newParent, String newName, String newDesc)
{
for (ClassNode c : BytecodeViewer.getLoadedClasses())
{
@ -182,6 +182,7 @@ public final class ASMResourceUtil
mi.owner = newName;
mi.desc = mi.desc.replace(oldName, newName);
}
if (i instanceof FieldInsnNode)
{
FieldInsnNode fi = (FieldInsnNode) i;

View File

@ -113,7 +113,7 @@ public class BCV
{
try
{
File f = new File(tempDirectory + fs + MiscUtils.randomString(12) + "loaded_temp.jar");
File f = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(12) + "loaded_temp.jar");
List<Class<?>> ret = new ArrayList<>();
JarUtils.saveAsJar(BCV.getLoadedClasses(), f.getAbsolutePath());

View File

@ -40,9 +40,10 @@ import static the.bytecode.club.bytecodeviewer.Constants.*;
public class ExceptionUI extends JFrameConsole
{
public static final String KONLOCH = "https://github.com/Konloch/bytecode-viewer/issues or Konloch at https://the.bytecode.club or konloch@gmail.com";
public static final String KONLOCH = "https://github.com/Konloch/bytecode-viewer/issues" +
"or Konloch at https://the.bytecode.club or konloch@gmail.com";
public static final String SEND_STACKTRACE_TO = buildErrorLogHeader(KONLOCH);
public static final String SEND_STACKTRACE_TO_NL = SEND_STACKTRACE_TO + nl + nl;
public static final String SEND_STACKTRACE_TO_NL = SEND_STACKTRACE_TO + NL + NL;
/**
* @param e The exception to be shown
@ -116,7 +117,7 @@ public class ExceptionUI extends JFrameConsole
setTitle("Bytecode Viewer " + VERSION + " - Error Log - Send this to " + author);
getContentPane().setLayout(new CardLayout(0, 0));
getTextArea().setText(buildErrorLogHeader(author) + nl + nl + error);
getTextArea().setText(buildErrorLogHeader(author) + NL + NL + error);
getTextArea().setCaretPosition(0);
//embed error log as a new tab
@ -138,7 +139,9 @@ public class ExceptionUI extends JFrameConsole
{
String fatJar = FAT_JAR ? " [Fat Jar]" : "";
return TranslatedStrings.PLEASE_SEND_THIS_ERROR_LOG_TO + " " + author + "\n" + TranslatedStrings.PLEASE_SEND_RESOURCES + "\nBytecode Viewer Version: " + VERSION + fatJar + ", OS: " + System.getProperty("os.name") + ", Java: " + System.getProperty("java.version");
return TranslatedStrings.PLEASE_SEND_THIS_ERROR_LOG_TO + " " + author + "\n"
+ TranslatedStrings.PLEASE_SEND_RESOURCES
+ "\nBytecode Viewer Version: " + VERSION + fatJar + ", OS: " + System.getProperty("os.name") + ", Java: " + System.getProperty("java.version");
}
private static final long serialVersionUID = -5230501978224926296L;

View File

@ -51,23 +51,22 @@ public class Boot
{
/*flags*/
public static boolean globalstop = false;
public static boolean completedboot = false;
public static boolean completedBoot = false;
public static boolean downloading = false;
private static InitialBootScreen screen;
private static final List<String> libsList = new ArrayList<>();
private static final List<String> libsFileList = new ArrayList<>();
private static final List<String> urlList = new ArrayList<>();
private static final List<String> LIBS_LIST = new ArrayList<>();
private static final List<String> LIBS_FILE_LIST = new ArrayList<>();
private static final List<String> URL_LIST = new ArrayList<>();
public static void boot(String[] args, boolean CLI) throws Exception
public static void boot(String[] args, boolean isCLI) throws Exception
{
bootstrap();
ILoader<?> loader = findLoader();
screen = new InitialBootScreen();
if (!CLI)
if (!isCLI)
SwingUtilities.invokeLater(() -> screen.setVisible(true));
create(loader, args.length <= 0 || Boolean.parseBoolean(args[0]));
@ -88,17 +87,11 @@ public class Boot
populateUrlList();
if (globalstop)
if (URL_LIST.isEmpty())
{
while (true)
{
Thread.sleep(100);//just keep this thread halted.
}
}
if (urlList.isEmpty())
{
JOptionPane.showMessageDialog(null, "Bytecode Viewer ran into an issue, for some reason github is not " + "returning what we're expecting. Please try rebooting, if this issue persists please contact " + "@Konloch.", "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "Bytecode Viewer ran into an issue, for some reason github is not "
+ "returning what we're expecting. Please try rebooting, if this issue persists please contact "
+ "@Konloch.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
@ -110,11 +103,11 @@ public class Boot
populateLibsDirectory();
screen.getProgressBar().setMaximum(urlList.size() * 2);
screen.getProgressBar().setMaximum(URL_LIST.size() * 2);
int completedCheck = 0;
for (String s : urlList)
for (String s : URL_LIST)
{
String fileName = s.substring("https://github.com/Konloch/bytecode-viewer/blob/master/libs/".length());
File file = new File(libsDirectory, fileName);
@ -122,13 +115,14 @@ public class Boot
boolean passed = false;
while (!passed)
{
if (!libsList.contains(fileName))
if (!LIBS_LIST.contains(fileName))
{
downloading = true;
setState("Bytecode Viewer Boot Screen - Downloading " + fileName + "...");
System.out.println("Downloading " + fileName);
try (InputStream is = new URL("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName).openConnection().getInputStream(); FileOutputStream fos = new FileOutputStream(file))
try (InputStream is = new URL("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName).openConnection().getInputStream();
FileOutputStream fos = new FileOutputStream(file))
{
System.out.println("Downloading from " + s);
byte[] buffer = new byte[8192];
@ -157,7 +151,7 @@ public class Boot
setState("Bytecode Viewer Boot Screen - Verifying " + fileName + "...");
System.out.println("Verifying " + fileName + "...");
File f = new File(Constants.tempDirectory, "temp");
File f = new File(Constants.TEMP_DIRECTORY, "temp");
if (!f.exists())
{
f.getParentFile().mkdirs();
@ -165,7 +159,7 @@ public class Boot
ZipUtils.zipFile(file, f);
f.delete();
libsFileList.add(file.getAbsolutePath());
LIBS_FILE_LIST.add(file.getAbsolutePath());
System.out.println("Download finished!");
passed = true;
}
@ -183,7 +177,7 @@ public class Boot
setState("Bytecode Viewer Boot Screen - Verifying " + fileName + "...");
System.out.println("Verifying " + fileName + "...");
File f = new File(Constants.tempDirectory, "temp");
File f = new File(Constants.TEMP_DIRECTORY, "temp");
ZipUtils.zipFile(file, f);
f.delete();
@ -193,7 +187,7 @@ public class Boot
{
e.printStackTrace();
System.out.println("Jar or Zip" + file.getAbsolutePath() + " is corrupt, redownloading.");
libsFileList.remove(file.getAbsolutePath());
LIBS_FILE_LIST.remove(file.getAbsolutePath());
file.delete();
}
}
@ -209,11 +203,11 @@ public class Boot
setState("Bytecode Viewer Boot Screen - Checking & Deleting Foreign/Outdated Libraries...");
System.out.println("Checking & Deleting foreign/outdated libraries");
for (String s : libsFileList)
for (String s : LIBS_FILE_LIST)
{
File f = new File(s);
boolean delete = true;
for (String urlS : urlList)
for (String urlS : URL_LIST)
{
String fileName = urlS.substring("https://github.com/Konloch/bytecode-viewer/blob/master/libs/".length());
if (fileName.equals(f.getName()))
@ -229,7 +223,7 @@ public class Boot
setState("Bytecode Viewer Boot Screen - Loading Libraries...");
System.out.println("Loading libraries...");
for (String s : libsFileList)
for (String s : LIBS_FILE_LIST)
{
if (s.endsWith(".jar"))
{
@ -249,7 +243,8 @@ public class Boot
{
e.printStackTrace();
f.delete();
JOptionPane.showMessageDialog(null, "Error, Library " + f.getName() + " is corrupt, please " + "restart to redownload it.", "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "Error, Library " + f.getName() + " is corrupt, please "
+ "restart to redownload it.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
@ -267,7 +262,7 @@ public class Boot
screen.getProgressBar().setValue(completedCheck);
setState("Bytecode Viewer Boot Screen - Booting!");
completedboot = true;
completedBoot = true;
}
public static File libsDir()
@ -305,7 +300,7 @@ public class Boot
for (String s : req.read())
if (s.contains("href=\"/Konloch/bytecode-viewer/blob/master/libs/"))
{
urlList.add("https://github.com" + s.split("href=")[1].split("\"")[1]);
URL_LIST.add("https://github.com" + s.split("href=")[1].split("\"")[1]);
}
}
@ -315,16 +310,16 @@ public class Boot
if (libsDir.exists())
for (File f : MiscUtils.listFiles(libsDir))
{
libsList.add(f.getName());
libsFileList.add(f.getAbsolutePath());
LIBS_LIST.add(f.getName());
LIBS_FILE_LIST.add(f.getAbsolutePath());
}
}
public static void dropKrakatau()
{
File temp = new File(getBCVDirectory() + fs + "krakatau_" + krakatauVersion + ".zip");
File temp = new File(getBCVDirectory() + FS + "krakatau_" + krakatauVersion + ".zip");
File krakatauDirectory = new File(krakatauWorkingDirectory);
krakatauWorkingDirectory += fs + "Krakatau-master";
krakatauWorkingDirectory += FS + "Krakatau-master";
if (!krakatauDirectory.exists() || temp.exists())
{
if (temp.exists())
@ -359,9 +354,9 @@ public class Boot
public static void dropEnjarify()
{
File temp = new File(getBCVDirectory() + fs + "enjarify" + Constants.enjarifyVersion + ".zip");
File temp = new File(getBCVDirectory() + FS + "enjarify" + Constants.enjarifyVersion + ".zip");
File enjarifyDirectory = new File(Constants.enjarifyWorkingDirectory);
Constants.enjarifyWorkingDirectory += fs + "enjarify-master";
Constants.enjarifyWorkingDirectory += FS + "enjarify-master";
if (!enjarifyDirectory.exists() || temp.exists())
{
if (temp.exists())
@ -396,7 +391,7 @@ public class Boot
public static void downloadZipsOnly()
{
for (String s : urlList)
for (String s : URL_LIST)
{
String fileName = s.substring("https://github.com/Konloch/bytecode-viewer/blob/master/libs/".length());
File file = new File(libsDir(), fileName);
@ -404,7 +399,7 @@ public class Boot
boolean passed = false;
while (!passed)
{
if (!libsList.contains(fileName) && fileName.endsWith(".zip"))
if (!LIBS_LIST.contains(fileName) && fileName.endsWith(".zip"))
{
downloading = true;
setState("Bytecode Viewer Boot Screen - Downloading " + fileName + "...");
@ -443,11 +438,11 @@ public class Boot
setState("Bytecode Viewer Boot Screen - Verifying " + fileName + "...");
System.out.println("Verifying " + fileName + "...");
File f = new File(Constants.tempDirectory, "temp");
File f = new File(Constants.TEMP_DIRECTORY, "temp");
ZipUtils.zipFile(file, f);
f.delete();
libsFileList.add(file.getAbsolutePath());
LIBS_FILE_LIST.add(file.getAbsolutePath());
System.out.println("Download finished!");
passed = true;
}
@ -469,7 +464,7 @@ public class Boot
setState("Bytecode Viewer Boot Screen - Checking Enjarify...");
System.out.println("Checking enjarify");
File enjarifyZip = null;
for (File f : MiscUtils.listFiles(new File(Constants.libsDirectory)))
for (File f : MiscUtils.listFiles(new File(Constants.LIBS_DIRECTORY)))
{
if (f.getName().toLowerCase().startsWith("enjarify-"))
{
@ -495,8 +490,8 @@ public class Boot
}
}
Constants.enjarifyWorkingDirectory = getBCVDirectory() + fs + "enjarify_" + Constants.enjarifyVersion + fs + "enjarify-master";
File enjarifyDirectory = new File(getBCVDirectory() + fs + "enjarify_" + Constants.enjarifyVersion);
Constants.enjarifyWorkingDirectory = getBCVDirectory() + FS + "enjarify_" + Constants.enjarifyVersion + FS + "enjarify-master";
File enjarifyDirectory = new File(getBCVDirectory() + FS + "enjarify_" + Constants.enjarifyVersion);
if (!enjarifyDirectory.exists())
{
try
@ -507,7 +502,8 @@ public class Boot
}
catch (Exception e)
{
BytecodeViewer.showMessage("ERROR: There was an issue unzipping enjarify (possibly corrupt). Restart " + "BCV." + nl + "If the error persists contact @Konloch.");
BytecodeViewer.showMessage("ERROR: There was an issue unzipping enjarify (possibly corrupt). Restart BCV."
+ NL + "If the error persists contact @Konloch.");
BytecodeViewer.handleException(e);
Objects.requireNonNull(enjarifyZip).delete();
}
@ -521,7 +517,7 @@ public class Boot
System.out.println("Checking krakatau");
File krakatauZip = null;
for (File f : MiscUtils.listFiles(new File(Constants.libsDirectory)))
for (File f : MiscUtils.listFiles(new File(Constants.LIBS_DIRECTORY)))
{
if (f.getName().toLowerCase().startsWith("krakatau-"))
{
@ -548,9 +544,9 @@ public class Boot
}
}
Constants.krakatauWorkingDirectory = getBCVDirectory() + fs + "krakatau_" + Constants.krakatauVersion + fs + "Krakatau-master";
Constants.krakatauWorkingDirectory = getBCVDirectory() + FS + "krakatau_" + Constants.krakatauVersion + FS + "Krakatau-master";
File krakatauDirectory = new File(getBCVDirectory() + fs + "krakatau_" + Constants.krakatauVersion);
File krakatauDirectory = new File(getBCVDirectory() + FS + "krakatau_" + Constants.krakatauVersion);
if (!krakatauDirectory.exists())
{
try
@ -561,7 +557,8 @@ public class Boot
}
catch (Exception e)
{
BytecodeViewer.showMessage("ERROR: There was an issue unzipping Krakatau decompiler (possibly " + "corrupt). Restart BCV." + nl + "If the error persists contact @Konloch.");
BytecodeViewer.showMessage("ERROR: There was an issue unzipping Krakatau decompiler (possibly corrupt). Restart BCV."
+ NL + "If the error persists contact @Konloch.");
BytecodeViewer.handleException(e);
Objects.requireNonNull(krakatauZip).delete();
}

View File

@ -60,25 +60,26 @@ public class InitialBootScreen extends JFrame
gridBagLayout.columnWidths = new int[]{0, 0};
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
getContentPane().setLayout(gridBagLayout);
JScrollPane scrollPane = new JScrollPane();
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.gridheight = 24;
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 0;
gbc_scrollPane.gridy = 0;
getContentPane().add(scrollPane, gbc_scrollPane);
GridBagConstraints scrollPaneConstraints = new GridBagConstraints();
scrollPaneConstraints.gridheight = 24;
scrollPaneConstraints.insets = new Insets(0, 0, 5, 0);
scrollPaneConstraints.fill = GridBagConstraints.BOTH;
scrollPaneConstraints.gridx = 0;
scrollPaneConstraints.gridy = 0;
getContentPane().add(scrollPane, scrollPaneConstraints);
scrollPane.setViewportView(HTMLPane.fromResource(language.getHTMLPath("intro")));
GridBagConstraints gbc_progressBar = new GridBagConstraints();
gbc_progressBar.fill = GridBagConstraints.HORIZONTAL;
gbc_progressBar.gridx = 0;
gbc_progressBar.gridy = 24;
getContentPane().add(progressBar, gbc_progressBar);
GridBagConstraints progressBarConstraints = new GridBagConstraints();
progressBarConstraints.fill = GridBagConstraints.HORIZONTAL;
progressBarConstraints.gridx = 0;
progressBarConstraints.gridy = 24;
getContentPane().add(progressBar, progressBarConstraints);
this.setLocationRelativeTo(null);
}

View File

@ -34,7 +34,7 @@ import java.net.URI;
import java.net.URL;
import static the.bytecode.club.bytecodeviewer.Constants.VERSION;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* @author Konloch
@ -43,7 +43,8 @@ public class UpdateCheck implements Runnable
{
//just brute force download the url path
//one of these works for every single version of BCV
public static final String[] remoteGithubReleases = new String[]{
public static final String[] REMOTE_GITHUB_RELEASES = new String[]
{
//current url scheme since v2.9.12
"https://github.com/Konloch/bytecode-viewer/releases/download/v{VERSION}/Bytecode-Viewer-{VERSION}.jar",
//for v2.9.10 and v2.9.11
@ -59,13 +60,17 @@ public class UpdateCheck implements Runnable
//for v1.0
"https://github.com/Konloch/bytecode-viewer/releases/download/B{VERSION}/BytecodeViewer.jar",
//zip variant of current url scheme since v2.9.12 (not currently used but incase it ever does)
"https://github.com/Konloch/bytecode-viewer/releases/download/v{VERSION}/Bytecode-Viewer-{VERSION}.zip",};
"https://github.com/Konloch/bytecode-viewer/releases/download/v{VERSION}/Bytecode-Viewer-{VERSION}.zip"
};
//a list of all of the released versions of BCV
public static final String[] versions = new String[]{
public static final String[] BCV_VERSIONS = new String[]
{
//"2.11.0",
//"2.10.15",
"2.10.14", "2.10.13", "2.10.12", "2.10.11", "2.9.22", "2.9.21", "2.9.20", "2.9.19", "2.9.18", "2.9.17", "2.9.16", "2.9.15", "2.9.14", "2.9.13", "2.9.12", "2.9.11", "2.9.10", //broken due to repo change
"2.10.14", "2.10.13", "2.10.12", "2.10.11",
"2.9.22", "2.9.21", "2.9.20",
"2.9.19", "2.9.18", "2.9.17", "2.9.16", "2.9.15", "2.9.14", "2.9.13", "2.9.12", "2.9.11", "2.9.10", //broken due to repo change
"2.9.8", //broken due to repo change & zip
"2.9.7", //broken due to repo change & zip
"2.9.6", //zip
@ -79,7 +84,11 @@ public class UpdateCheck implements Runnable
"2.8.0", //zip
"2.7.1", //zip
"2.7.0", //zip
"2.6.0", "2.5.2", "2.5.1", "2.5.0", "2.4.0", "2.3.0", "2.2.1", "2.2.0", "2.1.1", "2.1.0", "2.0.1", "2.0", "1.5.3", "1.5.2", "1.5.1", "1.5", "1.4", "1.3.1", "1.3", "1.2", "1.1", "1.0",};
"2.6.0", "2.5.2", "2.5.1", "2.5.0", "2.4.0", "2.3.0", "2.2.1", "2.2.0", "2.1.1", "2.1.0", "2.0.1",
"2.0",
"1.5.3", "1.5.2", "1.5.1", "1.5", "1.4", "1.3.1", "1.3",
"1.2", "1.1", "1.0"
};
@Override
public void run()
@ -100,7 +109,7 @@ public class UpdateCheck implements Runnable
{
}
MultipleChoiceDialog outdatedDialog = new MultipleChoiceDialog("Bytecode Viewer - Outdated Version", "Your version: " + localVersion + ", latest version: " + version + nl + "What would you like to do?", new String[]{"Open The Download Page", "Download The Updated Jar", "Do Nothing (And Don't Ask Again)"});
MultipleChoiceDialog outdatedDialog = new MultipleChoiceDialog("Bytecode Viewer - Outdated Version", "Your version: " + localVersion + ", latest version: " + version + NL + "What would you like to do?", new String[]{"Open The Download Page", "Download The Updated Jar", "Do Nothing (And Don't Ask Again)"});
int result = outdatedDialog.promptChoice();
@ -109,7 +118,7 @@ public class UpdateCheck implements Runnable
if (Desktop.isDesktopSupported())
Desktop.getDesktop().browse(new URI("https://github.com/Konloch/bytecode-viewer/releases"));
else
BytecodeViewer.showMessage("Cannot open the page, please manually type it." + nl + "https://github.com/Konloch/bytecode-viewer/releases");
BytecodeViewer.showMessage("Cannot open the page, please manually type it." + NL + "https://github.com/Konloch/bytecode-viewer/releases");
}
else if (result == 1)
{
@ -152,7 +161,9 @@ public class UpdateCheck implements Runnable
if (file.exists())
{
MultipleChoiceDialog overwriteDialog = new MultipleChoiceDialog("Bytecode Viewer - Overwrite File", "The file " + file + " exists, would you like to overwrite it?", new String[]{TranslatedStrings.YES.toString(), TranslatedStrings.NO.toString()});
MultipleChoiceDialog overwriteDialog = new MultipleChoiceDialog("Bytecode Viewer - Overwrite File",
"The file " + file + " exists, would you like to overwrite it?",
new String[]{ TranslatedStrings.YES.toString(), TranslatedStrings.NO.toString() });
if (overwriteDialog.promptChoice() != 0)
return null;
@ -166,21 +177,21 @@ public class UpdateCheck implements Runnable
//used to download all released versions of BCV
/*public static void main(String[] args)
{
BytecodeViewer.viewer = new MainViewerGUI();
for(String version : versions)
{
//TODO most are jars, check which are zip and append zip as needed
File file = new File("./" + version + ".zip");
if(!file.exists())
downloadBCV(version, file, () -> {}, () -> {});
}
}*/
{
BytecodeViewer.viewer = new MainViewerGUI();
for(String version : BCV_VERSIONS)
{
//TODO most are jars, check which are zip and append zip as needed
File file = new File("./" + version + ".zip");
if(!file.exists())
downloadBCV(version, file, () -> {}, () -> {});
}
}*/
private static void downloadBCV(String version, File saveTo, Runnable onFinish, Runnable onFail)
{
boolean found = false;
for (String urlAttempt : remoteGithubReleases)
for (String urlAttempt : REMOTE_GITHUB_RELEASES)
{
try
{
@ -223,7 +234,7 @@ public class UpdateCheck implements Runnable
private static void download(String url, File saveTo, Runnable onFinish) throws Exception
{
BCV.log("Downloading from: " + url);
BytecodeViewer.showMessage("Downloading the jar in the background, when it's finished you will be alerted with another message box." + nl + nl + "Expect this to take several minutes.");
BytecodeViewer.showMessage("Downloading the jar in the background, when it's finished you will be alerted with another message box." + NL + NL + "Expect this to take several minutes.");
try (InputStream is = new URL(url).openConnection().getInputStream(); FileOutputStream fos = new FileOutputStream(saveTo))
{

View File

@ -52,13 +52,13 @@ public class ClassTree
this(convertToMap(classes));
}
public ClassTree(Map<String, ClassNode> classes_)
public ClassTree(Map<String, ClassNode> classes)
{
classes = copyOf(classes_);
this.classes = copyOf(classes);
supers = new NullPermeableHashMap<>(SET_CREATOR);
delgates = new NullPermeableHashMap<>(SET_CREATOR);
build(classes);
build(this.classes);
}
// TODO: optimise
@ -66,32 +66,36 @@ public class ClassTree
{
for (ClassNode node : classes.values())
{
for (String iface : node.interfaces)
for (String iFace : node.interfaces)
{
ClassNode ifacecs = classes.get(iface);
if (ifacecs == null)
ClassNode iFaces = classes.get(iFace);
if (iFaces == null)
continue;
getDelegates0(ifacecs).add(node);
getDelegates0(iFaces).add(node);
Set<ClassNode> superinterfaces = new HashSet<>();
buildSubTree(classes, superinterfaces, ifacecs);
buildSubTree(classes, superinterfaces, iFaces);
getSupers0(node).addAll(superinterfaces);
}
ClassNode currentSuper = classes.get(node.superName);
while (currentSuper != null)
{
getDelegates0(currentSuper).add(node);
getSupers0(node).add(currentSuper);
for (String iface : currentSuper.interfaces)
for (String iFace : currentSuper.interfaces)
{
ClassNode ifacecs = classes.get(iface);
if (ifacecs == null)
ClassNode iFaces = classes.get(iFace);
if (iFaces == null)
continue;
getDelegates0(ifacecs).add(currentSuper);
getDelegates0(iFaces).add(currentSuper);
Set<ClassNode> superinterfaces = new HashSet<>();
buildSubTree(classes, superinterfaces, ifacecs);
buildSubTree(classes, superinterfaces, iFaces);
getSupers0(currentSuper).addAll(superinterfaces);
getSupers0(node).addAll(superinterfaces);
}
@ -108,6 +112,7 @@ public class ClassTree
for (String iface : node.interfaces)
{
ClassNode ifacecs = classes.get(iface);
if (ifacecs == null)
continue;
@ -126,14 +131,17 @@ public class ClassTree
for (String iface : currentSuper.interfaces)
{
ClassNode ifacecs = classes.get(iface);
if (ifacecs == null)
continue;
getDelegates0(ifacecs).add(currentSuper);
Set<ClassNode> superinterfaces = new HashSet<>();
buildSubTree(classes, superinterfaces, ifacecs);
getSupers0(currentSuper).addAll(superinterfaces);
getSupers0(node).addAll(superinterfaces);
}
currentSuper = classes.get(currentSuper.superName);
}
@ -162,14 +170,12 @@ public class ClassTree
public Set<MethodNode> getMethodsFromSuper(ClassNode node, String name, String desc)
{
Set<MethodNode> methods = new HashSet<>();
for (ClassNode super_ : getSupers(node))
for (ClassNode superClassNode : getSupers(node))
{
for (MethodNode mn : super_.methods)
for (MethodNode mn : superClassNode.methods)
{
if (mn.name.equals(name) && mn.desc.equals(desc))
{
methods.add(mn);
}
}
}
return methods;
@ -183,9 +189,7 @@ public class ClassTree
for (MethodNode mn : delegate.methods)
{
if (mn.name.equals(name) && mn.desc.equals(desc))
{
methods.add(mn);
}
}
}
return methods;
@ -193,14 +197,12 @@ public class ClassTree
public MethodNode getFirstMethodFromSuper(ClassNode node, String name, String desc)
{
for (ClassNode super_ : getSupers(node))
for (ClassNode superClassNode : getSupers(node))
{
for (MethodNode mn : super_.methods)
for (MethodNode mn : superClassNode.methods)
{
if (mn.name.equals(name) && mn.desc.equals(desc))
{
return mn;
}
}
}
return null;
@ -234,12 +236,10 @@ public class ClassTree
public Set<ClassNode> getSupers(ClassNode cn)
{
return Collections.unmodifiableSet(supers.get(cn));
// return supers.get(cn);
}
public Set<ClassNode> getDelegates(ClassNode cn)
{
return Collections.unmodifiableSet(delgates.get(cn));
// return delgates.get(cn);
}
}

View File

@ -32,7 +32,8 @@ import java.net.URLClassLoader;
public class ClassPathLoader implements ILoader<Object>
{
void extendClassPath(URL url) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
void extendClassPath(URL url) throws NoSuchMethodException, SecurityException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<URLClassLoader> urlClass = URLClassLoader.class;
@ -59,10 +60,11 @@ public class ClassPathLoader implements ILoader<Object>
extendClassPath(url);
}
}
}/* catch (IOException e) {
System.err.println("Error loading resource.");
e.printStackTrace();
}*/
}
/* catch (IOException e) {
System.err.println("Error loading resource.");
e.printStackTrace();
}*/
catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
{
System.err.println("Error reflecting URLClassLoader.addURL(URL) ?");

View File

@ -85,14 +85,14 @@ public class LibraryClassLoader extends ClassLoader implements ILoader<JarConten
@Override
public Class<?> findClass(String name) throws ClassNotFoundException, NoClassDefFoundError
{
String byte_name = name.replace(".", "/");
if (classCache.containsKey(byte_name))
return classCache.get(byte_name);
String byteName = name.replace(".", "/");
if (classCache.containsKey(byteName))
return classCache.get(byteName);
ClassNode cn = null;
for (JarContents<ClassNode> contents : binded)
{
cn = contents.getClassContents().namedMap().get(byte_name);
cn = contents.getClassContents().namedMap().get(byteName);
if (cn != null)
break;
}
@ -102,7 +102,7 @@ public class LibraryClassLoader extends ClassLoader implements ILoader<JarConten
Class<?> klass = define(cn);
if (klass != null)
{
classCache.put(byte_name, klass);
classCache.put(byteName, klass);
return klass;
}
}

View File

@ -29,8 +29,9 @@ import the.bytecode.club.bytecodeviewer.compilers.impl.SmaliAssembler;
*/
public enum Compiler
{
KRAKATAU_ASSEMBLER(new KrakatauAssembler()), SMALI_ASSEMBLER(new SmaliAssembler()), JAVA_COMPILER(new JavaCompiler()),
;
KRAKATAU_ASSEMBLER(new KrakatauAssembler()),
SMALI_ASSEMBLER(new SmaliAssembler()),
JAVA_COMPILER(new JavaCompiler());
private final InternalCompiler compiler;

View File

@ -27,4 +27,4 @@ package the.bytecode.club.bytecodeviewer.compilers;
public abstract class InternalCompiler
{
public abstract byte[] compile(String contents, String fullyQualifiedName);
}
}

View File

@ -43,19 +43,20 @@ public class JavaCompiler extends InternalCompiler
@Override
public byte[] compile(String contents, String fullyQualifiedName)
{
String fileStart = tempDirectory + fs + "temp" + MiscUtils.randomString(12) + fs;
String fileStart2 = tempDirectory + fs + "temp" + MiscUtils.randomString(12) + fs;
File java = new File(fileStart + fs + fullyQualifiedName + ".java");
File clazz = new File(fileStart2 + fs + fullyQualifiedName + ".class");
File cp = new File(tempDirectory + fs + "cpath_" + MiscUtils.randomString(12) + ".jar");
File tempD = new File(fileStart + fs + fullyQualifiedName.substring(0, fullyQualifiedName.length() - fullyQualifiedName.split("/")[fullyQualifiedName.split("/").length - 1].length()));
String fileStart = TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(12) + FS;
String fileStart2 = TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(12) + FS;
File java = new File(fileStart + FS + fullyQualifiedName + ".java");
File clazz = new File(fileStart2 + FS + fullyQualifiedName + ".class");
File cp = new File(TEMP_DIRECTORY + FS + "cpath_" + MiscUtils.randomString(12) + ".jar");
File tempD = new File(fileStart + FS + fullyQualifiedName.substring(0, fullyQualifiedName.length() -
fullyQualifiedName.split("/")[fullyQualifiedName.split("/").length - 1].length()));
tempD.mkdirs();
new File(fileStart2).mkdirs();
if (Configuration.javac.isEmpty() || !new File(Configuration.javac).exists())
{
BytecodeViewer.showMessage("You need to set your Javac path, this requires the JDK to be downloaded." + nl + "(C:/Program Files/Java/JDK_xx/bin/javac.exe)");
BytecodeViewer.showMessage("You need to set your Javac path, this requires the JDK to be downloaded." + NL + "(C:/Program Files/Java/JDK_xx/bin/javac.exe)");
ExternalResources.getSingleton().selectJavac();
}
@ -75,13 +76,11 @@ public class JavaCompiler extends InternalCompiler
ProcessBuilder pb;
if (Configuration.library.isEmpty())
{
pb = new ProcessBuilder(Configuration.javac, "-d", fileStart2, "-classpath", cp.getAbsolutePath(), java.getAbsolutePath());
}
pb = new ProcessBuilder(Configuration.javac, "-d", fileStart2,
"-classpath", cp.getAbsolutePath(), java.getAbsolutePath());
else
{
pb = new ProcessBuilder(Configuration.javac, "-d", fileStart2, "-classpath", cp.getAbsolutePath() + System.getProperty("path.separator") + Configuration.library, java.getAbsolutePath());
}
pb = new ProcessBuilder(Configuration.javac, "-d", fileStart2,
"-classpath", cp.getAbsolutePath() + System.getProperty("path.separator") + Configuration.library, java.getAbsolutePath());
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);
@ -102,22 +101,26 @@ public class JavaCompiler extends InternalCompiler
int exitValue = process.waitFor();
//Read out dir output
try (InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
log.append(nl).append(line);
log.append(NL).append(line);
}
log.append(nl).append(nl).append(TranslatedStrings.ERROR2).append(nl).append(nl);
try (InputStream is = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
log.append(NL).append(NL).append(TranslatedStrings.ERROR2).append(NL).append(NL);
try (InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
log.append(nl).append(line);
log.append(NL).append(line);
}
log.append(nl).append(nl).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
System.out.println(log);
if (!clazz.exists())

View File

@ -51,16 +51,16 @@ public class KrakatauAssembler extends InternalCompiler
if (!ExternalResources.getSingleton().hasSetPython2Command())
return null;
File tempD = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs);
File tempD = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS);
tempD.mkdir();
File tempJ = new File(tempD.getAbsolutePath() + fs + fullyQualifiedName + ".j");
File tempJ = new File(tempD.getAbsolutePath() + FS + fullyQualifiedName + ".j");
DiskWriter.replaceFile(tempJ.getAbsolutePath(), contents, true);
final File tempDirectory = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs);
final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS);
tempDirectory.mkdir();
final File tempJar = new File(Constants.tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".jar");
final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
StringBuilder log = new StringBuilder();
@ -72,29 +72,33 @@ public class KrakatauAssembler extends InternalCompiler
pythonCommands = ArrayUtils.addAll(pythonCommands, "-2");
ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3
krakatauWorkingDirectory + fs + "assemble.py", "-out", tempDirectory.getAbsolutePath(), tempJ.getAbsolutePath()));
krakatauWorkingDirectory + FS + "assemble.py", "-out", tempDirectory.getAbsolutePath(), tempJ.getAbsolutePath()));
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);
//Read out dir output
try (InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
log.append(nl).append(line);
log.append(NL).append(line);
}
log.append(nl).append(nl).append(TranslatedStrings.ERROR2).append(nl).append(nl);
try (InputStream is = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
log.append(NL).append(NL).append(TranslatedStrings.ERROR2).append(NL).append(NL);
try (InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
log.append(nl).append(line);
log.append(NL).append(line);
}
int exitValue = process.waitFor();
log.append(nl).append(nl).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
System.err.println(log);
byte[] b = FileUtils.readFileToByteArray(Objects.requireNonNull(ExternalResources.getSingleton().findFile(tempDirectory, ".class")));

View File

@ -30,8 +30,8 @@ import the.bytecode.club.bytecodeviewer.util.ZipUtils;
import java.io.File;
import java.util.Objects;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* Smali Assembler Wrapper for Java
@ -44,16 +44,16 @@ public class SmaliAssembler extends InternalCompiler
@Override
public byte[] compile(String contents, String fullyQualifiedName)
{
String fileStart = tempDirectory + fs + "temp";
String fileStart = TEMP_DIRECTORY + FS + "temp";
int fileNumber = MiscUtils.getClassNumber(fileStart, ".dex");
final File tempSmaliFolder = new File(fileStart + fileNumber + "-smalifolder" + fs);
final File tempSmaliFolder = new File(fileStart + fileNumber + "-smalifolder" + FS);
tempSmaliFolder.mkdir();
File tempSmali = new File(tempSmaliFolder.getAbsolutePath() + fs + fileNumber + ".smali");
File tempSmali = new File(tempSmaliFolder.getAbsolutePath() + FS + fileNumber + ".smali");
File tempDex = new File("./out.dex");
File tempJar = new File(fileStart + fileNumber + ".jar");
File tempJarFolder = new File(fileStart + fileNumber + "-jar" + fs);
File tempJarFolder = new File(fileStart + fileNumber + "-jar" + FS);
try
{

View File

@ -29,8 +29,23 @@ public enum Decompiler
{
//TODO WARNING: do not change the decompiler order, when adding a new decompiler just add it to the end
// enum ordinal is used for settings serialization instead of the enum name
NONE("None", "", null), PROCYON_DECOMPILER("Procyon Decompiler", "proycon", new ProcyonDecompiler()), CFR_DECOMPILER("CFR Decompiler", "cfr", new CFRDecompiler()), FERNFLOWER_DECOMPILER("FernFlower Decompiler", "fernflower", new FernFlowerDecompiler()), BYTECODE_DISASSEMBLER("Bytecode Disassembler", "bcvbd", new BytecodeDisassembler()), HEXCODE_VIEWER("Hexcode Viewer", "bcvhex", null), SMALI_DISASSEMBLER("Smali Disassembler", "smali", new SmaliDisassembler()), KRAKATAU_DECOMPILER("Krakatau Decompiler", "krakatau", new KrakatauDecompiler()), KRAKATAU_DISASSEMBLER("Krakatau Disassembler", "krakataud", new KrakatauDisassembler()), JD_DECOMPILER("JD-GUI Decompiler", "jdgui", new JDGUIDecompiler()), JADX_DECOMPILER("JADX Decompiler", "jadx", new JADXDecompiler()), ASM_TEXTIFY_DISASSEMBLER("ASM Disassembler", "asm", new ASMTextifierDisassembler()), ASMIFIER_DECOMPILER("ASMifier Generator", "asmifier", new ASMifierGenerator()), JAVAP_DISASSEMBLER("Javap Disassembler", "javap", new JavapDisassembler()),
;
NONE("None", "", null),
PROCYON_DECOMPILER("Procyon Decompiler", "proycon", new ProcyonDecompiler()),
CFR_DECOMPILER("CFR Decompiler", "cfr", new CFRDecompiler()),
FERNFLOWER_DECOMPILER("FernFlower Decompiler", "fernflower", new FernFlowerDecompiler()),
BYTECODE_DISASSEMBLER("Bytecode Disassembler", "bcvbd", new BytecodeDisassembler()),
HEXCODE_VIEWER("Hexcode Viewer", "bcvhex", null),
SMALI_DISASSEMBLER("Smali Disassembler", "smali", new SmaliDisassembler()),
KRAKATAU_DECOMPILER("Krakatau Decompiler", "krakatau", new KrakatauDecompiler()),
KRAKATAU_DISASSEMBLER("Krakatau Disassembler", "krakataud", new KrakatauDisassembler()),
JD_DECOMPILER("JD-GUI Decompiler", "jdgui", new JDGUIDecompiler()),
JADX_DECOMPILER("JADX Decompiler", "jadx", new JADXDecompiler()),
ASM_TEXTIFY_DISASSEMBLER("ASM Disassembler", "asm", new ASMTextifierDisassembler()),
ASMIFIER_DECOMPILER("ASMifier Generator", "asmifier", new ASMifierGenerator()),
JAVAP_DISASSEMBLER("Javap Disassembler", "javap", new JavapDisassembler());
private final String decompilerName;
private final String decompilerNameProgrammic;

View File

@ -29,7 +29,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import java.util.ArrayList;
import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* @author Konloch
@ -45,6 +45,7 @@ public class ClassNodeDecompiler
sb.append(getAccessString(cn.access));
sb.append(" ");
sb.append(cn.name);
if (cn.superName != null && !cn.superName.equals("java/lang/Object"))
{
sb.append(" extends ");
@ -52,34 +53,37 @@ public class ClassNodeDecompiler
}
int amountOfInterfaces = cn.interfaces.size();
if (amountOfInterfaces > 0)
{
sb.append(" implements ");
sb.append(cn.interfaces.get(0));
for (int i = 1; i < amountOfInterfaces; i++)
{
sb.append(", ");
sb.append(cn.interfaces.get(i));
}
}
sb.append(" {");
sb.append(nl);
sb.append(NL);
sb.append(" ");
sb.append("<ClassVersion=" + cn.version + ">");
sb.append(nl);
sb.append(NL);
if (cn.sourceDebug != null)
{
sb.append(" ");
sb.append("<SourceDebug=" + cn.sourceDebug + ">");
sb.append(nl);
sb.append(NL);
}
if (cn.sourceFile != null)
{
sb.append(" ");
sb.append("<SourceFile=" + cn.sourceFile + ">");
sb.append(nl);
sb.append(NL);
}
if (cn.signature != null)
@ -90,17 +94,19 @@ public class ClassNodeDecompiler
for (FieldNode fn : cn.fields)
{
sb.append(nl);
sb.append(NL);
sb.append(" ");
FieldNodeDecompiler.decompile(sb, fn);
}
if (cn.fields.size() > 0)
{
sb.append(nl);
sb.append(NL);
}
for (MethodNode mn : cn.methods)
{
sb.append(nl);
sb.append(NL);
MethodNodeDecompiler.decompile(sb, mn, cn);
}
@ -111,13 +117,14 @@ public class ClassNodeDecompiler
{
decompiledClasses.add(innerClassName);
ClassNode cn1 = BytecodeViewer.blindlySearchForClassNode(innerClassName);
if (cn1 != null)
{
sb.appendPrefix(" ");
sb.append(nl + nl);
sb.append(NL + NL);
sb = decompile(sb, decompiledClasses, cn1);
sb.trimPrefix(5);
sb.append(nl);
sb.append(NL);
}
else
{
@ -129,21 +136,24 @@ public class ClassNodeDecompiler
if (!unableToDecompile.isEmpty())
{
sb.append("// The following inner classes couldn't be decompiled: ");
for (String s : unableToDecompile)
{
sb.append(s);
sb.append(" ");
}
sb.append(nl);
sb.append(NL);
}
if (cn.attrs != null)
{
sb.append(nl);
sb.append(NL);
for (Attribute attr : cn.attrs)
{
//TODO: finish attributes
sb.append(attr.type + ": ");// + attr.content.toString());
sb.append(attr.type + ": "); // + attr.content.toString());
}
}
@ -157,6 +167,7 @@ public class ClassNodeDecompiler
public static String getAccessString(int access)
{
List<String> tokens = new ArrayList<>();
if ((access & Opcodes.ACC_PUBLIC) != 0)
tokens.add("public");
if ((access & Opcodes.ACC_PRIVATE) != 0)
@ -182,11 +193,13 @@ public class ClassNodeDecompiler
// hackery delimeters
StringBuilder sb = new StringBuilder(tokens.get(0));
for (int i = 1; i < tokens.size(); i++)
{
sb.append(" ");
sb.append(tokens.get(i));
}
return sb.toString();
}
}

View File

@ -33,7 +33,6 @@ import java.util.Arrays;
*/
public class InstructionPattern implements Opcodes
{
/**
* Last instruction-match position pointer
**/
@ -67,6 +66,7 @@ public class InstructionPattern implements Opcodes
{
filters = new InstructionFilter[opcodes.length];
lastMatch = new AbstractInsnNode[opcodes.length];
for (int i = 0; i < opcodes.length; i++)
{
filters[i] = new OpcodeFilter(opcodes[i]);
@ -100,16 +100,17 @@ public class InstructionPattern implements Opcodes
if (filter.accept(ain))
{
lastMatch[pointer] = ain;
if (pointer >= (filters.length - 1))
{
return true;
}
pointer++;
}
else
{
reset();
}
return false;
}
@ -150,10 +151,12 @@ public class InstructionPattern implements Opcodes
public static InstructionFilter[] translate(AbstractInsnNode[] ains)
{
InstructionFilter[] filters = new InstructionFilter[ains.length];
for (int i = 0; i < ains.length; i++)
{
filters[i] = translate(ains[i]);
}
return filters;
}
@ -167,63 +170,38 @@ public class InstructionPattern implements Opcodes
public static InstructionFilter translate(AbstractInsnNode ain)
{
if (ain instanceof LdcInsnNode)
{
return new LdcInstructionFilter(((LdcInsnNode) ain).cst);
}
else if (ain instanceof TypeInsnNode)
{
return new TypeInstructionFilter(ain.getOpcode(), ((TypeInsnNode) ain).desc);
}
else if (ain instanceof FieldInsnNode)
{
return new FieldInstructionFilter(ain.getOpcode(), ((FieldInsnNode) ain).owner, ((FieldInsnNode) ain).name, ((FieldInsnNode) ain).desc);
}
else if (ain instanceof MethodInsnNode)
{
return new MethodInstructionFilter(ain.getOpcode(), ((MethodInsnNode) ain).owner, ((MethodInsnNode) ain).name, ((MethodInsnNode) ain).desc);
}
else if (ain instanceof VarInsnNode)
{
return new VarInstructionFilter(ain.getOpcode(), ((VarInsnNode) ain).var);
}
else if (ain instanceof InsnNode)
{
return new InsnInstructionFilter(ain.getOpcode());
}
else if (ain instanceof IincInsnNode)
{
return new IincInstructionFilter(((IincInsnNode) ain).incr, ((IincInsnNode) ain).var);
}
else if (ain instanceof JumpInsnNode)
{
return new JumpInstructionFilter(ain.getOpcode());
}
else if (ain instanceof LabelNode)
{
return InstructionFilter.ACCEPT_ALL; // TODO: Cache labels and
// check. // TODO: That's a
// fucking stupid idea.
}
else if (ain instanceof MultiANewArrayInsnNode)
{
return new MultiANewArrayInstructionFilter(((MultiANewArrayInsnNode) ain).desc, ((MultiANewArrayInsnNode) ain).dims);
}
else
{
return InstructionFilter.ACCEPT_ALL;
}
else if (ain instanceof MultiANewArrayInsnNode)
return new MultiANewArrayInstructionFilter(((MultiANewArrayInsnNode) ain).desc, ((MultiANewArrayInsnNode) ain).dims);
else
return InstructionFilter.ACCEPT_ALL;
}
public static void main(String[] args)
{
AbstractInsnNode[] ains = new AbstractInsnNode[]{new LdcInsnNode("ldc"), new VarInsnNode(ASTORE, 0), new LdcInsnNode("ldc")};
AbstractInsnNode[] abstractInsnNodes = new AbstractInsnNode[]{new LdcInsnNode("ldc"), new VarInsnNode(ASTORE, 0), new LdcInsnNode("ldc")};
InstructionPattern pattern = new InstructionPattern(new AbstractInsnNode[]{new LdcInsnNode("ldc"), new VarInsnNode(-1, -1)});
for (AbstractInsnNode ain : ains)
for (AbstractInsnNode insnNode : abstractInsnNodes)
{
if (pattern.accept(ain))
{
if (pattern.accept(insnNode))
System.out.println(Arrays.toString(pattern.getLastMatch()));
}
}
}
}

View File

@ -111,6 +111,7 @@ public class JavaBytecodeTokenMaker extends AbstractJFlexCTokenMaker
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l)
{
int count = packed.charAt(i++);

View File

@ -27,7 +27,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* @author Konloch
@ -39,15 +39,11 @@ public class MethodNodeDecompiler
public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, MethodNode m, ClassNode cn)
{
String class_;
String className;
if (cn.name.contains("/"))
{
class_ = cn.name.substring(cn.name.lastIndexOf("/") + 1);
}
className = cn.name.substring(cn.name.lastIndexOf("/") + 1);
else
{
class_ = cn.name;
}
className = cn.name;
String s = getAccessString(m.access);
sb.append(" ");
@ -56,9 +52,7 @@ public class MethodNodeDecompiler
sb.append(" ");
if (m.name.equals("<init>"))
{
sb.append(class_);
}
sb.append(className);
else if (!m.name.equals("<clinit>"))
{
Type returnType = Type.getReturnType(m.desc);
@ -111,7 +105,7 @@ public class MethodNodeDecompiler
sb.append(" {}");
sb.append(" //");
sb.append(m.desc);
sb.append(nl);
sb.append(NL);
}
else
{
@ -129,18 +123,18 @@ public class MethodNodeDecompiler
sb.append(" //");
sb.append(m.desc);
sb.append(nl);
sb.append(NL);
if (m.signature != null)
{
sb.append(" <sig:").append(m.signature).append(">");
sb.append(nl);
sb.append(NL);
}
if (m.annotationDefault != null)
{
sb.append(m.annotationDefault);
sb.append(nl);
sb.append(NL);
}
InstructionPrinter insnPrinter = new InstructionPrinter(m, args);
@ -155,6 +149,7 @@ public class MethodNodeDecompiler
addAttrList(m.visibleTypeAnnotations, "visTypeAnno", sb, insnPrinter);
List<TryCatchBlockNode> tryCatchBlocks = m.tryCatchBlocks;
for (int i = 0; i < tryCatchBlocks.size(); i++)
{
TryCatchBlockNode o = tryCatchBlocks.get(i);
@ -170,15 +165,16 @@ public class MethodNodeDecompiler
sb.append(o.type);
else
sb.append("Type is null.");
sb.append(nl);
sb.append(NL);
}
for (String insn : insnPrinter.createPrint())
{
sb.append(" ");
sb.append(insn);
sb.append(nl);
sb.append(NL);
}
sb.append(" }" + nl);
sb.append(" }" + NL);
}
return sb;
}
@ -196,9 +192,9 @@ public class MethodNodeDecompiler
sb.append(":");
sb.append(printAttr(o, insnPrinter));
sb.append(">");
sb.append(nl);
sb.append(NL);
}
sb.append(nl);
sb.append(NL);
}
}

View File

@ -43,7 +43,7 @@ import java.util.jar.JarFile;
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.CFR;
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.ERROR;
@ -86,7 +86,7 @@ public class CFRDecompiler extends InternalDecompiler
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
return CFR + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + sw;
return CFR + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + sw;
}
}

View File

@ -46,18 +46,18 @@ public class FernFlowerDecompiler extends InternalDecompiler
{
File tempZip = new File(sourceJar);
File f = new File(tempDirectory + fs + "temp" + fs);
File f = new File(TEMP_DIRECTORY + FS + "temp" + FS);
f.mkdir();
try
{
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempZip.getAbsolutePath(), tempDirectory + "./temp/"));
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempZip.getAbsolutePath(), TEMP_DIRECTORY + "./temp/"));
}
catch (StackOverflowError | Exception ignored)
{
}
File tempZip2 = new File(tempDirectory + fs + "temp" + fs + tempZip.getName());
File tempZip2 = new File(TEMP_DIRECTORY + FS + "temp" + FS + tempZip.getName());
if (tempZip2.exists())
tempZip2.renameTo(new File(zipName));
@ -67,7 +67,7 @@ public class FernFlowerDecompiler extends InternalDecompiler
@Override
public String decompileClassNode(ClassNode cn, byte[] b)
{
String start = tempDirectory + fs + MiscUtils.getUniqueName("", ".class");
String start = TEMP_DIRECTORY + FS + MiscUtils.getUniqueName("", ".class");
final File tempClass = new File(start + ".class");
@ -108,7 +108,7 @@ public class FernFlowerDecompiler extends InternalDecompiler
{
try
{
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempClass.getAbsolutePath(), new File(tempDirectory).getAbsolutePath()));
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempClass.getAbsolutePath(), new File(TEMP_DIRECTORY).getAbsolutePath()));
}
catch (Throwable e)
{
@ -124,7 +124,7 @@ public class FernFlowerDecompiler extends InternalDecompiler
String javaDir = start;
if (BytecodeViewer.viewer.ren.isSelected())
{
javaDir = tempDirectory + "class_0";
javaDir = TEMP_DIRECTORY + "class_0";
}
final File outputJava = new File(javaDir + ".java");
@ -145,11 +145,11 @@ public class FernFlowerDecompiler extends InternalDecompiler
e.printStackTrace(new PrintWriter(exceptionWriter));
e.printStackTrace();
exception += nl + nl + exceptionWriter;
exception += NL + NL + exceptionWriter;
}
}
return FERNFLOWER + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + exception;
return FERNFLOWER + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
private String[] generateMainMethod(String className, String folder)

View File

@ -47,7 +47,7 @@ public class JADXDecompiler extends InternalDecompiler
@Override
public String decompileClassNode(ClassNode cn, byte[] b)
{
String fileStart = tempDirectory + fs;
String fileStart = TEMP_DIRECTORY + FS;
String exception = "";
final File tempClass = new File(MiscUtils.getUniqueName(fileStart, ".class") + ".class");
@ -92,7 +92,7 @@ public class JADXDecompiler extends InternalDecompiler
if (exception.isEmpty())
exception = "Decompiled source file not found!";
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + exception;
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
//TODO remove
@ -129,13 +129,13 @@ public class JADXDecompiler extends InternalDecompiler
e.printStackTrace();
String exception = ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + exception;
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
return s;
}
}
return "JADX error!" + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR;
return "JADX error!" + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR;
}
@Override

View File

@ -34,8 +34,8 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import java.io.*;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.ERROR;
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.JDGUI;
@ -55,19 +55,19 @@ public class JDGUIDecompiler extends InternalDecompiler
String exception;
try
{
final File tempDirectory = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs);
final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS);
tempDirectory.mkdir();
final File tempClass = new File(tempDirectory.getAbsolutePath() + fs + cn.name + ".class");
final File tempJava = new File(tempDirectory.getAbsolutePath() + fs + cn.name + ".java");
final File tempClass = new File(tempDirectory.getAbsolutePath() + FS + cn.name + ".class");
final File tempJava = new File(tempDirectory.getAbsolutePath() + FS + cn.name + ".java");
if (cn.name.contains("/"))
{
String[] raw = cn.name.split("/");
String path = tempDirectory.getAbsolutePath() + fs;
String path = tempDirectory.getAbsolutePath() + FS;
for (int i = 0; i < raw.length - 1; i++)
{
path += raw[i] + fs;
path += raw[i] + FS;
File f = new File(path);
f.mkdir();
}
@ -124,7 +124,7 @@ public class JDGUIDecompiler extends InternalDecompiler
exception = ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
}
return JDGUI + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + exception;
return JDGUI + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
@Override

View File

@ -34,7 +34,7 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.api.ExceptionUI.SEND_STACKTRACE_TO;
/**
@ -59,9 +59,9 @@ public class JavapDisassembler extends InternalDecompiler
private synchronized String synchronizedDecompilation(ClassNode cn, byte[] b)
{
final File tempDirectory = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs);
final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS);
tempDirectory.mkdir();
final File tempClass = new File(Constants.tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".class");
final File tempClass = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".class");
DiskWriter.replaceFileBytes(tempClass.getAbsolutePath(), b, false);

View File

@ -91,48 +91,52 @@ public class KrakatauDecompiler extends InternalDecompiler
pythonCommands = ArrayUtils.addAll(pythonCommands, "-2");
ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3
krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3
krakatauWorkingDirectory + FS + "decompile.py", "-skip", //love you storyyeller <3
"-nauto", "-path", Configuration.rt + ";" + krakatauTempJar.getAbsolutePath() + buildCLIArguments(), "-out", krakatauTempDir.getAbsolutePath(), cn.name + ".class"));
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);
StringBuilder log = new StringBuilder(TranslatedStrings.PROCESS2 + nl + nl);
StringBuilder log = new StringBuilder(TranslatedStrings.PROCESS2 + NL + NL);
//Read out dir output
try (InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
{
log.append(nl).append(line);
log.append(NL).append(line);
}
}
log.append(nl).append(nl).append(TranslatedStrings.ERROR2).append(nl).append(nl);
log.append(NL).append(NL).append(TranslatedStrings.ERROR2).append(NL).append(NL);
try (InputStream is = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
{
log.append(nl).append(line);
log.append(NL).append(line);
}
}
int exitValue = process.waitFor();
log.append(nl).append(nl).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
s = log.toString();
//if the motherfucker failed this'll fail, aka wont set.
s = DiskReader.loadAsString(krakatauTempDir.getAbsolutePath() + fs + cn.name + ".java");
s = DiskReader.loadAsString(krakatauTempDir.getAbsolutePath() + FS + cn.name + ".java");
}
catch (Exception e)
{
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
e.printStackTrace();
s += nl + ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
s += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
}
return s;
@ -160,9 +164,9 @@ public class KrakatauDecompiler extends InternalDecompiler
String s = ExceptionUI.SEND_STACKTRACE_TO_NL;
final File tempDirectory = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs);
final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS);
tempDirectory.mkdir();
final File tempJar = new File(Constants.tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".jar");
final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar");
JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
@ -173,41 +177,45 @@ public class KrakatauDecompiler extends InternalDecompiler
pythonCommands = ArrayUtils.addAll(pythonCommands, "-2");
ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3
krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3
krakatauWorkingDirectory + FS + "decompile.py", "-skip", //love you storyyeller <3
"-nauto", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath() + buildCLIArguments(), "-out", tempDirectory.getAbsolutePath(), cn.name + ".class"));
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);
StringBuilder log = new StringBuilder(TranslatedStrings.PROCESS2 + nl + nl);
StringBuilder log = new StringBuilder(TranslatedStrings.PROCESS2 + NL + NL);
//Read out dir output
try (InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
{
log.append(nl).append(line);
log.append(NL).append(line);
}
}
log.append(nl).append(nl).append(TranslatedStrings.ERROR2).append(nl).append(nl);
log.append(NL).append(NL).append(TranslatedStrings.ERROR2).append(NL).append(NL);
try (InputStream is = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
{
log.append(nl).append(line);
log.append(NL).append(line);
}
}
int exitValue = process.waitFor();
log.append(nl).append(nl).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
s = log.toString();
//if the motherfucker failed this'll fail, aka wont set.
s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + fs + cn.name + ".java");
s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + FS + cn.name + ".java");
tempDirectory.delete();
tempJar.delete();
}
@ -216,7 +224,7 @@ public class KrakatauDecompiler extends InternalDecompiler
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
e.printStackTrace();
s += nl + ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
s += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
}
return s;
@ -236,7 +244,7 @@ public class KrakatauDecompiler extends InternalDecompiler
}
String ran = MiscUtils.randomString(32);
final File tempDirectory = new File(Constants.tempDirectory + fs + ran + fs);
final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + ran + FS);
tempDirectory.mkdir();
final File tempJar = new File(sourceJar);
@ -248,7 +256,7 @@ public class KrakatauDecompiler extends InternalDecompiler
pythonCommands = ArrayUtils.addAll(pythonCommands, "-2");
ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3
krakatauWorkingDirectory + fs + "decompile.py", "-skip", //love you storyyeller <3
krakatauWorkingDirectory + FS + "decompile.py", "-skip", //love you storyyeller <3
"-nauto", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), tempJar.getAbsolutePath()));
Process process = pb.start();

View File

@ -52,9 +52,9 @@ public class KrakatauDisassembler extends InternalDecompiler
String s = ExceptionUI.SEND_STACKTRACE_TO_NL;
final File tempDirectory = new File(Constants.tempDirectory + fs + MiscUtils.randomString(32) + fs);
final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS);
tempDirectory.mkdir();
final File tempJar = new File(Constants.tempDirectory + fs + "temp" + MiscUtils.randomString(32) + ".jar");
final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar");
JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
try
@ -64,47 +64,51 @@ public class KrakatauDisassembler extends InternalDecompiler
pythonCommands = ArrayUtils.addAll(pythonCommands, "-2");
ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3
krakatauWorkingDirectory + fs + "disassemble.py", "-path", tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), cn.name + ".class"));
krakatauWorkingDirectory + FS + "disassemble.py", "-path", tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), cn.name + ".class"));
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);
StringBuilder log = new StringBuilder(TranslatedStrings.PROCESS2 + nl + nl);
StringBuilder log = new StringBuilder(TranslatedStrings.PROCESS2 + NL + NL);
//Read out dir output
try (InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
{
log.append(nl).append(line);
log.append(NL).append(line);
}
}
log.append(nl).append(nl).append(TranslatedStrings.ERROR2).append(nl).append(nl);
log.append(NL).append(NL).append(TranslatedStrings.ERROR2).append(NL).append(NL);
try (InputStream is = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
{
log.append(nl).append(line);
log.append(NL).append(line);
}
}
int exitValue = process.waitFor();
log.append(nl).append(nl).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue);
s = log.toString();
// if the motherfucker failed this'll fail, aka won't set.
s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + fs + cn.name + ".j");
s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + FS + cn.name + ".j");
}
catch (Exception e)
{
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
e.printStackTrace();
s += nl + ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
s += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
}
return s;
}
@ -116,7 +120,7 @@ public class KrakatauDisassembler extends InternalDecompiler
return;
String ran = MiscUtils.randomString(32);
final File tempDirectory = new File(Constants.tempDirectory + fs + ran + fs);
final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + ran + FS);
tempDirectory.mkdir();
final File tempJar = new File(sourceJar);
@ -128,7 +132,7 @@ public class KrakatauDisassembler extends InternalDecompiler
pythonCommands = ArrayUtils.addAll(pythonCommands, "-2");
ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3
krakatauWorkingDirectory + fs + "disassemble.py", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), tempJar.getAbsolutePath()));
krakatauWorkingDirectory + FS + "disassemble.py", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), tempJar.getAbsolutePath()));
Process process = pb.start();
BytecodeViewer.createdProcesses.add(process);

View File

@ -80,7 +80,7 @@ public class ProcyonDecompiler extends InternalDecompiler
String exception;
try
{
String fileStart = tempDirectory + fs + "temp";
String fileStart = TEMP_DIRECTORY + FS + "temp";
final File tempClass = new File(MiscUtils.getUniqueName(fileStart, ".class") + ".class");
@ -121,7 +121,7 @@ public class ProcyonDecompiler extends InternalDecompiler
exception = ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
}
return PROCYON + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + exception;
return PROCYON + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
@Override

View File

@ -47,7 +47,7 @@ public class SmaliDisassembler extends InternalDecompiler
public String decompileClassNode(ClassNode cn, byte[] b)
{
String exception = "";
String fileStart = tempDirectory + fs + "temp";
String fileStart = TEMP_DIRECTORY + FS + "temp";
String start = MiscUtils.getUniqueName(fileStart, ".class");
@ -124,7 +124,7 @@ public class SmaliDisassembler extends InternalDecompiler
exception += ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
}
return SMALI + " " + DISASSEMBLER + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + exception;
return SMALI + " " + DISASSEMBLER + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
@Override

View File

@ -63,7 +63,7 @@ import java.util.Map;
import static the.bytecode.club.bytecodeviewer.Configuration.useNewSettingsDialog;
import static the.bytecode.club.bytecodeviewer.Constants.VERSION;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
/**
* The main file for the GUI
@ -907,7 +907,7 @@ public class MainViewerGUI extends JFrame
for (ResourceContainer container : BytecodeViewer.resourceContainers.values())
{
File newFile = new File(container.file.getParent() + fs + container.name);
File newFile = new File(container.file.getParent() + FS + container.name);
if (!container.file.getAbsolutePath().equals(newFile.getAbsolutePath()) && (container.file.getAbsolutePath().endsWith(".apk") || container.file.getAbsolutePath().endsWith(".dex"))) //APKs & dex get renamed
{
container.file.renameTo(newFile);

View File

@ -25,7 +25,7 @@ import javax.swing.*;
import java.awt.*;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* A simple swing JFrame console
@ -130,7 +130,7 @@ public class JFrameConsole extends JFrame
{
//TODO if two consoles are ran at the same time and exceed the maximum this file will be overwritten
final File tempFile = new File(tempDirectory, "console_" + consoleID + ".log");
final File tempFile = new File(TEMP_DIRECTORY, "console_" + consoleID + ".log");
//TODO this needs to be rewritten, it doesn't work for a plugin that causes multiple exception UIs
new Thread(() ->

View File

@ -23,7 +23,7 @@ import the.bytecode.club.bytecodeviewer.Constants;
import javax.swing.*;
import java.io.PrintStream;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* A swing console that can print out from PrintStreams
@ -136,7 +136,7 @@ public class JFrameConsolePrintStream extends JFrameConsole
String start = split[0] + "'" + split[1] + "', ";
s = s.substring(start.length());
}
replace.append(s).append(nl);
replace.append(s).append(NL);
}
setText(replace.toString());

View File

@ -47,8 +47,8 @@ import java.io.File;
import java.util.Enumeration;
import java.util.Map.Entry;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* The file navigation pane.
@ -379,7 +379,7 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File
//TODO make a settings toggle to disable preservation of the original name
// it should also detect if the file name is not compatible with the current OS and enable automatically
File tempFile = new File(tempDirectory + fs + hash + fs + name + "." + extension);
File tempFile = new File(TEMP_DIRECTORY + FS + hash + FS + name + "." + extension);
if (!tempFile.exists())
{
DiskWriter.replaceFileBytes(tempFile.getAbsolutePath(), content, false);

View File

@ -31,7 +31,7 @@ import the.bytecode.club.bytecodeviewer.util.JarUtils;
import javax.swing.*;
import java.awt.*;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Represents a Bytecode/ClassFile View Panel
@ -79,7 +79,7 @@ public class BytecodeViewPanel extends JPanel
return true;
SystemConsole errConsole = new SystemConsole(TranslatedStrings.JAVA_COMPILE_FAILED.toString());
errConsole.setText(TranslatedStrings.ERROR_COMPILING_CLASS + " " + viewer.resource.getResourceClassNode().name + nl + TranslatedStrings.COMPILER_TIP + nl + nl + TranslatedStrings.SUGGESTED_FIX_COMPILER_ERROR + nl + nl);
errConsole.setText(TranslatedStrings.ERROR_COMPILING_CLASS + " " + viewer.resource.getResourceClassNode().name + NL + TranslatedStrings.COMPILER_TIP + NL + NL + TranslatedStrings.SUGGESTED_FIX_COMPILER_ERROR + NL + NL);
try
{

View File

@ -104,7 +104,9 @@ public class Workspace extends TranslatedVisibleComponent
private void addResource(ResourceContainer container, String name, ResourceViewer resourceView)
{
// Warn user and prevent 'nothing' from opening if no Decompiler is selected
if (BytecodeViewer.viewer.viewPane1.getSelectedDecompiler() == Decompiler.NONE && BytecodeViewer.viewer.viewPane2.getSelectedDecompiler() == Decompiler.NONE && BytecodeViewer.viewer.viewPane3.getSelectedDecompiler() == Decompiler.NONE)
if (BytecodeViewer.viewer.viewPane1.getSelectedDecompiler() == Decompiler.NONE
&& BytecodeViewer.viewer.viewPane2.getSelectedDecompiler() == Decompiler.NONE
&& BytecodeViewer.viewer.viewPane3.getSelectedDecompiler() == Decompiler.NONE)
{
BytecodeViewer.showMessage(TranslatedStrings.SUGGESTED_FIX_NO_DECOMPILER_WARNING.toString());
return;

View File

@ -138,7 +138,9 @@ public class ClassViewer extends ResourceViewer
if (!BytecodeViewer.viewer.autoCompileOnRefresh.isSelected() && !BytecodeViewer.viewer.compileOnSave.isSelected())
{
BytecodeViewer.showMessage("Make sure to compile (File>Compile or Ctrl + T) whenever you want to " + "test or export your changes.\nYou can set compile automatically on refresh or on save " + "in the settings menu.");
BytecodeViewer.showMessage("Make sure to compile (File>Compile or Ctrl + T) whenever you want to "
+ "test or export your changes.\nYou can set compile automatically on refresh or on save "
+ "in the settings menu.");
SettingsSerializer.saveSettingsAsync();
}
@ -293,9 +295,7 @@ public class ClassViewer extends ResourceViewer
for (Component c : this.getComponents())
{
if (c instanceof BytecodeViewPanel || c instanceof JSplitPane)
{
this.remove(c);
}
}
this.sp.setResizeWeight(0.5);
@ -307,13 +307,17 @@ public class ClassViewer extends ResourceViewer
this.sp.setLeftComponent(bytecodeViewPanel1);
this.sp.setRightComponent(bytecodeViewPanel2);
this.add(sp, BorderLayout.CENTER);
} /* If panel 1 and panel 3 are ticked but not panel 2 */
}
/* If panel 1 and panel 3 are ticked but not panel 2 */
else if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE)
{
this.sp.setLeftComponent(bytecodeViewPanel1);
this.sp.setRightComponent(bytecodeViewPanel3);
this.add(sp, BorderLayout.CENTER);
} /* If panel 2 and panel 3 are ticked but not panel 1 */
}
/* If panel 2 and panel 3 are ticked but not panel 1 */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE)
{
this.sp.setLeftComponent(bytecodeViewPanel2);
@ -332,15 +336,25 @@ public class ClassViewer extends ResourceViewer
}
/* If view panel 1 is only ticked... */
if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE)
if (bytecodeViewPanel1.decompiler != Decompiler.NONE
&& bytecodeViewPanel2.decompiler == Decompiler.NONE
&& bytecodeViewPanel3.decompiler == Decompiler.NONE)
{
this.add(bytecodeViewPanel1, BorderLayout.CENTER);
} /* If view panel 2 is only ticked... */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE)
}
/* If view panel 2 is only ticked... */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE
&& bytecodeViewPanel2.decompiler != Decompiler.NONE
&& bytecodeViewPanel3.decompiler == Decompiler.NONE)
{
this.add(bytecodeViewPanel2, BorderLayout.CENTER);
} /* If view panel 3 is only ticked... */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE)
}
/* If view panel 3 is only ticked... */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE
&& bytecodeViewPanel2.decompiler == Decompiler.NONE
&& bytecodeViewPanel3.decompiler != Decompiler.NONE)
{
this.add(bytecodeViewPanel3, BorderLayout.CENTER);
}

View File

@ -58,7 +58,6 @@ public class FileViewer extends ResourceViewer
this.setName(name);
this.setLayout(new BorderLayout());
this.add(mainPanel, BorderLayout.CENTER);
setContents();
@ -69,7 +68,9 @@ public class FileViewer extends ResourceViewer
final byte[] contents = resource.getResourceBytes();
final String nameLowerCase = this.resource.name.toLowerCase();
final String onlyName = FilenameUtils.getName(nameLowerCase);
final boolean hexViewerOnly = BytecodeViewer.viewer.viewPane1.getSelectedDecompiler() == Decompiler.HEXCODE_VIEWER && BytecodeViewer.viewer.viewPane2.getSelectedDecompiler() == Decompiler.NONE && BytecodeViewer.viewer.viewPane3.getSelectedDecompiler() == Decompiler.NONE;
final boolean hexViewerOnly = BytecodeViewer.viewer.viewPane1.getSelectedDecompiler() == Decompiler.HEXCODE_VIEWER
&& BytecodeViewer.viewer.viewPane2.getSelectedDecompiler() == Decompiler.NONE
&& BytecodeViewer.viewer.viewPane3.getSelectedDecompiler() == Decompiler.NONE;
//image viewer
if (MiscUtils.guessIfBinary(contents) || hexViewerOnly)
@ -80,7 +81,6 @@ public class FileViewer extends ResourceViewer
// + ClassRead then quick-decompile using Pane1 Decompiler
// (If none selected, try Pane2, Pane3, default to Procyon)
//check by file extension to display image
if (!onlyName.contains(":") && ResourceType.imageExtensionMap.containsKey(FilenameUtils.getExtension(onlyName)) && !hexViewerOnly)
{

View File

@ -29,15 +29,18 @@ import java.util.Objects;
*/
public class MethodData
{
public String name, desc;
public String name;
public String desc;
@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof MethodData))
return false;
MethodData that = (MethodData) o;
return Objects.equals(name, that.name) && Objects.equals(desc, that.desc);
}
@ -51,11 +54,15 @@ public class MethodData
public String constructPattern()
{
final StringBuilder pattern = new StringBuilder();
pattern.append(name).append(" *\\(");
final org.objectweb.asm.Type[] types = org.objectweb.asm.Type.getArgumentTypes(desc);
pattern.append(name).append(" *\\(");
pattern.append("(.*)");
Arrays.stream(types).map(Type::getClassName).forEach(clazzName -> pattern.append(clazzName.substring(clazzName.lastIndexOf(".") + 1)).append("(.*)"));
Arrays.stream(types).map(Type::getClassName)
.forEach(clazzName -> pattern.append(clazzName.substring(clazzName.lastIndexOf(".") + 1))
.append("(.*)"));
pattern.append("\\) *\\{");
return pattern.toString();
}
}

View File

@ -45,7 +45,11 @@ public enum LAFTheme
SYSTEM("System Theme", RSTATheme.THEME_MATCH, TranslatedComponents.SYSTEM_THEME), //System theme
DARK("Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.DARK_THEME), //DarkLaf
LIGHT("Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.LIGHT_THEME), //Intellij theme
ONE_DARK("One Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.ONE_DARK_THEME), SOLARIZED_DARK("Solarized Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.SOLARIZED_DARK_THEME), SOLARIZED_LIGHT("Solarized Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.SOLARIZED_LIGHT_THEME), HIGH_CONTRAST_DARK("High Contrast Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_DARK_THEME), HIGH_CONTRAST_LIGHT("High Contrast Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_LIGHT_THEME),
ONE_DARK("One Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.ONE_DARK_THEME),
SOLARIZED_DARK("Solarized Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.SOLARIZED_DARK_THEME),
SOLARIZED_LIGHT("Solarized Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.SOLARIZED_LIGHT_THEME),
HIGH_CONTRAST_DARK("High Contrast Dark Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_DARK_THEME),
HIGH_CONTRAST_LIGHT("High Contrast Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_LIGHT_THEME),
;
private final String readableName;

View File

@ -36,11 +36,9 @@ public enum RSTATheme
{
//uses the darklaf RSyntaxTextArea extension
THEME_MATCH("Theme Match (Recommended)", null, TranslatedComponents.THEME_MATCH), //uses the default theme from RSyntaxTextArea
DEFAULT("Default (Recommended Light)", "/org/fife/ui/rsyntaxtextarea/themes/default.xml", TranslatedComponents.DEFAULT_RECOMMENDED_LIGHT), //uses the default dark theme from RSyntaxTextArea
DARK("Dark (Recommended Dark)", "/org/fife/ui/rsyntaxtextarea/themes/dark.xml", TranslatedComponents.DARK),
DEFAULT_ALT("Default-Alt", "/org/fife/ui/rsyntaxtextarea/themes/default-alt.xml", TranslatedComponents.DEFAULT_ALT), ECLIPSE("Eclipse", "/org/fife/ui/rsyntaxtextarea/themes/eclipse.xml", TranslatedComponents.ECLIPSE), IDEA("IntelliJ", "/org/fife/ui/rsyntaxtextarea/themes/idea.xml", TranslatedComponents.INTELLIJ), VS("Visual Studio", "/org/fife/ui/rsyntaxtextarea/themes/vs.xml", TranslatedComponents.VISUAL_STUDIO), DRUID("Druid (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/druid.xml", TranslatedComponents.DRUID_DARK), MONOKAI("Monokai (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/monokai.xml", TranslatedComponents.MONOKAI_DARK),
;
DEFAULT("Default (Recommended Light)", "/org/fife/ui/rsyntaxtextarea/themes/default.xml", TranslatedComponents.DEFAULT_RECOMMENDED_LIGHT), //uses the default dark theme from RSyntaxTextArea
DARK("Dark (Recommended Dark)", "/org/fife/ui/rsyntaxtextarea/themes/dark.xml", TranslatedComponents.DARK),
DEFAULT_ALT("Default-Alt", "/org/fife/ui/rsyntaxtextarea/themes/default-alt.xml", TranslatedComponents.DEFAULT_ALT), ECLIPSE("Eclipse", "/org/fife/ui/rsyntaxtextarea/themes/eclipse.xml", TranslatedComponents.ECLIPSE), IDEA("IntelliJ", "/org/fife/ui/rsyntaxtextarea/themes/idea.xml", TranslatedComponents.INTELLIJ), VS("Visual Studio", "/org/fife/ui/rsyntaxtextarea/themes/vs.xml", TranslatedComponents.VISUAL_STUDIO), DRUID("Druid (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/druid.xml", TranslatedComponents.DRUID_DARK), MONOKAI("Monokai (Dark)", "/org/fife/ui/rsyntaxtextarea/themes/monokai.xml", TranslatedComponents.MONOKAI_DARK);
private final String readableName;
private final String file;
@ -105,6 +103,7 @@ DARK("Dark (Recommended Dark)", "/org/fife/ui/rsyntaxtextarea/themes/dark.xml",
return t;
}
}
return DEFAULT;
}

View File

@ -109,15 +109,17 @@ public class BytecodeViewPanelUpdater implements Runnable
else
{
final Decompiler decompiler = bytecodeViewPanel.decompiler;
final String workingDecompilerName = viewer.resource.workingName + "-" + decompiler.getDecompilerName();
//perform decompiling inside of this thread
final String decompiledSource = decompiler.getDecompiler().decompileClassNode(viewer.resource.getResourceClassNode(), classBytes);
ClassFileContainer container = new ClassFileContainer(viewer.resource.workingName + "-" + decompiler.getDecompilerName(), decompiledSource, viewer.resource.container);
if (!BytecodeViewer.viewer.workPane.classFiles.containsKey(viewer.resource.workingName + "-" + decompiler.getDecompilerName()))
ClassFileContainer container = new ClassFileContainer(workingDecompilerName, decompiledSource, viewer.resource.container);
if (!BytecodeViewer.viewer.workPane.classFiles.containsKey(workingDecompilerName))
{
container.parse();
BytecodeViewer.viewer.workPane.classFiles.put(viewer.resource.workingName + "-" + decompiler.getDecompilerName(), container);
BytecodeViewer.viewer.workPane.classFiles.put(workingDecompilerName, container);
container.hasBeenParsed = true;
}
@ -180,7 +182,9 @@ public class BytecodeViewPanelUpdater implements Runnable
return;
//nullcheck broken pane
if (updateUpdaterTextArea == null || updateUpdaterTextArea.getScrollPane() == null || updateUpdaterTextArea.getScrollPane().getViewport() == null)
if (updateUpdaterTextArea == null
|| updateUpdaterTextArea.getScrollPane() == null
|| updateUpdaterTextArea.getScrollPane().getViewport() == null)
{
//build an error message
SwingUtilities.invokeLater(() -> buildTextArea(bytecodeViewPanel.decompiler, "Critical BCV Error"));
@ -252,6 +256,7 @@ public class BytecodeViewPanelUpdater implements Runnable
int activeLineDelta = -1;
MethodParser.Method activeMethod = null;
MethodParser activeMethods = viewer.methods.get(bytecodeViewPanel.panelIndex);
if (activeMethods != null)
{
int activeMethodLine = activeMethods.findActiveMethod(activeLine);
@ -262,6 +267,7 @@ public class BytecodeViewPanelUpdater implements Runnable
ClassViewer.selectMethod(updateUpdaterTextArea, activeMethodLine);
}
}
for (int i = 0; i < panes; i++)
{
if (i != bytecodeViewPanel.panelIndex)
@ -304,6 +310,7 @@ public class BytecodeViewPanelUpdater implements Runnable
{
setLine = activeLine;
}
if (setLine >= 0)
{
ClassViewer.setViewLine(area, setLine);
@ -329,10 +336,11 @@ public class BytecodeViewPanelUpdater implements Runnable
});
final MethodParser methods = viewer.methods.get(bytecodeViewPanel.panelIndex);
for (int i = 0; i < updateUpdaterTextArea.getLineCount(); i++)
{
String lineText = updateUpdaterTextArea.getLineText(i);
Matcher regexMatcher = MethodParser.regex.matcher(lineText);
Matcher regexMatcher = MethodParser.REGEX.matcher(lineText);
if (regexMatcher.find())
{
String methodName = regexMatcher.group("name");
@ -411,6 +419,7 @@ public class BytecodeViewPanelUpdater implements Runnable
tokenMakerFactory.putMapping("text/javaBytecode", "the.bytecode.club.bytecodeviewer.decompilers.bytecode.JavaBytecodeTokenMaker");
bytecodeViewPanel.textArea.setSyntaxEditingStyle("text/javaBytecode");
}
bytecodeViewPanel.textArea.setCodeFoldingEnabled(true);
bytecodeViewPanel.textArea.setText(decompiledSource);
bytecodeViewPanel.textArea.setCaretPosition(0);
@ -488,6 +497,7 @@ public class BytecodeViewPanelUpdater implements Runnable
RSyntaxTextAreaHighlighterEx highlighterEx = (RSyntaxTextAreaHighlighterEx) textArea.getHighlighter();
Token token = textArea.modelToToken(textArea.getCaretPosition());
if (token == null)
{
token = textArea.modelToToken(textArea.getCaretPosition() - 1);

View File

@ -23,7 +23,7 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareCodeScanner;
import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareScan;
import the.bytecode.club.bytecodeviewer.malwarescanner.util.SearchableString;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Scans for any trace of java/awt/Robot inside of method instructions and strings
@ -37,14 +37,14 @@ public class AWTRobotScanner extends MalwareCodeScanner
public void scanFieldString(MalwareScan scan, ClassNode cn, FieldNode field, SearchableString string)
{
if (string.searchable.contains("java/awt/Robot") || string.searchable.contains("java.awt.Robot"))
foundLDC(scan, string.original, "at field " + fieldToString(cn, field) + nl);
foundLDC(scan, string.original, "at field " + fieldToString(cn, field) + NL);
}
@Override
public void scanMethodString(MalwareScan scan, ClassNode cn, MethodNode method, SearchableString string)
{
if (string.searchable.contains("java/awt/Robot") || string.searchable.contains("java.awt.Robot"))
foundLDC(scan, string.original, "at method " + methodToString(cn, method) + nl);
foundLDC(scan, string.original, "at method " + methodToString(cn, method) + NL);
}
@Override
@ -54,7 +54,7 @@ public class AWTRobotScanner extends MalwareCodeScanner
{
final MethodInsnNode min = (MethodInsnNode) instruction;
if (min.owner.startsWith("java/awt/Robot"))
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + nl);
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL);
}
}
}

View File

@ -23,7 +23,7 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareCodeScanner;
import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareScan;
import the.bytecode.club.bytecodeviewer.malwarescanner.util.SearchableString;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* @author Konloch
@ -48,7 +48,7 @@ public class JavaIOScanner extends MalwareCodeScanner
{
final MethodInsnNode min = (MethodInsnNode) instruction;
if (min.owner.startsWith("java/io"))
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + nl);
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL);
}
}
}

View File

@ -23,7 +23,7 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareCodeScanner;
import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareScan;
import the.bytecode.club.bytecodeviewer.malwarescanner.util.SearchableString;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* @author Konloch
@ -49,7 +49,7 @@ public class JavaNetScanner extends MalwareCodeScanner
{
final MethodInsnNode min = (MethodInsnNode) instruction;
if (min.owner.startsWith("java/net"))
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + nl);
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL);
}
}
}

View File

@ -23,7 +23,7 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareCodeScanner;
import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareScan;
import the.bytecode.club.bytecodeviewer.malwarescanner.util.SearchableString;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Scans for any trace of java/lang/Runtime inside of method instructions and strings
@ -37,14 +37,14 @@ public class JavaRuntimeScanner extends MalwareCodeScanner
public void scanFieldString(MalwareScan scan, ClassNode cn, FieldNode field, SearchableString string)
{
if (string.searchable.contains("java/lang/Runtime") || string.searchable.contains("java.lang.Runtime"))
foundLDC(scan, string.original, "at field " + fieldToString(cn, field) + nl);
foundLDC(scan, string.original, "at field " + fieldToString(cn, field) + NL);
}
@Override
public void scanMethodString(MalwareScan scan, ClassNode cn, MethodNode method, SearchableString string)
{
if (string.searchable.contains("java/lang/Runtime") || string.searchable.contains("java.lang.Runtime"))
foundLDC(scan, string.original, "at method " + methodToString(cn, method) + nl);
foundLDC(scan, string.original, "at method " + methodToString(cn, method) + NL);
}
@Override
@ -54,7 +54,7 @@ public class JavaRuntimeScanner extends MalwareCodeScanner
{
final MethodInsnNode min = (MethodInsnNode) instruction;
if (min.owner.startsWith("java/lang/Runtime"))
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + nl);
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL);
}
}
}

View File

@ -25,7 +25,7 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareCodeScanner;
import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareScan;
import the.bytecode.club.bytecodeviewer.malwarescanner.util.SearchableString;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Checks for the security manager getting set to null
@ -59,7 +59,7 @@ public class NullSecurityManagerScanner extends MalwareCodeScanner
if (lastInstruction == OpCode.ACONST_NULL.getCode() && owner.equals("java/lang/System") && name.equals("setSecurityManager"))
{
found(scan, "Security Manager set to null at method " + methodToString(cn, method) + nl);
found(scan, "Security Manager set to null at method " + methodToString(cn, method) + NL);
}
}

View File

@ -23,7 +23,7 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareCodeScanner;
import the.bytecode.club.bytecodeviewer.malwarescanner.MalwareScan;
import the.bytecode.club.bytecodeviewer.malwarescanner.util.SearchableString;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Scans for method instructions containing java/lang/reflect
@ -51,7 +51,7 @@ public class ReflectionScanner extends MalwareCodeScanner
{
final MethodInsnNode min = (MethodInsnNode) instruction;
if (min.owner.startsWith("java/lang/reflect"))
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + nl);
foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL);
}
}
}

View File

@ -28,7 +28,7 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.util.SearchableString;
import java.util.regex.Pattern;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Scans strings for common URL patterns:
@ -43,20 +43,26 @@ import static the.bytecode.club.bytecodeviewer.Constants.nl;
*/
public class URLScanner extends MalwareCodeScanner
{
private static final Pattern ipPattern = Pattern.compile("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b");
private static final Pattern IP_PATTERN = Pattern.compile("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b");
@Override
public void scanFieldString(MalwareScan scan, ClassNode cn, FieldNode field, SearchableString string)
{
if (string.searchable.contains("www.") || string.searchable.contains("http://") || string.searchable.contains("https://") || ipPattern.matcher(string.searchable).matches())
foundLDC(scan, string.original, "at field " + fieldToString(cn, field) + nl);
if (string.searchable.contains("www.")
|| string.searchable.contains("http://")
|| string.searchable.contains("https://")
|| IP_PATTERN.matcher(string.searchable).matches())
foundLDC(scan, string.original, "at field " + fieldToString(cn, field) + NL);
}
@Override
public void scanMethodString(MalwareScan scan, ClassNode cn, MethodNode method, SearchableString string)
{
if (string.searchable.contains("www.") || string.searchable.contains("http://") || string.searchable.contains("https://") || ipPattern.matcher(string.searchable).matches())
foundLDC(scan, string.original, "at method " + methodToString(cn, method) + nl);
if (string.searchable.contains("www.")
|| string.searchable.contains("http://")
|| string.searchable.contains("https://")
|| IP_PATTERN.matcher(string.searchable).matches())
foundLDC(scan, string.original, "at method " + methodToString(cn, method) + NL);
}
@Override

View File

@ -40,8 +40,8 @@ import java.awt.*;
import java.io.File;
import java.io.IOException;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
import static the.bytecode.club.bytecodeviewer.Settings.addRecentPlugin;
/**
@ -164,7 +164,7 @@ public class PluginWriter extends JFrame
public void runPlugin()
{
File tempFile = new File(tempDirectory + fs + "temp" + MiscUtils.randomString(32) + fs + pluginName);
File tempFile = new File(TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + FS + pluginName);
tempFile.getParentFile().mkdirs();
try

View File

@ -35,7 +35,7 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* An Allatori String Decrypter, targets an unknown (old) version.
@ -60,7 +60,7 @@ public class AllatoriStringDecrypter extends Plugin
{
PluginConsole frame = new PluginConsole("Allatori String Decrypter");
MultipleChoiceDialog dialog = new MultipleChoiceDialog("Bytecode Viewer - WARNING", "WARNING: This will load the classes into the JVM and execute the allatori decrypter function" + nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.", new String[]{"Continue", "Cancel"});
MultipleChoiceDialog dialog = new MultipleChoiceDialog("Bytecode Viewer - WARNING", "WARNING: This will load the classes into the JVM and execute the allatori decrypter function" + NL + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.", new String[]{"Continue", "Cancel"});
if (dialog.promptChoice() == 0)
{
@ -97,7 +97,7 @@ public class AllatoriStringDecrypter extends Plugin
private void log(String msg)
{
out.append(msg);
out.append(Constants.nl);
out.append(Constants.NL);
}
public void scanClassNode(ClassNode classNode) throws Exception

View File

@ -33,7 +33,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* EZ Injection - This plugin is designed to provide a graphical way for the
@ -243,7 +243,7 @@ public class EZInjection extends Plugin
for (ClassNode cn : BytecodeViewer.getLoadedClasses())
BCV.getClassNodeLoader().addClass(cn);
print("Attempting to find " + invokeMethodInformation + ":" + nl + nl);
print("Attempting to find " + invokeMethodInformation + ":" + NL + NL);
for (ClassNode classNode : classNodeList)
{
@ -258,7 +258,7 @@ public class EZInjection extends Plugin
{
if (m2.getName().equals(m.name))
{
print("Invoking " + invokeMethodInformation + ":" + nl + nl);
print("Invoking " + invokeMethodInformation + ":" + NL + NL);
GraphicalReflectionKit kit = launchKit ? new GraphicalReflectionKit() : null;
try

View File

@ -24,7 +24,7 @@ import the.bytecode.club.bytecodeviewer.api.PluginConsole;
import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Simply shows all the non-empty strings in every single class
@ -51,7 +51,7 @@ public class ShowAllStrings extends Plugin
{
String s = (String) v;
if (!s.isEmpty())
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append(" -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(nl);
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append(" -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(NL);
}
if (v instanceof String[])
@ -60,7 +60,7 @@ public class ShowAllStrings extends Plugin
{
String s = ((String[]) v)[i];
if (!s.isEmpty())
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append("[").append(i).append("] -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(nl);
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append("[").append(i).append("] -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(NL);
}
}
}
@ -78,7 +78,7 @@ public class ShowAllStrings extends Plugin
{
final String s = (String) ((LdcInsnNode) a).cst;
if (!s.isEmpty())
sb.append(classNode.name).append(".").append(m.name).append(m.desc).append(" -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(nl);
sb.append(classNode.name).append(".").append(m.name).append(m.desc).append(" -> \"").append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")).append("\"").append(NL);
}
}
}

View File

@ -30,7 +30,7 @@ import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Objects;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Runs the classes then simply grabs the static String[] z
@ -47,7 +47,7 @@ public class ZStringArrayDecrypter extends Plugin
PluginConsole gui = new PluginConsole("ZStringArray Decrypter");
StringBuilder out = new StringBuilder();
MultipleChoiceDialog dialog = new MultipleChoiceDialog("Bytecode Viewer - WARNING", "WARNING: This will load the classes into the JVM and execute the initialize function" + nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.", new String[]{"Continue", "Cancel"});
MultipleChoiceDialog dialog = new MultipleChoiceDialog("Bytecode Viewer - WARNING", "WARNING: This will load the classes into the JVM and execute the initialize function" + NL + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.", new String[]{"Continue", "Cancel"});
if (dialog.promptChoice() == 0)
{
@ -61,13 +61,13 @@ public class ZStringArrayDecrypter extends Plugin
{
if (field.getName().equals("z"))
{
out.append(cn.getName()).append(":").append(nl);
out.append(cn.getName()).append(":").append(NL);
field.setAccessible(true);
if (field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()))
{
String[] fieldVal = (String[]) field.get(null);
for (int i = 0; i < fieldVal.length; i++)
out.append(" z[").append(i).append("] = ").append(fieldVal[i]).append(nl);
out.append(" z[").append(i).append("] = ").append(fieldVal[i]).append(NL);
}
}
}
@ -82,7 +82,7 @@ public class ZStringArrayDecrypter extends Plugin
if (needsWarning)
{
BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them" + nl + "makes sure you include ALL the libraries it requires.");
BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them" + NL + "makes sure you include ALL the libraries it requires.");
}
gui.setText(out.toString());

View File

@ -20,6 +20,7 @@ package the.bytecode.club.bytecodeviewer.resources;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.SettingsSerializer;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
@ -64,7 +65,7 @@ public class ExternalResources
boolean block = true;
//while (Configuration.java.isEmpty() && block)
{
BytecodeViewer.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)");
BytecodeViewer.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)");
ExternalResources.getSingleton().selectJava();
block = !blockTillSelected; //signal block flag off
}
@ -94,7 +95,7 @@ public class ExternalResources
boolean block = true;
//while (Configuration.javaTools.isEmpty() && block)
{
BytecodeViewer.showMessage("You need to set your Java Tools path, this requires the JDK to be downloaded." + nl + "(C:/Program Files/Java/JDK_xx/lib/tools.jar)");
BytecodeViewer.showMessage("You need to set your Java Tools path, this requires the JDK to be downloaded." + NL + "(C:/Program Files/Java/JDK_xx/lib/tools.jar)");
ExternalResources.getSingleton().selectJavaTools();
block = !blockTillSelected; //signal block flag off
}
@ -296,7 +297,7 @@ public class ExternalResources
*/
public String findLibrary(String nameContains)
{
for (File f : MiscUtils.listFiles(new File(libsDirectory)))
for (File f : MiscUtils.listFiles(new File(LIBS_DIRECTORY)))
if (f.getName().contains(nameContains))
return f.getAbsolutePath();
@ -358,7 +359,9 @@ public class ExternalResources
*/
public String readProcess(Process process) throws IOException
{
try (InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr))
try (InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr))
{
StringBuilder builder = new StringBuilder();
String line;
@ -366,7 +369,7 @@ public class ExternalResources
while ((line = reader.readLine()) != null)
{
builder.append(line);
builder.append(System.getProperty("line.separator"));
builder.append(Constants.NL);
}
return builder.toString();

View File

@ -32,8 +32,8 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import javax.swing.*;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
@ -87,7 +87,7 @@ public class ResourceDecompiling
return;
//this temporary jar file will be used to store the classes while BCV performs decompilation
File temporaryTargetJar = MiscUtils.deleteExistingFile(new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar"));
File temporaryTargetJar = MiscUtils.deleteExistingFile(new File(TEMP_DIRECTORY + FS + "temp_" + MiscUtils.getRandomizedName() + ".jar"));
//extract all the loaded classes imported into BCV to the temporary target jar
JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), temporaryTargetJar.getAbsolutePath());

View File

@ -35,8 +35,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
@ -106,7 +106,7 @@ public class APKExport implements Exporter
Thread saveThread = new Thread(() ->
{
BytecodeViewer.updateBusyStatus(true);
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread buildAPKThread = new Thread(() ->

View File

@ -30,8 +30,8 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import javax.swing.*;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
@ -72,7 +72,7 @@ public class DexExport implements Exporter
Thread saveAsJar = new Thread(() ->
{
BytecodeViewer.updateBusyStatus(true);
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread saveAsDex = new Thread(() ->

View File

@ -27,8 +27,8 @@ import the.bytecode.club.bytecodeviewer.util.*;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
@ -40,7 +40,7 @@ public class APKResourceImporter implements Importer
@Override
public void open(File file) throws Exception
{
File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk");
File tempCopy = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + ".apk");
FileUtils.copyFile(file, tempCopy);
ResourceContainer container = new ResourceContainer(tempCopy, file.getName());
@ -48,7 +48,7 @@ public class APKResourceImporter implements Importer
// APK Resource Decoding Here
if (BytecodeViewer.viewer.decodeAPKResources.isSelected())
{
File decodedResources = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".apk");
File decodedResources = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + ".apk");
APKTool.decodeResources(tempCopy, decodedResources, container);
container.resourceFiles = JarUtils.loadResources(decodedResources);
}
@ -57,7 +57,7 @@ public class APKResourceImporter implements Importer
// to prevent unicode filenames
String name = MiscUtils.getRandomizedName() + ".jar";
File output = new File(tempDirectory + fs + name);
File output = new File(TEMP_DIRECTORY + FS + name);
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
Dex2Jar.dex2Jar(tempCopy, output);

View File

@ -29,8 +29,8 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
@ -41,14 +41,14 @@ public class DEXResourceImporter implements Importer
@Override
public void open(File file) throws Exception
{
File tempCopy = new File(tempDirectory + fs + MiscUtils.randomString(32) + ".dex");
File tempCopy = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + ".dex");
FileUtils.copyFile(file, tempCopy); //copy and rename to prevent unicode filenames
ResourceContainer container = new ResourceContainer(tempCopy, file.getName());
String name = MiscUtils.getRandomizedName() + ".jar";
File output = new File(tempDirectory + fs + name);
File output = new File(TEMP_DIRECTORY + FS + name);
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
Dex2Jar.dex2Jar(tempCopy, output);

View File

@ -37,8 +37,8 @@ import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* Compressed APKs (XAPK)
@ -68,7 +68,7 @@ public class XAPKResourceImporter implements Importer
if (fileName.endsWith(".apk"))
{
File tempFile = new File(tempDirectory + fs + "temp" + MiscUtils.randomString(32) + fs + entry);
File tempFile = new File(TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + FS + entry);
tempFile.getParentFile().mkdirs();
try (InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(tempFile))

View File

@ -24,8 +24,8 @@ import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
@ -37,14 +37,14 @@ public class APKTool
{
try
{
File dir = new File(tempDirectory + fs + MiscUtils.randomString(32) + fs + "Decoded Resources");
File dir = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS + "Decoded Resources");
dir.mkdirs();
File tempAPKPath = new File(tempDirectory + fs + MiscUtils.randomString(12));
File tempAPKPath = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(12));
tempAPKPath.mkdirs();
brut.apktool.Main.main(new String[]{"r", "--frame-path", tempAPKPath.getAbsolutePath(), "d", input.getAbsolutePath(), "-o", dir.getAbsolutePath(), "-f"});
File zip = new File(tempDirectory + fs + MiscUtils.randomString(12) + ".zip");
File zip = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(12) + ".zip");
ZipUtils.zipFolderAPKTool(dir.getAbsolutePath(), zip.getAbsolutePath());
if (zip.exists())
@ -61,17 +61,17 @@ public class APKTool
public static synchronized void buildAPK(File input, File output, ResourceContainer container)
{
String temp = tempDirectory + fs;
File tempDir = new File(temp + fs + MiscUtils.getRandomizedName() + fs);
String temp = TEMP_DIRECTORY + FS;
File tempDir = new File(temp + FS + MiscUtils.getRandomizedName() + FS);
tempDir.mkdirs();
File tempAPKPath = new File(tempDirectory + fs + MiscUtils.randomString(12));
File tempAPKPath = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(12));
tempAPKPath.mkdirs();
try
{
File smaliFolder = new File(container.APKToolContents.getAbsolutePath() + fs + "smali");
File smaliFolder = new File(container.APKToolContents.getAbsolutePath() + FS + "smali");
FileUtils.deleteDirectory(smaliFolder);

View File

@ -30,7 +30,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static the.bytecode.club.bytecodeviewer.Constants.nl;
import static the.bytecode.club.bytecodeviewer.Constants.NL;
/**
* Loads the libraries on boot. If booting failed for some reason, this kicks in as a fail safe.
@ -58,7 +58,7 @@ public class BootCheck implements Runnable
@SuppressWarnings({"rawtypes", "unchecked"})
public void failSafeLoadLibraries()
{
if (!Boot.completedboot && !Boot.downloading)
if (!Boot.completedBoot && !Boot.downloading)
{
File libsDir = Boot.libsDir();
File[] listFiles = libsDir.listFiles();
@ -66,7 +66,7 @@ public class BootCheck implements Runnable
//first boot failed to download libraries
if (listFiles == null || listFiles.length <= 0)
{
BytecodeViewer.showMessage("Github is loading extremely slow, BCV needs to download libraries from github in order" + nl + "to work, please try adjusting your network settings or manually downloading these libraries" + nl + "if this error persists.");
BytecodeViewer.showMessage("Github is loading extremely slow, BCV needs to download libraries from github in order" + NL + "to work, please try adjusting your network settings or manually downloading these libraries" + NL + "if this error persists.");
return;
}
@ -107,7 +107,6 @@ public class BootCheck implements Runnable
Boot.checkEnjarify();
Boot.checkKrakatau();
Boot.globalstop = false;
Boot.hide();
int CLI = CommandLineInput.parseCommandLine(BytecodeViewer.launchArgs);

View File

@ -34,7 +34,7 @@ import java.awt.*;
*/
public class JTextAreaUtils
{
private static final DefaultHighlighter.DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 62, 150));
private static final DefaultHighlighter.DefaultHighlightPainter PAINTER = new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 62, 150));
/**
* This was really interesting to write.
@ -163,7 +163,7 @@ public class JTextAreaUtils
{
// Create highlighter using private painter and apply around
// pattern
highlighter.addHighlight(pos, pos + pattern.length(), painter);
highlighter.addHighlight(pos, pos + pattern.length(), PAINTER);
pos += pattern.length();
}
}

View File

@ -36,7 +36,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.FS;
/**
* Loading and saving jars
@ -384,7 +384,7 @@ public class JarUtils
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
String name = dir + fs + cn.name + ".class";
String name = dir + FS + cn.name + ".class";
File f = new File(name);
f.mkdirs();

View File

@ -31,28 +31,28 @@ import java.util.Map;
*/
public class LazyNameUtil
{
public static boolean SAME_NAME_JAR_WORKSPACE = false;
private static final Map<String, SeqAndCount> nameMap = new HashMap<>();
public static boolean sameNameJarWorkspace = false;
private static final Map<String, SeqAndCount> NAME_MAP = new HashMap<>();
public static void reset()
{
nameMap.clear();
NAME_MAP.clear();
}
public static String applyNameChanges(String name)
{
if (nameMap.containsKey(name))
if (NAME_MAP.containsKey(name))
{
if (!SAME_NAME_JAR_WORKSPACE)
SAME_NAME_JAR_WORKSPACE = true;
if (!sameNameJarWorkspace)
sameNameJarWorkspace = true;
SeqAndCount seqAndCount = nameMap.get(name);
nameMap.put(name, seqAndCount.incrSeqAndCount());
SeqAndCount seqAndCount = NAME_MAP.get(name);
NAME_MAP.put(name, seqAndCount.incrSeqAndCount());
return FilenameUtils.removeExtension(name) + "#" + seqAndCount.getSeq() + "." + FilenameUtils.getExtension(name);
}
else
{
nameMap.put(name, SeqAndCount.init());
NAME_MAP.put(name, SeqAndCount.init());
}
return name;
@ -66,15 +66,15 @@ public class LazyNameUtil
if (name.contains("#"))
name = name.substring(0, name.indexOf("#")) + name.substring(name.indexOf("."));
SeqAndCount seqAndCount = nameMap.get(name);
SeqAndCount seqAndCount = NAME_MAP.get(name);
if (seqAndCount == null)
return;
// sequence remain the same and decrease the count
// still the count become 1
if (seqAndCount.getCount() == 1)
nameMap.remove(name);
NAME_MAP.remove(name);
else
nameMap.put(name, seqAndCount.decrCount());
NAME_MAP.put(name, seqAndCount.decrCount());
}
}

View File

@ -51,26 +51,26 @@ public class MethodParser
}
}
public static final Pattern regex = Pattern.compile("\\s*(?:static|public|private|protected|final|abstract)" + "[\\w\\s.<>\\[\\]]*\\s+(?<name>[\\w.]+)\\s*\\((?<params>[\\w\\s,.<>\\[\\]$?]*)\\)");
public static final Pattern REGEX = Pattern.compile("\\s*(?:static|public|private|protected|final|abstract)"
+ "[\\w\\s.<>\\[\\]]*\\s+(?<name>[\\w.]+)\\s*\\((?<params>[\\w\\s,.<>\\[\\]$?]*)\\)");
private final TreeMap<Integer, Method> methods = new TreeMap<>();
private static String removeBrackets(String string)
{
if (string.indexOf('<') != -1 && string.indexOf('>') != -1)
{
return removeBrackets(string.replaceAll("<[^<>]*>", ""));
}
return string;
}
private static String getLastPart(String string, int character)
{
int ch = string.lastIndexOf(character);
if (ch != -1)
{
string = string.substring(ch + 1);
}
return string;
}
@ -80,6 +80,7 @@ public class MethodParser
{
name = getLastPart(name, '.');
String[] args = {};
if (!params.isEmpty())
{
params = removeBrackets(params);
@ -87,15 +88,18 @@ public class MethodParser
for (int i = 0; i < args.length; i++)
{
args[i] = args[i].trim();
if (args[i].indexOf(' ') != -1)
{
String[] strings = args[i].split(" ");
args[i] = strings[strings.length - 2];
}
args[i] = getLastPart(args[i], '.');
args[i] = getLastPart(args[i], '$');
}
}
Method method = new Method(name, Arrays.asList(args));
methods.put(line, method);
}
@ -120,22 +124,26 @@ public class MethodParser
public String getMethodName(int line)
{
Method method = methods.get(line);
if (method != null)
{
if (!method.name.isEmpty())
return method.name;
}
return "";
}
public List<String> getMethodParams(int line)
{
Method method = methods.get(line);
if (method != null)
{
if (!method.params.isEmpty())
return method.params;
}
return null;
}
@ -151,11 +159,10 @@ public class MethodParser
if (name.equals(entry.getValue().name) && params.size() == entry.getValue().params.size())
{
if (params.equals(entry.getValue().params))
{
return entry.getKey();
}
}
}
return -1;
}
@ -165,10 +172,9 @@ public class MethodParser
{
Map.Entry<Integer, Method> low = methods.floorEntry(line);
if (low != null)
{
return low.getKey();
}
}
return -1;
}
@ -184,16 +190,14 @@ public class MethodParser
{
Map.Entry<Integer, Method> low = methods.floorEntry(line);
Map.Entry<Integer, Method> high = methods.ceilingEntry(line);
if (low != null && high != null)
{
return Math.abs(line - low.getKey()) < Math.abs(line - high.getKey()) ? low.getKey() : high.getKey();
}
else if (low != null || high != null)
{
return low != null ? low.getKey() : high.getKey();
}
}
}
return -1;
}
}

View File

@ -44,8 +44,8 @@ public class MiscUtils
{
private static final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static final String AN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static final Random rnd = new Random();
private static final Set<String> createdRandomizedNames = new HashSet<>();
private static final Random RND = new Random();
private static final Set<String> CREATED_RANDOMIZED_NAMES = new HashSet<>();
/**
* Returns a random string without numbers
@ -57,7 +57,7 @@ public class MiscUtils
{
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++)
sb.append(AB.charAt(rnd.nextInt(AB.length())));
sb.append(AB.charAt(RND.nextInt(AB.length())));
return sb.toString();
}
@ -73,9 +73,9 @@ public class MiscUtils
while (!generated)
{
String randomizedName = MiscUtils.randomString(25);
if (!createdRandomizedNames.contains(randomizedName))
if (!CREATED_RANDOMIZED_NAMES.contains(randomizedName))
{
createdRandomizedNames.add(randomizedName);
CREATED_RANDOMIZED_NAMES.add(randomizedName);
name = randomizedName;
generated = true;
}
@ -86,7 +86,8 @@ public class MiscUtils
public static void printProcess(Process process) throws Exception
{
//Read out dir output
try (InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
@ -95,7 +96,9 @@ public class MiscUtils
}
}
try (InputStream is = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr))
try (InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr))
{
String line;
while ((line = br.readLine()) != null)
@ -115,7 +118,7 @@ public class MiscUtils
{
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++)
sb.append(AN.charAt(rnd.nextInt(AN.length())));
sb.append(AN.charAt(RND.nextInt(AN.length())));
return sb.toString();
}

View File

@ -19,6 +19,7 @@
package the.bytecode.club.bytecodeviewer.util;
import org.jetbrains.annotations.NotNull;
import the.bytecode.club.bytecodeviewer.Constants;
import java.io.FilterOutputStream;
import java.io.IOException;
@ -42,7 +43,7 @@ public class NewlineOutputStream extends FilterOutputStream
super(os);
if (newline == null)
{
String s = System.getProperty("line.separator");
String s = Constants.NL;
if (s == null || s.length() <= 0)
s = "\n";
newline = s.getBytes(StandardCharsets.ISO_8859_1); // really us-ascii

View File

@ -41,8 +41,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public class SecurityMan extends SecurityManager
{
private static final boolean disableExecSandbox = true;
private static final boolean disableDiskWriteSandbox = true;
private static final boolean DISABLE_EXEC_SANDBOX = true;
private static final boolean DISABLE_DISK_WRITE_SANDBOX = true;
private final AtomicInteger silentExec = new AtomicInteger(1);
private boolean printing = false;
@ -77,11 +77,17 @@ public class SecurityMan extends SecurityManager
public void checkExec(String cmd)
{
//This was disabled on 02-13-2022, at some point in the future I will fix the compatibility issues and re-enable it.
if (disableExecSandbox)
if (DISABLE_EXEC_SANDBOX)
return;
//incoming command must contain the following or it will be automatically denied
String[] execWhitelist = {"attrib", "python", "pypy", "java", "brut_util",};
//incoming command must contain the following, or it will be automatically denied
String[] execWhitelist = {
"attrib",
"python",
"pypy",
"java",
"brut_util"
};
//the goal is to make this true
boolean allow = false;
@ -108,7 +114,7 @@ public class SecurityMan extends SecurityManager
blocked = true;
//block anything executing in system temp
else if (normalizedPath.startsWith(Constants.systemTempDirectory.toLowerCase()))
else if (normalizedPath.startsWith(Constants.SYSTEM_TEMP_DIRECTORY.toLowerCase()))
blocked = true;
//can only write into BCV dir, so anything executing from here has probably been dropped
@ -170,7 +176,19 @@ public class SecurityMan extends SecurityManager
*/
private boolean canClassExecute(String fullyQualifiedClassName)
{
return fullyQualifiedClassName.equals(KrakatauDecompiler.class.getCanonicalName()) || fullyQualifiedClassName.equals(KrakatauDisassembler.class.getCanonicalName()) || fullyQualifiedClassName.equals(CFRDecompiler.class.getCanonicalName()) || fullyQualifiedClassName.equals(ProcyonDecompiler.class.getCanonicalName()) || fullyQualifiedClassName.equals(FernFlowerDecompiler.class.getCanonicalName()) || fullyQualifiedClassName.equals(JDGUIDecompiler.class.getCanonicalName()) || fullyQualifiedClassName.equals(KrakatauAssembler.class.getCanonicalName()) || fullyQualifiedClassName.equals(ExternalResources.class.getCanonicalName()) || fullyQualifiedClassName.equals(Enjarify.class.getCanonicalName()) || fullyQualifiedClassName.equals(APKTool.class.getCanonicalName()) || fullyQualifiedClassName.equals(BytecodeViewer.class.getCanonicalName()) || fullyQualifiedClassName.equals(Constants.class.getCanonicalName()) || fullyQualifiedClassName.equals(JavaCompiler.class.getCanonicalName());
return fullyQualifiedClassName.equals(KrakatauDecompiler.class.getCanonicalName())
|| fullyQualifiedClassName.equals(KrakatauDisassembler.class.getCanonicalName())
|| fullyQualifiedClassName.equals(CFRDecompiler.class.getCanonicalName())
|| fullyQualifiedClassName.equals(ProcyonDecompiler.class.getCanonicalName())
|| fullyQualifiedClassName.equals(FernFlowerDecompiler.class.getCanonicalName())
|| fullyQualifiedClassName.equals(JDGUIDecompiler.class.getCanonicalName())
|| fullyQualifiedClassName.equals(KrakatauAssembler.class.getCanonicalName())
|| fullyQualifiedClassName.equals(ExternalResources.class.getCanonicalName())
|| fullyQualifiedClassName.equals(Enjarify.class.getCanonicalName())
|| fullyQualifiedClassName.equals(APKTool.class.getCanonicalName())
|| fullyQualifiedClassName.equals(BytecodeViewer.class.getCanonicalName())
|| fullyQualifiedClassName.equals(Constants.class.getCanonicalName())
|| fullyQualifiedClassName.equals(JavaCompiler.class.getCanonicalName());
}
@Override
@ -334,13 +352,24 @@ public class SecurityMan extends SecurityManager
System.out.println("Writing: " + file);
//This was disabled on 02-13-2022, at some point in the future I will fix the compatibility issues and re-enable it.
if (disableDiskWriteSandbox)
if (DISABLE_DISK_WRITE_SANDBOX)
return;
try
{
//can only export as the following extensions
if (file.endsWith(".zip") || file.endsWith(".jar") || file.endsWith(".apk") || file.endsWith(".dex") || file.endsWith(".class") || file.endsWith("js") || file.endsWith(".java") || file.endsWith(".gy") || file.endsWith(".bcv") || file.endsWith(".json") || file.endsWith(".txt") || file.endsWith(".log"))
if (file.endsWith(".zip")
|| file.endsWith(".jar")
|| file.endsWith(".apk")
|| file.endsWith(".dex")
|| file.endsWith(".class")
|| file.endsWith("js")
|| file.endsWith(".java")
|| file.endsWith(".gy")
|| file.endsWith(".bcv")
|| file.endsWith(".json")
|| file.endsWith(".txt")
|| file.endsWith(".log"))
return;
//can only write into BCV dir
@ -348,7 +377,7 @@ public class SecurityMan extends SecurityManager
return;
//can only write into system temp
if (file.startsWith(Constants.systemTempDirectory))
if (file.startsWith(Constants.SYSTEM_TEMP_DIRECTORY))
return;
}
catch (IOException e)

View File

@ -30,7 +30,10 @@ import java.util.function.BiFunction;
*/
public enum SyntaxLanguage
{
XML(SyntaxConstants.SYNTAX_STYLE_XML, (n, c) -> n.endsWith(".xml") || c.startsWith("<?xml") || c.startsWith("<xml")), PYTHON(SyntaxConstants.SYNTAX_STYLE_PYTHON, (n, c) -> n.endsWith(".py") || n.endsWith(".python")), RUBY(SyntaxConstants.SYNTAX_STYLE_RUBY, (n, c) -> n.endsWith(".rb") || n.endsWith(".ruby")), JAVA(SyntaxConstants.SYNTAX_STYLE_JAVA, (n, c) -> n.endsWith(".java")), HTML(SyntaxConstants.SYNTAX_STYLE_HTML, (n, c) -> n.endsWith(".html")), CSS(SyntaxConstants.SYNTAX_STYLE_CSS, (n, c) -> n.endsWith(".css")), PROPERTIES(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE, (n, c) -> n.endsWith(".properties") || n.endsWith(".mf") || n.endsWith(".sf") || n.endsWith(".plugin") || n.endsWith(".attachprovider") || n.endsWith(".transportservice") || n.endsWith(".connector")), PHP(SyntaxConstants.SYNTAX_STYLE_PHP, (n, c) -> n.endsWith(".php") || c.startsWith("<?php")), JS(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, (n, c) -> n.endsWith(".js")), BATCH(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH, (n, c) -> n.endsWith(".bat")), SHELL(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL, (n, c) -> n.endsWith(".sh")), C(SyntaxConstants.SYNTAX_STYLE_C, (n, c) -> n.endsWith(".c") || n.endsWith(".h")), CPP(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS, (n, c) -> n.endsWith(".cpp") || n.endsWith(".hpp")), SCALA(SyntaxConstants.SYNTAX_STYLE_SCALA, (n, c) -> n.endsWith(".scala")), CLOJURE(SyntaxConstants.SYNTAX_STYLE_CLOJURE, (n, c) -> n.endsWith(".clojure")), GROOVY(SyntaxConstants.SYNTAX_STYLE_GROOVY, (n, c) -> n.endsWith(".groovy") || n.endsWith(".gradle")), LUA(SyntaxConstants.SYNTAX_STYLE_LUA, (n, c) -> n.endsWith(".lua")), SQL(SyntaxConstants.SYNTAX_STYLE_SQL, (n, c) -> n.endsWith(".sql")), JSON(SyntaxConstants.SYNTAX_STYLE_JSON, (n, c) -> n.endsWith(".json")), JSP(SyntaxConstants.SYNTAX_STYLE_JSP, (n, c) -> n.endsWith(".jsp")), YAML(SyntaxConstants.SYNTAX_STYLE_YAML, (n, c) -> n.endsWith(".yml") || n.endsWith(".yaml")), CS(SyntaxConstants.SYNTAX_STYLE_CSHARP, (n, c) -> n.endsWith(".cs")), CSV(SyntaxConstants.SYNTAX_STYLE_CSV, (n, c) -> n.endsWith(".csv")), DOCKER(SyntaxConstants.SYNTAX_STYLE_DOCKERFILE, (n, c) -> n.endsWith(".dockerfile")), DART(SyntaxConstants.SYNTAX_STYLE_DART, (n, c) -> n.endsWith(".dart")), GO(SyntaxConstants.SYNTAX_STYLE_GO, (n, c) -> n.endsWith(".go")), HTACCESS(SyntaxConstants.SYNTAX_STYLE_HTACCESS, (n, c) -> n.endsWith(".htaccess")), INI(SyntaxConstants.SYNTAX_STYLE_INI, (n, c) -> n.endsWith(".ini")), KOTLIN(SyntaxConstants.SYNTAX_STYLE_KOTLIN, (n, c) -> n.endsWith(".kt") || n.endsWith(".kts")), LATEX(SyntaxConstants.SYNTAX_STYLE_LATEX, (n, c) -> n.endsWith(".tex")), MARKDOWN(SyntaxConstants.SYNTAX_STYLE_MARKDOWN, (n, c) -> n.endsWith(".md")), PERL(SyntaxConstants.SYNTAX_STYLE_PERL, (n, c) -> n.endsWith(".pl")), TYPESCRIPT(SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT, (n, c) -> n.endsWith(".ts")), NONE(SyntaxConstants.SYNTAX_STYLE_NONE, (n, c) -> false);
XML(SyntaxConstants.SYNTAX_STYLE_XML, (n, c) -> n.endsWith(".xml") || c.startsWith("<?xml") || c.startsWith("<xml")),
PYTHON(SyntaxConstants.SYNTAX_STYLE_PYTHON, (n, c) -> n.endsWith(".py") || n.endsWith(".python")),
RUBY(SyntaxConstants.SYNTAX_STYLE_RUBY, (n, c) -> n.endsWith(".rb") || n.endsWith(".ruby")),
JAVA(SyntaxConstants.SYNTAX_STYLE_JAVA, (n, c) -> n.endsWith(".java")), HTML(SyntaxConstants.SYNTAX_STYLE_HTML, (n, c) -> n.endsWith(".html")), CSS(SyntaxConstants.SYNTAX_STYLE_CSS, (n, c) -> n.endsWith(".css")), PROPERTIES(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE, (n, c) -> n.endsWith(".properties") || n.endsWith(".mf") || n.endsWith(".sf") || n.endsWith(".plugin") || n.endsWith(".attachprovider") || n.endsWith(".transportservice") || n.endsWith(".connector")), PHP(SyntaxConstants.SYNTAX_STYLE_PHP, (n, c) -> n.endsWith(".php") || c.startsWith("<?php")), JS(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, (n, c) -> n.endsWith(".js")), BATCH(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH, (n, c) -> n.endsWith(".bat")), SHELL(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL, (n, c) -> n.endsWith(".sh")), C(SyntaxConstants.SYNTAX_STYLE_C, (n, c) -> n.endsWith(".c") || n.endsWith(".h")), CPP(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS, (n, c) -> n.endsWith(".cpp") || n.endsWith(".hpp")), SCALA(SyntaxConstants.SYNTAX_STYLE_SCALA, (n, c) -> n.endsWith(".scala")), CLOJURE(SyntaxConstants.SYNTAX_STYLE_CLOJURE, (n, c) -> n.endsWith(".clojure")), GROOVY(SyntaxConstants.SYNTAX_STYLE_GROOVY, (n, c) -> n.endsWith(".groovy") || n.endsWith(".gradle")), LUA(SyntaxConstants.SYNTAX_STYLE_LUA, (n, c) -> n.endsWith(".lua")), SQL(SyntaxConstants.SYNTAX_STYLE_SQL, (n, c) -> n.endsWith(".sql")), JSON(SyntaxConstants.SYNTAX_STYLE_JSON, (n, c) -> n.endsWith(".json")), JSP(SyntaxConstants.SYNTAX_STYLE_JSP, (n, c) -> n.endsWith(".jsp")), YAML(SyntaxConstants.SYNTAX_STYLE_YAML, (n, c) -> n.endsWith(".yml") || n.endsWith(".yaml")), CS(SyntaxConstants.SYNTAX_STYLE_CSHARP, (n, c) -> n.endsWith(".cs")), CSV(SyntaxConstants.SYNTAX_STYLE_CSV, (n, c) -> n.endsWith(".csv")), DOCKER(SyntaxConstants.SYNTAX_STYLE_DOCKERFILE, (n, c) -> n.endsWith(".dockerfile")), DART(SyntaxConstants.SYNTAX_STYLE_DART, (n, c) -> n.endsWith(".dart")), GO(SyntaxConstants.SYNTAX_STYLE_GO, (n, c) -> n.endsWith(".go")), HTACCESS(SyntaxConstants.SYNTAX_STYLE_HTACCESS, (n, c) -> n.endsWith(".htaccess")), INI(SyntaxConstants.SYNTAX_STYLE_INI, (n, c) -> n.endsWith(".ini")), KOTLIN(SyntaxConstants.SYNTAX_STYLE_KOTLIN, (n, c) -> n.endsWith(".kt") || n.endsWith(".kts")), LATEX(SyntaxConstants.SYNTAX_STYLE_LATEX, (n, c) -> n.endsWith(".tex")), MARKDOWN(SyntaxConstants.SYNTAX_STYLE_MARKDOWN, (n, c) -> n.endsWith(".md")), PERL(SyntaxConstants.SYNTAX_STYLE_PERL, (n, c) -> n.endsWith(".pl")), TYPESCRIPT(SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT, (n, c) -> n.endsWith(".ts")), NONE(SyntaxConstants.SYNTAX_STYLE_NONE, (n, c) -> false);
public static final SyntaxLanguage[] VALUES = values();

View File

@ -55,32 +55,26 @@ public class JTabbedPanePopupMenuTabsCloser extends AbstractJTabbedPanePopupMenu
{
JPopupMenu popUpMenu = new JPopupMenu();
if (closeConfiguration.isClose())
{
addItemCloseTab(popUpMenu, popupOnTab);
}
if (closeConfiguration.isCloseOthers())
{
addItemCloseOtherTabs(popUpMenu, popupOnTab);
}
if (closeConfiguration.isCloseAll())
{
addItemCloseAllTabs(popUpMenu);
}
if (closeConfiguration.isCloseLefts())
{
addItemCloseLeftTabs(popUpMenu, popupOnTab);
}
if (closeConfiguration.isCloseRights())
{
addItemCloseRightTabs(popUpMenu, popupOnTab);
}
return popUpMenu;
}
protected void addItemCloseTab(JPopupMenu popUpMenu, Component popupOnTab)
{
addMenuItem(popUpMenu, "Close", e ->
{tabbedPaneCloser.removeComponent(popupOnTab);});
addMenuItem(popUpMenu, "Close", e -> tabbedPaneCloser.removeComponent(popupOnTab));
}
protected void addItemCloseOtherTabs(JPopupMenu popUpMenu, Component popupOnTab)
@ -91,20 +85,17 @@ public class JTabbedPanePopupMenuTabsCloser extends AbstractJTabbedPanePopupMenu
protected void addItemCloseAllTabs(JPopupMenu popUpMenu)
{
addMenuItem(popUpMenu, "Close All", e ->
{tabbedPaneCloser.removeAllComponents();});
addMenuItem(popUpMenu, "Close All", e -> tabbedPaneCloser.removeAllComponents());
}
protected void addItemCloseLeftTabs(JPopupMenu popUpMenu, Component popupOnTab)
{
addMenuItem(popUpMenu, "Close Lefts", e ->
{tabbedPaneCloser.removeLeftComponents(popupOnTab);});
addMenuItem(popUpMenu, "Close Lefts", e -> tabbedPaneCloser.removeLeftComponents(popupOnTab));
}
protected void addItemCloseRightTabs(JPopupMenu popUpMenu, Component popupOnTab)
{
addMenuItem(popUpMenu, "Close Rights", e ->
{tabbedPaneCloser.removeRightComponents(popupOnTab);});
addMenuItem(popUpMenu, "Close Rights", e -> tabbedPaneCloser.removeRightComponents(popupOnTab));
}
protected void addMenuItem(JPopupMenu popUpMenu, String item, ActionListener listener)

View File

@ -46,7 +46,7 @@ public class PopupMenuTabsCloseConfiguration
return close;
}
public void Close(boolean close)
public void close(boolean close)
{
this.close = close;
}