Compiler & Assembler Cleanup
This commit is contained in:
parent
efaae70d36
commit
eadd35174e
9 changed files with 74 additions and 29 deletions
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 enum Compiler
|
||||
{
|
||||
KRAKATAU_ASSEMBLER(new KrakatauAssembler()),
|
||||
SMALI_ASSEMBLER(new SmaliAssembler()),
|
||||
JAVA_COMPILER(new JavaCompiler()),
|
||||
;
|
||||
|
||||
public abstract class Compiler {
|
||||
private final InternalCompiler compiler;
|
||||
|
||||
public abstract byte[] compile(String contents, String name);
|
||||
Compiler(InternalCompiler compiler) {this.compiler = compiler;}
|
||||
|
||||
public InternalCompiler getCompiler()
|
||||
{
|
||||
return compiler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* Used to represent a single the compiler/assembler
|
||||
*
|
||||
* @author Konloch
|
||||
*/
|
||||
|
||||
public abstract class InternalCompiler
|
||||
{
|
||||
|
||||
public abstract byte[] compile(String contents, String name);
|
||||
|
||||
}
|
|
@ -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");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue