diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 23681873..7c1572fc 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Objects; import javax.swing.*; @@ -17,7 +16,7 @@ import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bootloader.Boot; import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader; -import the.bytecode.club.bytecodeviewer.compilers.Compilers; +import the.bytecode.club.bytecodeviewer.compilers.Compiler; import the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.ResourcePanelCompileMode; @@ -87,6 +86,7 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * + Krakatau Assembly compile - Needs to be fixed * * TODO IN-PROGRESS: + * + Finish Compiler.JAVA_COMPILER * + Finish dragging code * + Finish right-click tab menu detection * + Fix hook inject for EZ-Injection @@ -411,7 +411,7 @@ public class BytecodeViewer { ClassNode origNode = (ClassNode) smali[0]; String smaliText = (String) smali[1]; - byte[] smaliCompiled = Compilers.smali.compile(smaliText, origNode.name); + byte[] smaliCompiled = Compiler.SMALI_ASSEMBLER.getCompiler().compile(smaliText, origNode.name); if (smaliCompiled != null) { @@ -443,7 +443,7 @@ public class BytecodeViewer { ClassNode origNode = (ClassNode) krakatau[0]; String krakatauText = (String) krakatau[1]; - byte[] krakatauCompiled = Compilers.krakatau.compile(krakatauText, origNode.name); + byte[] krakatauCompiled = Compiler.KRAKATAU_ASSEMBLER.getCompiler().compile(krakatauText, origNode.name); if (krakatauCompiled != null) { @@ -479,7 +479,7 @@ public class BytecodeViewer errConsole.setText("Error compiling class: " + origNode.name + nl + "Keep in mind most " + "decompilers cannot produce compilable classes" + nl + nl); - byte[] javaCompiled = Compilers.java.compile(javaText, origNode.name); + byte[] javaCompiled = Compiler.JAVA_COMPILER.getCompiler().compile(javaText, origNode.name); if (javaCompiled != null) { try { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java index 9b167265..4babf2f0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java @@ -9,7 +9,8 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; import org.objectweb.asm.tree.ClassNode; -import the.bytecode.club.bytecodeviewer.compilers.Compilers; +import the.bytecode.club.bytecodeviewer.compilers.Compiler; +import the.bytecode.club.bytecodeviewer.compilers.InternalCompiler; import the.bytecode.club.bytecodeviewer.decompilers.InternalDecompiler; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.plugin.preinstalled.EZInjection; @@ -264,8 +265,8 @@ public class BytecodeViewer { * * @return The wrapped Krakatau Assembler instance */ - public static the.bytecode.club.bytecodeviewer.compilers.Compiler getKrakatauCompiler() { - return Compilers.krakatau; + public static InternalCompiler getKrakatauCompiler() { + return Compiler.KRAKATAU_ASSEMBLER.getCompiler(); } /** @@ -273,7 +274,7 @@ public class BytecodeViewer { * * @return The wrapped Smali Assembler instance */ - public static the.bytecode.club.bytecodeviewer.compilers.Compiler getSmaliCompiler() { - return Compilers.smali; + public static InternalCompiler getSmaliCompiler() { + return Compiler.SMALI_ASSEMBLER.getCompiler(); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/Compiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/Compiler.java index bcdb4112..4050643f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/Compiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/Compiler.java @@ -19,13 +19,23 @@ package the.bytecode.club.bytecodeviewer.compilers; ***************************************************************************/ /** - * Used to represent all the compilers/assemblers BCV contains. + * A collection of all of the supported compilers/assemblers inside of BCV * * @author Konloch */ - -public abstract class Compiler { - - public abstract byte[] compile(String contents, String name); - +public enum Compiler +{ + KRAKATAU_ASSEMBLER(new KrakatauAssembler()), + SMALI_ASSEMBLER(new SmaliAssembler()), + JAVA_COMPILER(new JavaCompiler()), + ; + + private final InternalCompiler compiler; + + Compiler(InternalCompiler compiler) {this.compiler = compiler;} + + public InternalCompiler getCompiler() + { + return compiler; + } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/Compilers.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/Compilers.java deleted file mode 100644 index 023042db..00000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/Compilers.java +++ /dev/null @@ -1,7 +0,0 @@ -package the.bytecode.club.bytecodeviewer.compilers; - -public class Compilers { - public static Compiler krakatau = new KrakatauAssembler(); - public static Compiler smali = new SmaliAssembler(); - public static Compiler java = new JavaCompiler(); -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/InternalCompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/InternalCompiler.java new file mode 100644 index 00000000..6186457b --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/InternalCompiler.java @@ -0,0 +1,32 @@ +package the.bytecode.club.bytecodeviewer.compilers; + +/*************************************************************************** + * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * + * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +/** + * Used to represent a single the compiler/assembler + * + * @author Konloch + */ + +public abstract class InternalCompiler +{ + + public abstract byte[] compile(String contents, String name); + +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java index 6b81f34d..fed9cd80 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/JavaCompiler.java @@ -37,10 +37,12 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * @author Konloch */ -public class JavaCompiler extends Compiler { +public class JavaCompiler extends InternalCompiler +{ @Override - public byte[] compile(String contents, String name) { + public byte[] compile(String contents, String name) + { String fileStart = tempDirectory + fs + "temp" + MiscUtils.randomString(12) + fs; String fileStart2 = tempDirectory + fs + "temp" + MiscUtils.randomString(12) + fs; File java = new File(fileStart + fs + name + ".java"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java index 8bea5da6..05418429 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/KrakatauAssembler.java @@ -36,7 +36,8 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * * @author Konloch */ -public class KrakatauAssembler extends Compiler { +public class KrakatauAssembler extends InternalCompiler +{ @Override public byte[] compile(String contents, String name) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/SmaliAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/SmaliAssembler.java index 4b857f5e..2f71e430 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/SmaliAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/SmaliAssembler.java @@ -35,7 +35,8 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * @author Konloch */ -public class SmaliAssembler extends Compiler { +public class SmaliAssembler extends InternalCompiler +{ @Override public byte[] compile(String contents, String name) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java index 07a28244..27c939a5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java @@ -56,6 +56,7 @@ public class ImportResource implements Runnable for (final File file : files) { final String fn = file.getName(); + if (!file.exists()) { update = false; @@ -96,9 +97,13 @@ public class ImportResource implements Runnable } } } - } catch (final Exception e) { + } + catch (final Exception e) + { new ExceptionUI(e); - } finally { + } + finally + { BytecodeViewer.viewer.updateBusyStatus(false); if (update)