From 5dab52bfd3a8a16d6b786a7e06a72ea21bbf35e6 Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 29 Sep 2024 19:47:50 -0600 Subject: [PATCH] Code Cleanup --- .../club/bytecodeviewer/Configuration.java | 6 ++- .../club/bytecodeviewer/Constants.java | 15 ++++--- .../club/bytecodeviewer/api/ExceptionUI.java | 4 +- .../club/bytecodeviewer/bootloader/Boot.java | 9 ++-- .../bootloader/UpdateCheck.java | 8 ++-- .../bytecodeviewer/cli/CommandLineInput.java | 10 ++++- .../bytecode/InstructionPrinter.java | 20 ++++++--- .../impl/ASMTextifierDisassembler.java | 1 - .../gui/components/HTMLPane.java | 2 +- .../bytecodeviewer/gui/theme/LAFTheme.java | 3 +- .../bytecodeviewer/gui/theme/RSTATheme.java | 7 ++- .../obfuscators/RenameFields.java | 3 +- .../obfuscators/RenameMethods.java | 3 +- .../obfuscators/mapping/Remapper.java | 6 ++- .../obfuscators/rename/RenameClasses.java | 5 +-- .../obfuscators/rename/RenameFields.java | 3 -- .../obfuscators/rename/RenameMethods.java | 14 +++--- .../bytecodeviewer/plugin/PluginManager.java | 45 ++++++++++--------- .../classcontainer/parser/TokenUtil.java | 13 +++++- .../resources/exporting/impl/APKExport.java | 9 +++- .../resources/exporting/impl/DexExport.java | 3 ++ .../club/bytecodeviewer/util/SecurityMan.java | 4 +- 22 files changed, 126 insertions(+), 67 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java index e715fe53f..a71ee9924 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java @@ -42,7 +42,11 @@ public class Configuration public static boolean python3Extra = false; public static String rt = ""; public static String library = ""; - public static String java = Constants.JAVA_BINARY.exists() ? Constants.JAVA_BINARY.getAbsolutePath() : Constants.JAVA_BINARY_NIX.exists() ? Constants.JAVA_BINARY_NIX.getAbsolutePath() : ""; + public static String java = Constants.JAVA_BINARY.exists() + ? Constants.JAVA_BINARY.getAbsolutePath() + : Constants.JAVA_BINARY_NIX.exists() + ? Constants.JAVA_BINARY_NIX.getAbsolutePath() + : ""; public static String javac = ""; public static String javaTools = ""; public static File krakatauTempDir; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java index 98811d10d..4523ef92f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java @@ -60,8 +60,11 @@ public class Constants //version is set via maven public static final String VERSION = getVersion(BytecodeViewer.class.getPackage().getImplementationVersion()); + + //CHECKSTYLE:OFF //dev mode is just a check for running via IDE public static boolean DEV_MODE; + //CHECKSTYLE:ON //if true the version checker will prompt and ask how you would like to proceed public static final boolean FORCE_VERSION_CHECKER_PROMPT = false; @@ -71,7 +74,7 @@ public class Constants public static final String[] SUPPORTED_FILE_EXTENSIONS = ResourceType.SUPPORTED_BCV_EXTENSION_MAP.keySet().toArray(new String[0]); public static final int ASM_VERSION = Opcodes.ASM9; - public static final File BCVDir = resolveBCVRoot(); + public static final File BCV_DIR = 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"); @@ -119,18 +122,18 @@ public static File resolveBCVRoot() */ public static String getBCVDirectory() { - while (!BCVDir.exists()) - BCVDir.mkdirs(); + while (!BCV_DIR.exists()) + BCV_DIR.mkdirs(); //hides the BCV directory - if (isWindows() && !BCVDir.isHidden()) + if (isWindows() && !BCV_DIR.isHidden()) { new Thread(() -> { try { // Hide file by running attrib system command (on Windows) - Process p = new ProcessBuilder("attrib", "+H", BCVDir.getAbsolutePath()).start(); + Process p = new ProcessBuilder("attrib", "+H", BCV_DIR.getAbsolutePath()).start(); } catch (Exception e) { @@ -139,7 +142,7 @@ public static String getBCVDirectory() }, "Hide BCV Dir").start(); } - return BCVDir.getAbsolutePath(); + return BCV_DIR.getAbsolutePath(); } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java index 24754df6d..3f7d0a9a1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/ExceptionUI.java @@ -141,7 +141,9 @@ public static String buildErrorLogHeader(String author) 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"); + + "\nBytecode Viewer Version: " + VERSION + fatJar + + ", OS: " + System.getProperty("os.name") + + ", Java: " + System.getProperty("java.version"); } private static final long serialVersionUID = -5230501978224926296L; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/Boot.java b/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/Boot.java index 820ae5f1d..ae45610d6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/Boot.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/Boot.java @@ -331,7 +331,8 @@ public static void dropKrakatau() while (temp.exists()) temp.delete(); - try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("Krakatau-" + krakatauVersion + ".zip"); FileOutputStream baos = new FileOutputStream(temp)) + try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("Krakatau-" + krakatauVersion + ".zip"); + FileOutputStream baos = new FileOutputStream(temp)) { int r; byte[] buffer = new byte[8192]; @@ -368,7 +369,8 @@ public static void dropEnjarify() while (temp.exists()) temp.delete(); - try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("enjarify-" + Constants.enjarifyVersion + ".zip"); FileOutputStream baos = new FileOutputStream(temp)) + try (InputStream is = BytecodeViewer.class.getClassLoader().getResourceAsStream("enjarify-" + Constants.enjarifyVersion + ".zip"); + FileOutputStream baos = new FileOutputStream(temp)) { int r; byte[] buffer = new byte[8192]; @@ -405,7 +407,8 @@ public static void downloadZipsOnly() 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]; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/UpdateCheck.java b/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/UpdateCheck.java index e5f5574dd..1005a844b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/UpdateCheck.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/UpdateCheck.java @@ -118,7 +118,8 @@ public void run() 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) { @@ -176,7 +177,7 @@ public static File promptFileSave(String description, String extension) throws I } //used to download all released versions of BCV - /*public static void main(String[] args) + /*public static void main(String[] args) { BytecodeViewer.viewer = new MainViewerGUI(); for(String version : BCV_VERSIONS) @@ -234,7 +235,8 @@ private static boolean validURl(String url) throws Exception 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)) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java index 0aa1f6386..28fa6a878 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java @@ -178,7 +178,15 @@ else if (cmd.hasOption("help")) //if its zip/jar/apk/dex attempt unzip as whole zip //if its just class allow any - if (decompiler != null && !decompiler.equalsIgnoreCase("procyon") && !decompiler.equalsIgnoreCase("cfr") && !decompiler.equalsIgnoreCase("fernflower") && !decompiler.equalsIgnoreCase("krakatau") && !decompiler.equalsIgnoreCase("krakatau-bytecode") && !decompiler.equalsIgnoreCase("jd-gui") && !decompiler.equalsIgnoreCase("smali") && !decompiler.equalsIgnoreCase("asmifier")) + if (decompiler != null + && !decompiler.equalsIgnoreCase("procyon") + && !decompiler.equalsIgnoreCase("cfr") + && !decompiler.equalsIgnoreCase("fernflower") + && !decompiler.equalsIgnoreCase("krakatau") + && !decompiler.equalsIgnoreCase("krakatau-bytecode") + && !decompiler.equalsIgnoreCase("jd-gui") + && !decompiler.equalsIgnoreCase("smali") + && !decompiler.equalsIgnoreCase("asmifier")) { System.out.println("Error, no decompiler called '" + decompiler + "' found. Type -list" + " for the list"); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java index a96e1929d..c1085ceb0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java @@ -69,6 +69,7 @@ public InstructionPrinter(MethodNode m, InstructionPattern pattern, TypeAndName[ this(m, args); InstructionSearcher searcher = new InstructionSearcher(m.instructions, pattern); match = searcher.search(); + if (match) { for (AbstractInsnNode[] ains : searcher.getMatches()) @@ -102,6 +103,7 @@ public List createPrint() { firstLabel = false; info.clear(); + for (AbstractInsnNode ain : mNode.instructions) { String line = printInstruction(ain); @@ -114,8 +116,10 @@ public List createPrint() info.add(line); } } + if (firstLabel && BytecodeViewer.viewer.appendBracketsToLabels.isSelected()) info.add("}"); + return info; } @@ -169,16 +173,12 @@ protected String printVarInsnNode(VarInsnNode vin) if (BytecodeViewer.viewer.debugHelpers.isSelected()) { if (vin.var == 0 && !Modifier.isStatic(mNode.access)) - { sb.append(" // reference to self"); - } else { final int refIndex = vin.var - (Modifier.isStatic(mNode.access) ? 0 : 1); if (refIndex >= 0 && refIndex < args.length - 1) - { sb.append(" // reference to ").append(args[refIndex].name); - } } } @@ -229,9 +229,11 @@ protected String printMethodInsnNode(MethodInsnNode min) protected String printLdcInsnNode(LdcInsnNode ldc) { if (ldc.cst instanceof String) - return nameOpcode(ldc.getOpcode()) + " \"" + StringEscapeUtils.escapeJava(ldc.cst.toString()) + "\" (" + ldc.cst.getClass().getCanonicalName() + ")"; + return nameOpcode(ldc.getOpcode()) + " \"" + StringEscapeUtils.escapeJava(ldc.cst.toString()) + + "\" (" + ldc.cst.getClass().getCanonicalName() + ")"; - return nameOpcode(ldc.getOpcode()) + " " + StringEscapeUtils.escapeJava(ldc.cst.toString()) + " (" + ldc.cst.getClass().getCanonicalName() + ")"; + return nameOpcode(ldc.getOpcode()) + " " + StringEscapeUtils.escapeJava(ldc.cst.toString()) + + " (" + ldc.cst.getClass().getCanonicalName() + ")"; } protected String printInsnNode(InsnNode in) @@ -270,6 +272,7 @@ protected String printLabelNode(LabelNode label) String starting = tcbs.stream().filter(tcb -> tcb.start == label).map(tcb -> "start TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); String ending = tcbs.stream().filter(tcb -> tcb.end == label).map(tcb -> "end TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); String handlers = tcbs.stream().filter(tcb -> tcb.handler == label).map(tcb -> "handle TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); + if (!ending.isEmpty()) info.add("// " + ending); if (!starting.isEmpty()) @@ -325,10 +328,12 @@ protected String printTableSwitchInsnNode(TableSwitchInsnNode tin) StringBuilder line = new StringBuilder(nameOpcode(tin.getOpcode()) + " \n"); List labels = tin.labels; int count = 0; + for (int i = tin.min; i < tin.max + 1; i++) { line.append(" val: ").append(i).append(" -> ").append("L").append(resolveLabel((LabelNode) labels.get(count++))).append("\n"); } + line.append(" default" + " -> L").append(resolveLabel(tin.dflt)); return line.toString(); } @@ -408,6 +413,7 @@ private String printFrameObject(Object obj) { if (obj instanceof LabelNode) return "label [L" + resolveLabel((LabelNode) obj) + "]"; + if (obj instanceof Integer) { switch ((int) obj) @@ -430,8 +436,10 @@ private String printFrameObject(Object obj) return "unknown"; } } + if (obj instanceof String) return obj.toString(); + return "unknown [" + obj.toString() + "]"; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java index d52fc3d3a..28249ef1b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java @@ -44,6 +44,5 @@ public String decompileClassNode(ClassNode cn, byte[] bytes) @Override public void decompileToZip(String sourceJar, String zipName) { - } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java index f41c55958..4192fb7a8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/HTMLPane.java @@ -59,7 +59,7 @@ public static HTMLPane fromString(String text) text = text.replace("{fatJar}", String.valueOf(FAT_JAR)); text = text.replace("{java}", Configuration.java); text = text.replace("{javac}", Configuration.javac); - text = text.replace("{bcvDir}", BCVDir.getAbsolutePath()); + text = text.replace("{bcvDir}", BCV_DIR.getAbsolutePath()); text = text.replace("{python}", Configuration.python2 + " " + (Configuration.python2Extra ? "-2" : "")); text = text.replace("{python3}", Configuration.python3 + " " + (Configuration.python3Extra ? "-3" : "")); text = text.replace("{rt}", Configuration.rt); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java index b46375fcb..e9aa0c5a7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/LAFTheme.java @@ -49,8 +49,7 @@ public enum LAFTheme 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), - ; + HIGH_CONTRAST_LIGHT("High Contrast Light Theme", RSTATheme.THEME_MATCH, TranslatedComponents.HIGH_CONTRAST_LIGHT_THEME); private final String readableName; private final RSTATheme rstaTheme; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/RSTATheme.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/RSTATheme.java index 3134b8c02..8e3fc46ce 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/RSTATheme.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/theme/RSTATheme.java @@ -38,7 +38,12 @@ public enum RSTATheme 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_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; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java index 148839fe0..8fbb48ebb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java @@ -45,7 +45,8 @@ public void obfuscate() { FieldNode f = (FieldNode) o; String newName = generateUniqueName(stringLength); - ASMResourceUtil.renameFieldNode(c.name, f.name, f.desc, null, newName, null); + ASMResourceUtil.renameFieldNode(c.name, f.name, f.desc, + null, newName, null); f.name = newName; } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java index e3c62936e..bb73264fb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java @@ -50,7 +50,8 @@ public void obfuscate() if (!m.name.equals("main") && !m.name.equals("") && !m.name.equals("")) { String newName = generateUniqueName(stringLength); - ASMResourceUtil.renameMethodNode(c.name, m.name, m.desc, null, newName, null); + ASMResourceUtil.renameMethodNode(c.name, m.name, m.desc, + null, newName, null); } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java index cf01e028c..650a48c23 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java @@ -176,7 +176,11 @@ public Object mapValue(Object value) if (value instanceof Handle) { Handle h = (Handle) value; - return new Handle(h.getTag(), mapType(h.getOwner()), mapMethodName(h.getOwner(), h.getName(), h.getDesc()), mapMethodDesc(h.getDesc()), h.getTag() == Opcodes.H_INVOKEINTERFACE); + return new Handle(h.getTag(), + mapType(h.getOwner()), + mapMethodName(h.getOwner(), h.getName(), h.getDesc()), + mapMethodDesc(h.getDesc()), + h.getTag() == Opcodes.H_INVOKEINTERFACE); } return value; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java index ef538d62a..d4d406dd3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java @@ -39,7 +39,7 @@ public static void open() { if (Configuration.runningObfuscation) { - BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" + "."); + BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish."); return; } @@ -75,9 +75,6 @@ public void obfuscate() String newName = generateUniqueName(stringLength); BytecodeViewer.refactorer.getHooks().addClass(new MappingData(c.name, newName)); - - /*ASMUtil_OLD.renameClassNode(c.name, newName); - c.name = newName;*/ } System.out.println("Obfuscated class names."); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java index a374d16d1..c7434bd63 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java @@ -64,9 +64,6 @@ public void obfuscate() String newName = generateUniqueName(stringLength); BytecodeViewer.refactorer.getHooks().addField(new FieldMappingData(c.name, new MappingData(f.name, newName), f.desc)); - - /*ASMUtil_OLD.renameFieldNode(c.name, f.name, f.desc, null, newName, null); - f.name = newName;*/ } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java index c08643c9f..9a3765e5b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java @@ -40,7 +40,7 @@ public static void open() { if (Configuration.runningObfuscation) { - BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" + "."); + BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish."); return; } @@ -66,16 +66,20 @@ public void obfuscate() if ((m.access & Opcodes.ACC_NATIVE) != 0) continue; - if (m.access != Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PROTECTED && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED) + if (m.access != Opcodes.ACC_ABSTRACT + && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC + && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE + && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PROTECTED + && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC + && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PRIVATE + && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED) { if (!m.name.equals("main") && !m.name.equals("") && !m.name.equals("")) { String newName = generateUniqueName(stringLength); BytecodeViewer.refactorer.getHooks().addMethod(new MethodMappingData(c.name, new MappingData(m.name, newName), m.desc)); - - /*ASMUtil_OLD.renameMethodNode(c.name, m.name, m.desc, - null, newName, null);*/ } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java index 766eec002..74fec5574 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java @@ -45,9 +45,9 @@ public final class PluginManager { - private static final Map launchStrategies = new HashMap<>(); - private static final PluginFileFilter filter = new PluginFileFilter(); - private static final List pluginInstances = new ArrayList<>(); + private static final Map LAUNCH_STRATEGIES = new HashMap<>(); + private static final PluginFileFilter FILTER = new PluginFileFilter(); + private static final List PLUGIN_INSTANCES = new ArrayList<>(); //TODO this system needs to be redone, currently it will conflict if more than one plugin is ran at the same time // the solution is to tie the plugin object into the plugin console, @@ -63,21 +63,21 @@ public final class PluginManager static { - launchStrategies.put("jar", new CompiledJavaPluginLaunchStrategy()); - launchStrategies.put("java", new JavaPluginLaunchStrategy()); - launchStrategies.put("js", new JavascriptPluginLaunchStrategy()); + LAUNCH_STRATEGIES.put("jar", new CompiledJavaPluginLaunchStrategy()); + LAUNCH_STRATEGIES.put("java", new JavaPluginLaunchStrategy()); + LAUNCH_STRATEGIES.put("js", new JavascriptPluginLaunchStrategy()); GroovyPluginLaunchStrategy groovy = new GroovyPluginLaunchStrategy(); - launchStrategies.put("gy", groovy); - launchStrategies.put("groovy", groovy); + LAUNCH_STRATEGIES.put("gy", groovy); + LAUNCH_STRATEGIES.put("groovy", groovy); PythonPluginLaunchStrategy python = new PythonPluginLaunchStrategy(); - launchStrategies.put("py", python); - launchStrategies.put("python", python); + LAUNCH_STRATEGIES.put("py", python); + LAUNCH_STRATEGIES.put("python", python); RubyPluginLaunchStrategy ruby = new RubyPluginLaunchStrategy(); - launchStrategies.put("rb", ruby); - launchStrategies.put("ruby", ruby); + LAUNCH_STRATEGIES.put("rb", ruby); + LAUNCH_STRATEGIES.put("ruby", ruby); } /** @@ -106,10 +106,10 @@ public static void runPlugin(Plugin newPluginInstance) activePlugin = newPluginInstance; //clean the plugin list from dead threads - pluginInstances.removeIf(Plugin::isFinished); + PLUGIN_INSTANCES.removeIf(Plugin::isFinished); //add to the list of running instances - pluginInstances.add(newPluginInstance); + PLUGIN_INSTANCES.add(newPluginInstance); //start the plugin thread newPluginInstance.start(); @@ -124,10 +124,11 @@ public static void runPlugin(Plugin newPluginInstance) public static void runPlugin(File f) throws Throwable { String ext = f.getName().substring(f.getName().lastIndexOf('.') + 1); - PluginLaunchStrategy strategy = launchStrategies.get(ext); + PluginLaunchStrategy strategy = LAUNCH_STRATEGIES.get(ext); if (strategy == null) - throw new RuntimeException(String.format("No launch strategy for extension %s (%s)", ext, f.getAbsolutePath())); + throw new RuntimeException(String.format("No launch strategy for extension %s (%s)", + ext, f.getAbsolutePath())); Plugin p = strategy.run(f); @@ -147,7 +148,9 @@ public static void addExceptionUI(ExceptionUI ui) return; } - final String name = activePlugin.activeContainer == null ? "#" + (activeTabbedException.getTabbedPane().getTabCount() + 1) : activePlugin.activeContainer.name; + final String name = activePlugin.activeContainer == null + ? "#" + (activeTabbedException.getTabbedPane().getTabCount() + 1) + : activePlugin.activeContainer.name; ExceptionUI existingUI = exceptionTabs.get(name); @@ -198,22 +201,22 @@ public static void addConsole(PluginConsole console) public static void register(String name, PluginLaunchStrategy strat) { - launchStrategies.put(name, strat); + LAUNCH_STRATEGIES.put(name, strat); } public static Set pluginExtensions() { - return launchStrategies.keySet(); + return LAUNCH_STRATEGIES.keySet(); } public static Map getLaunchStrategies() { - return launchStrategies; + return LAUNCH_STRATEGIES; } public static FileFilter fileFilter() { - return filter; + return FILTER; } public static class PluginFileFilter extends FileFilter diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/TokenUtil.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/TokenUtil.java index b26cb0f6d..5d053d083 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/TokenUtil.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/TokenUtil.java @@ -13,6 +13,17 @@ public class TokenUtil public static Token getToken(final RSyntaxTextArea textArea, final @NotNull Token token) { String lexeme = token.getLexeme(); - return lexeme.isEmpty() || lexeme.equals(".") || lexeme.equals("(") || lexeme.equals(")") || lexeme.equals("[") || lexeme.equals("~") || lexeme.equals("-") || lexeme.equals("+") || lexeme.equals(" ") || lexeme.equals(";") || lexeme.equals(",") || lexeme.equals(">") ? textArea.modelToToken(textArea.getCaretPosition() - 1) : token; + return lexeme.isEmpty() + || lexeme.equals(".") + || lexeme.equals("(") + || lexeme.equals(")") + || lexeme.equals("[") + || lexeme.equals("~") + || lexeme.equals("-") + || lexeme.equals("+") + || lexeme.equals(" ") + || lexeme.equals(";") + || lexeme.equals(",") + || lexeme.equals(">") ? textArea.modelToToken(textArea.getCaretPosition() - 1) : token; } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java index ceab5e9de..f5fe393f9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java @@ -72,7 +72,8 @@ public void promptForExport() //if theres only one file in the container don't bother asking if (validContainers.size() >= 2) { - MultipleChoiceDialog dialog = new MultipleChoiceDialog("Bytecode Viewer - Select APK", "Which file would you like to export as an APK?", validContainersNames.toArray(new String[0])); + MultipleChoiceDialog dialog = new MultipleChoiceDialog("Bytecode Viewer - Select APK", + "Which file would you like to export as an APK?", validContainersNames.toArray(new String[0])); //TODO may be off by one container = (ResourceContainer) containers.stream().skip(dialog.promptChoice()); @@ -80,7 +81,8 @@ public void promptForExport() } else { - BytecodeViewer.showMessage("You can only export as APK from a valid APK file. Make sure Settings>Decode Resources is ticked on." + "\n\nTip: Try exporting as DEX, it doesn't rely on decoded APK resources"); + BytecodeViewer.showMessage("You can only export as APK from a valid APK file. Make sure Settings>Decode Resources is ticked on." + + "\n\nTip: Try exporting as DEX, it doesn't rely on decoded APK resources"); return; } @@ -114,11 +116,14 @@ public void promptForExport() APKTool.buildAPK(new File(input), file, finalContainer); BytecodeViewer.updateBusyStatus(false); }, "Process APK"); + buildAPKThread.start(); }, "Jar Export"); + saveThread.start(); } }, "Resource Export"); + exportThread.start(); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java index 30b03d97e..5b7c6b35a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java @@ -81,11 +81,14 @@ public void promptForExport() BytecodeViewer.updateBusyStatus(false); }, "Process DEX"); + saveAsDex.start(); }, "Jar Export"); + saveAsJar.start(); } }, "Resource Export"); + exportThread.start(); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java index 311501232..851d6381f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/SecurityMan.java @@ -120,7 +120,7 @@ else if (normalizedPath.startsWith(Constants.SYSTEM_TEMP_DIRECTORY.toLowerCase() //can only write into BCV dir, so anything executing from here has probably been dropped try { - if (normalizedPath.startsWith(Constants.BCVDir.getCanonicalPath().toLowerCase())) + if (normalizedPath.startsWith(Constants.BCV_DIR.getCanonicalPath().toLowerCase())) blocked = true; } catch (IOException e) @@ -373,7 +373,7 @@ public void checkWrite(String file) return; //can only write into BCV dir - if (file.startsWith(Constants.BCVDir.getCanonicalPath())) + if (file.startsWith(Constants.BCV_DIR.getCanonicalPath())) return; //can only write into system temp