diff --git a/BytecodeViewer Beta 1.2.jar b/BytecodeViewer Beta 1.2.jar index c9737be1..f1708921 100644 Binary files a/BytecodeViewer Beta 1.2.jar and b/BytecodeViewer Beta 1.2.jar differ diff --git a/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 679116c1..45a5b02b 100644 --- a/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -115,6 +115,8 @@ import the.bytecode.club.bytecodeviewer.plugins.PluginManager; * 10/16/2014 - Added Replace Strings plugin. * 10/16/2014 - Added a loading icon that displays whenever a background task is being executed. * 10/19/2014 - Fixed harcoded \\. + * 10/19/2014 - Started importing Procyon and CFR decompilers. + * 10/19/2014 - Partially finished importing Procyon and CFR, just need to finish export java files as zip. * * @author Konloch * diff --git a/src/the/bytecode/club/bytecodeviewer/decompilers/java/ProcyonDecompiler.java b/src/the/bytecode/club/bytecodeviewer/decompilers/java/ProcyonDecompiler.java index 23971a56..963b7ea5 100644 --- a/src/the/bytecode/club/bytecodeviewer/decompilers/java/ProcyonDecompiler.java +++ b/src/the/bytecode/club/bytecodeviewer/decompilers/java/ProcyonDecompiler.java @@ -3,19 +3,31 @@ package the.bytecode.club.bytecodeviewer.decompilers.java; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStreamWriter; - -import me.konloch.kontainer.io.DiskReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; -import com.strobel.decompiler.Decompiler; +import com.strobel.decompiler.DecompilationOptions; import com.strobel.decompiler.DecompilerSettings; import com.strobel.decompiler.PlainTextOutput; +import com.strobel.assembler.InputTypeLoader; +import com.strobel.assembler.metadata.Buffer; +import com.strobel.assembler.metadata.ITypeLoader; +import com.strobel.assembler.metadata.MetadataSystem; +import com.strobel.assembler.metadata.TypeDefinition; +import com.strobel.assembler.metadata.TypeReference; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.JarUtils; + +/** + * + * @author Konloch + * @author DeathMarine + * + */ public class ProcyonDecompiler extends JavaDecompiler { @@ -40,40 +52,30 @@ public class ProcyonDecompiler extends JavaDecompiler { e.printStackTrace(); } - File tempJava = new File(fileStart + getClassNumber(fileStart, ".java") + ".java"); + + DecompilerSettings settings = new DecompilerSettings(); + LuytenTypeLoader typeLoader = new LuytenTypeLoader(); + MetadataSystem metadataSystem = new MetadataSystem(typeLoader); + TypeReference type = metadataSystem.lookupType(tempClass.getCanonicalPath()); + + DecompilationOptions decompilationOptions = new DecompilationOptions(); + decompilationOptions.setSettings(DecompilerSettings.javaDefaults()); + decompilationOptions.setFullDecompilation(true); + + TypeDefinition resolvedType = null; + if (type == null || ((resolvedType = type.resolve()) == null)) { + throw new Exception("Unable to resolve type."); + } + StringWriter stringwriter = new StringWriter(); + settings.getLanguage().decompileType(resolvedType, + new PlainTextOutput(stringwriter), decompilationOptions); + String decompiledSource = stringwriter.toString(); + - final FileOutputStream stream = new FileOutputStream(tempJava); - - try { - final OutputStreamWriter writer = new OutputStreamWriter(stream); - final PlainTextOutput p = new PlainTextOutput(writer); - - try { - Decompiler.decompile( - cn.getClass().getCanonicalName(), - p, - DecompilerSettings.javaDefaults() - ); - } finally { - writer.close(); - } - } - finally { - stream.close(); - } - - - String s = DiskReader.loadAsString(tempJava.getAbsolutePath()); - - tempJava.delete(); - tempClass.delete(); - - return s; + return decompiledSource; + } catch(Exception e) { + e.printStackTrace(); } - catch (final Exception e) { - e.printStackTrace(); - } - return "Procyon error! Send the stacktrace to Konloch at http://the.bytecode.club or konloch@gmail.com"; } @@ -121,5 +123,37 @@ public class ProcyonDecompiler extends JavaDecompiler { BytecodeViewer.showMessage("ProcyonDecompiler currently doesn't decompile as zip, please wait till 1.3 of Bytecode Viewer."); } + + + /** + * + * @author DeathMarine + * + */ + public final class LuytenTypeLoader implements ITypeLoader { + private final List _typeLoaders; + + public LuytenTypeLoader() { + _typeLoaders = new ArrayList(); + _typeLoaders.add(new InputTypeLoader()); + } + + public final List getTypeLoaders() { + return _typeLoaders; + } + + @Override + public boolean tryLoadType(final String internalName, final Buffer buffer) { + for (final ITypeLoader typeLoader : _typeLoaders) { + if (typeLoader.tryLoadType(internalName, buffer)) { + return true; + } + + buffer.reset(); + } + + return false; + } + } }