diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index bace70c9..2d415a15 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -1,12 +1,9 @@ package the.bytecode.club.bytecodeviewer; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import javax.swing.*; import com.google.gson.Gson; @@ -27,7 +24,6 @@ import the.bytecode.club.bytecodeviewer.resources.importing.ImportResource; import static the.bytecode.club.bytecodeviewer.Constants.*; import static the.bytecode.club.bytecodeviewer.Settings.addRecentPlugin; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentTypes.JAVA_AND_BYTECODE; import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; /*************************************************************************** @@ -114,6 +110,9 @@ import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; public class BytecodeViewer { + public static boolean EXPERIMENTAL_TAB_CODE = false; + public static boolean DEV_MODE = false; //if true error streams as preserved + public static String[] launchArgs; public static MainViewerGUI viewer = null; public static ClassNodeLoader loader = new ClassNodeLoader(); //might be insecure due to assholes targeting BCV, @@ -121,10 +120,8 @@ public class BytecodeViewer public static Refactorer refactorer = new Refactorer(); public static List files = new ArrayList<>(); //all of BCV's loaded files/classes/etc public static List createdProcesses = new ArrayList<>(); - public static final DecompilerViewComponent krakatau = new DecompilerViewComponent("Krakatau", JAVA_AND_BYTECODE); public static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - public static final boolean EXPERIMENTAL_TAB_CODE = false; - public static final boolean DEV_MODE = false; //if true error streams as preserved + private static final Thread versionChecker = new Thread(new VersionChecker(), "Version Checker"); private static final Thread pingBack = new Thread(new PingBack(), "Pingback"); private static final Thread installFatJar = new Thread(new InstallFatJar(), "Install Fat-Jar"); @@ -298,7 +295,10 @@ public class BytecodeViewer return null; } - + + /** + * Returns the File Container by the specific name + */ public static FileContainer getFileContainer(String name) { for (FileContainer container : files) @@ -307,11 +307,17 @@ public class BytecodeViewer return null; } - + + /** + * Returns all of the loaded File Containers + */ public static List getFiles() { return files; } - + + /** + * Returns a ClassNode by name specific namefrom a specific File Container + */ public static ClassNode getClassNode(FileContainer container, String name) { for (ClassNode c : container.classes) @@ -337,23 +343,11 @@ public class BytecodeViewer } /** - * Grab the byte array from the loaded Class object - * - * @param clazz - * @return - * @throws IOException + * Grab the byte array from the loaded Class object by getting the resource from the classloader */ - public static byte[] getClassFile(Class clazz) throws IOException + public static byte[] getClassFileBytes(Class clazz) throws IOException { - try (InputStream is = clazz.getResourceAsStream("/" + clazz.getName().replace('.', '/') + ".class"); - ByteArrayOutputStream baos = new ByteArrayOutputStream()) - { - int r; - byte[] buffer = new byte[8192]; - while ((r = Objects.requireNonNull(is).read(buffer)) >= 0) - baos.write(buffer, 0, r); - return baos.toByteArray(); - } + return ClassFileUtils.getClassFileBytes(clazz); } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java index 0a7e64a1..dd0350e8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java @@ -40,8 +40,8 @@ public enum Decompiler BYTECODE_DISASSEMBLER("Bytecode Disassembler", new BytecodeDisassembler(), new JRadioButtonMenuItem("Bytecode")), HEXCODE_VIEWER("Hexcode Viewer", null, new JRadioButtonMenuItem("Hexcode")), SMALI_DISASSEMBLER("Smali Disassembler", new SmaliDisassembler(), new DecompilerViewComponent("Smali", BYTECODE)), - KRAKATAU_DECOMPILER("Krakatau Decompiler", new KrakatauDecompiler(), BytecodeViewer.krakatau), - KRAKATAU_DISASSEMBLER("Krakatau Disassembler", new KrakatauDisassembler(), BytecodeViewer.krakatau), + KRAKATAU_DECOMPILER("Krakatau Decompiler", new KrakatauDecompiler(), DecompilerViewComponent.KRAKATAU), + KRAKATAU_DISASSEMBLER("Krakatau Disassembler", new KrakatauDisassembler(), DecompilerViewComponent.KRAKATAU), JD_DECOMPILER("JD-GUI Decompiler", new JDGUIDecompiler(), new DecompilerViewComponent("JD-GUI", JAVA)), JADX_DECOMPILER("JADX Decompiler", new JADXDecompiler(), new DecompilerViewComponent("JADX", JAVA)), ASM_TEXTIFY_DISASSEMBLER("ASM Disassembler", new ASMTextifierDecompiler(), new DecompilerViewComponent("ASM Textify", BYTECODE)), diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java index 99228073..8e9fda90 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java @@ -11,7 +11,7 @@ import the.bytecode.club.bytecodeviewer.decompilers.InternalDecompiler; import the.bytecode.club.bytecodeviewer.decompilers.jdgui.DirectoryLoader; import the.bytecode.club.bytecodeviewer.decompilers.jdgui.CommonPreferences; import the.bytecode.club.bytecodeviewer.decompilers.jdgui.PlainTextPrinter; -import the.bytecode.club.bytecodeviewer.decompilers.jdgui.ClassFileUtil; +import the.bytecode.club.bytecodeviewer.decompilers.jdgui.JDGUIClassFileUtil; import me.konloch.kontainer.io.DiskReader; import org.jd.core.v1.ClassFileToJavaSourceDecompiler; import org.objectweb.asm.tree.ClassNode; @@ -78,8 +78,8 @@ public class JDGUIDecompiler extends InternalDecompiler String pathToClass = tempClass.getAbsolutePath().replace('/', File.separatorChar).replace('\\', File.separatorChar); - String directoryPath = ClassFileUtil.ExtractDirectoryPath(pathToClass); - String internalPath = ClassFileUtil.ExtractInternalPath(directoryPath, pathToClass); + String directoryPath = JDGUIClassFileUtil.ExtractDirectoryPath(pathToClass); + String internalPath = JDGUIClassFileUtil.ExtractInternalPath(directoryPath, pathToClass); CommonPreferences preferences = new CommonPreferences() { @Override diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/ClassFileUtil.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java similarity index 99% rename from src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/ClassFileUtil.java rename to src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java index 96ed3724..f679af07 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/ClassFileUtil.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java @@ -13,7 +13,8 @@ import org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException; import org.jd.core.v1.service.deserializer.classfile.ClassFileReader; -public class ClassFileUtil { +public class JDGUIClassFileUtil +{ public static final char INTERNAL_PACKAGE_SEPARATOR = '/'; public static final String CLASS_FILE_SUFFIX = ".class"; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java index 8748541e..3243184a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java @@ -7,6 +7,8 @@ import the.bytecode.club.bytecodeviewer.util.RefreshWorkPane; import javax.swing.*; +import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentTypes.JAVA_AND_BYTECODE; + /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * @@ -31,6 +33,8 @@ import javax.swing.*; */ public class DecompilerViewComponent { + public static final DecompilerViewComponent KRAKATAU = new DecompilerViewComponent("Krakatau", JAVA_AND_BYTECODE); + private final String name; private final JMenu menu; private final DecompilerComponentTypes types; @@ -38,7 +42,8 @@ public class DecompilerViewComponent private final JRadioButtonMenuItem bytecode = new TranslatedJRadioButtonMenuItem("Bytecode", Translation.BYTECODE); private final JCheckBoxMenuItem editable = new TranslatedJCheckBoxMenuItem("Editable", Translation.EDITABLE); - public DecompilerViewComponent(String name, DecompilerComponentTypes types) { + public DecompilerViewComponent(String name, DecompilerComponentTypes types) + { this.name = name; this.menu = new JMenu(name); this.types = types; @@ -92,4 +97,4 @@ public class DecompilerViewComponent BYTECODE, JAVA_AND_BYTECODE } -} +} \ No newline at end of file diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/ClassFileUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/ClassFileUtils.java new file mode 100644 index 00000000..18872567 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/ClassFileUtils.java @@ -0,0 +1,29 @@ +package the.bytecode.club.bytecodeviewer.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; + +/** + * @author Konloch + * @since 7/6/2021 + */ +public class ClassFileUtils +{ + /** + * Grab the byte array from the loaded Class object by getting the resource from the classloader + */ + public static byte[] getClassFileBytes(Class clazz) throws IOException + { + try (InputStream is = clazz.getResourceAsStream("/" + clazz.getName().replace('.', '/') + ".class"); + ByteArrayOutputStream baos = new ByteArrayOutputStream()) + { + int r; + byte[] buffer = new byte[8192]; + while ((r = Objects.requireNonNull(is).read(buffer)) >= 0) + baos.write(buffer, 0, r); + return baos.toByteArray(); + } + } +}