"); + this.printStream.print("JD-CL Version: " + "0.1.0" + "
"); + this.printStream.print("JD-Core Version: " + CoreConstants.JD_CORE_VERSION); + this.printStream.print("
+ * + * This stream can be used with the Message.writeTo method to + * generate a message that uses the local plaform's line terminator + * for the purpose of (e.g.) saving the message to a local file. + */ +public class NewlineOutputStream extends FilterOutputStream { + private int lastb = -1; + private static byte[] newline; + + public NewlineOutputStream(OutputStream os) { + super(os); + if (newline == null) { + String s = System.getProperty("line.separator"); + if (s == null || s.length() <= 0) + s = "\n"; + try { + newline = s.getBytes("iso-8859-1"); // really us-ascii + } catch (UnsupportedEncodingException ex) { + // should never happen + newline = new byte[] { (byte)'\n' }; + } + } + } + + public void write(int b) throws IOException { + if (b == '\r') { + out.write(newline); + } else if (b == '\n') { + if (lastb != '\r') + out.write(newline); + } else { + out.write(b); + } + lastb = b; + } + + public void write(byte b[]) throws IOException { + write(b, 0, b.length); + } + + public void write(byte b[], int off, int len) throws IOException { + for (int i = 0 ; i < len ; i++) { + write(b[off + i]); + } + } +} \ No newline at end of file diff --git a/src/the/bytecode/club/bytecodeviewer/decompilers/JDGUIDecompiler.java b/src/the/bytecode/club/bytecodeviewer/decompilers/JDGUIDecompiler.java index 34262db1..866755a6 100644 --- a/src/the/bytecode/club/bytecodeviewer/decompilers/JDGUIDecompiler.java +++ b/src/the/bytecode/club/bytecodeviewer/decompilers/JDGUIDecompiler.java @@ -1,55 +1,43 @@ package the.bytecode.club.bytecodeviewer.decompilers; -import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStreamWriter; +import java.io.InputStreamReader; +import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.zip.ZipException; -import java.util.zip.ZipOutputStream; +import jd.cli.loader.DirectoryLoader; +import jd.cli.loader.JarLoader; +import jd.cli.preferences.CommonPreferences; +import jd.cli.util.ClassFileUtil; +import jd.core.loader.Loader; +import jd.core.process.DecompilerImpl; +import me.konloch.kontainer.io.DiskReader; import me.konloch.kontainer.io.DiskWriter; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; -import com.strobel.core.StringUtilities; -import com.strobel.decompiler.DecompilationOptions; -import com.strobel.decompiler.DecompilerSettings; -import com.strobel.decompiler.PlainTextOutput; -import com.strobel.decompiler.languages.java.JavaFormattingOptions; -import com.strobel.assembler.InputTypeLoader; -import com.strobel.assembler.metadata.Buffer; -import com.strobel.assembler.metadata.ITypeLoader; -import com.strobel.assembler.metadata.JarTypeLoader; -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; import the.bytecode.club.bytecodeviewer.MiscUtils; +import the.bytecode.club.bytecodeviewer.ZipUtils; +import jd.cli.printer.text.PlainTextPrinter; /** * JDCore Decompiler Wrapper * * @author Konloch + * @author JD-Core developers * */ public class JDGUIDecompiler extends Decompiler { - + @Override public void decompileToClass(String className, String classNameSaved) { ClassNode cn = BytecodeViewer.getClassNode(className); @@ -66,12 +54,65 @@ public class JDGUIDecompiler extends Decompiler { String contents = decompileClassNode(cn, cw.toByteArray()); DiskWriter.replaceFile(classNameSaved, contents, false); } - + @Override public String decompileClassNode(ClassNode cn, byte[] b) { String exception = ""; try { - String decompiledSource = "dicks WIP"; + final File tempDirectory = new File(BytecodeViewer.tempDirectory + BytecodeViewer.fs + MiscUtils.randomString(32) + BytecodeViewer.fs); + tempDirectory.mkdir(); + final File tempClass = new File(tempDirectory.getAbsolutePath() + BytecodeViewer.fs + cn.name + ".class"); + final File tempJava = new File(tempDirectory.getAbsolutePath() + BytecodeViewer.fs + cn.name + ".java"); + + if(cn.name.contains("/")) { + String[] raw = cn.name.split("/"); + String path = tempDirectory.getAbsolutePath() + BytecodeViewer.fs; + for(int i = 0; i < raw.length-1; i++) { + path += raw[i] + BytecodeViewer.fs; + File f = new File(path); + f.mkdir(); + } + } + + try { + final FileOutputStream fos = new FileOutputStream(tempClass); + + fos.write(b); + + fos.close(); + } catch (final IOException e) { + new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); + } + + + String pathToClass = tempClass.getAbsolutePath().replace('/', File.separatorChar).replace('\\', File.separatorChar); + String directoryPath = ClassFileUtil.ExtractDirectoryPath(pathToClass); + + String internalPath = ClassFileUtil.ExtractInternalPath(directoryPath, pathToClass); + + CommonPreferences preferences = new CommonPreferences() { + @Override + public boolean isShowLineNumbers() { + return false; + } + @Override + public boolean isMergeEmptyLines() { + return true; + } + }; + + DirectoryLoader loader = new DirectoryLoader(new File(directoryPath)); + + //PrintStream ps = new PrintStream("test.html"); + //HtmlPrinter printer = new HtmlPrinter(ps); + PrintStream ps = new PrintStream(tempJava.getAbsolutePath()); + PlainTextPrinter printer = new PlainTextPrinter(preferences, ps); + + jd.core.Decompiler decompiler = new DecompilerImpl(); + decompiler.decompile(preferences, loader, printer, internalPath); + + String decompiledSource = "Error with decompilation."; + decompiledSource = DiskReader.loadAsString(tempJava.getAbsolutePath()); return decompiledSource; } catch (Exception e) { @@ -86,6 +127,5 @@ public class JDGUIDecompiler extends Decompiler { @Override public void decompileToZip(String zipName) { - } } \ No newline at end of file diff --git a/src/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java b/src/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java index 32c88958..0756965b 100644 --- a/src/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java +++ b/src/the/bytecode/club/bytecodeviewer/gui/AboutWindow.java @@ -55,7 +55,7 @@ public class AboutWindow extends JFrame { "CTRL + T: Compile"+BytecodeViewer.nl+ "CTRL + S: Save classes as zip"+BytecodeViewer.nl+ "CTRL + R: Run (EZ-Inject) - dynamically load the classes and invoke a main class"+ - "\r\n\r\nIt uses code from the following:\r\n J-RET by WaterWolf\r\n JHexPane by Sam Koivu\r\n RSynaxPane by Robert Futrell\r\n Commons IO by Apache\r\n ASM by OW2\r\n FernFlower by Stiver\r\n Procyon by Mstrobel\r\n CFR by Lee Benfield\r\n CFIDE by Bibl\r\n Smali by JesusFreke\r\n Dex2Jar by pxb1..?\r\n Krakatau by Storyyeller\r\n\r\nIf you're interested in Java Reverse Engineering, join The Bytecode Club\r\nhttps://the.bytecode.club"); + "\r\n\r\nIt uses code from the following:\r\n J-RET by WaterWolf\r\n JHexPane by Sam Koivu\r\n RSynaxPane by Robert Futrell\r\n Commons IO by Apache\r\n ASM by OW2\r\n FernFlower by Stiver\r\n Procyon by Mstrobel\r\n CFR by Lee Benfield\r\n CFIDE by Bibl\r\n Smali by JesusFreke\r\n Dex2Jar by pxb1..?\r\n Krakatau by Storyyeller\r\n JD-GUI + JD-Core by The Java-Decompiler Team\r\n\r\nIf you're interested in Java Reverse Engineering, join The Bytecode Club\r\nhttps://the.bytecode.club"); } diff --git a/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 7cde247d..d6264ab2 100644 --- a/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -826,7 +826,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { JOptionPane pane = new JOptionPane( "What decompiler will you use?"); Object[] options = new String[] { "Procyon", "CFR", - "Fernflower", "Krakatau", "JD-GUI", "Cancel" }; + "Fernflower", "Krakatau", "Cancel" }; pane.setOptions(options); JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Select Decompiler"); @@ -895,22 +895,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { t.start(); } - if (result == 4) { - Thread t = new Thread() { - @Override - public void run() { - try { - Decompiler.jdgui.decompileToZip(path); - BytecodeViewer.viewer.setIcon(false); - } catch (Exception e) { - new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); - } - } - }; - t.start(); - } - - if(result == 5) { + if(result == 4) { BytecodeViewer.viewer.setIcon(false); } } @@ -963,7 +948,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { JOptionPane pane = new JOptionPane( "What decompiler will you use?"); Object[] options = new String[] { "Procyon", "CFR", - "Fernflower", "Krakatau", "DJ GUI", "Cancel" }; + "Fernflower", "Krakatau", "Cancel" }; pane.setOptions(options); JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Select Decompiler"); @@ -1034,23 +1019,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { }; t.start(); } - if (result == 4) { - Thread t = new Thread() { - @Override - public void run() { - try { - Decompiler.jdgui.decompileToClass(s,path); - BytecodeViewer.viewer.setIcon(false); - } catch (Exception e) { - new the.bytecode.club.bytecodeviewer.api.ExceptionUI( - e); - } - } - }; - t.start(); - } - - if(result == 5) { + if(result == 4) { BytecodeViewer.viewer.setIcon(false); } } diff --git a/src/the/bytecode/club/bytecodeviewer/gui/SearchingPane.java b/src/the/bytecode/club/bytecodeviewer/gui/SearchingPane.java index 2d1bc5a8..f30f4b8c 100644 --- a/src/the/bytecode/club/bytecodeviewer/gui/SearchingPane.java +++ b/src/the/bytecode/club/bytecodeviewer/gui/SearchingPane.java @@ -191,7 +191,7 @@ public class SearchingPane extends VisibleComponent { final ClassNode fN = BytecodeViewer.getClassNode(className); if (fN != null) { MainViewerGUI.getComponent(FileNavigationPane.class) - .openClassFileToWorkSpace(className, fN); + .openClassFileToWorkSpace(className+".class", fN); } System.out.println(className); diff --git a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/GroovyPluginLaunchStrategy.java b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/GroovyPluginLaunchStrategy.java index debadc07..e405d8bd 100644 --- a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/GroovyPluginLaunchStrategy.java +++ b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/GroovyPluginLaunchStrategy.java @@ -11,6 +11,7 @@ import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.plugin.PluginLaunchStrategy; /** + * @author Konloch * @author Bibl (don't ban me pls) * @created 1 Jun 2015 */ diff --git a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/JavaPluginLaunchStrategy.java b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/JavaPluginLaunchStrategy.java index 262085b5..3198483e 100644 --- a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/JavaPluginLaunchStrategy.java +++ b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/JavaPluginLaunchStrategy.java @@ -10,6 +10,7 @@ import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.plugin.PluginLaunchStrategy; /** + * @author Konloch * @author Bibl (don't ban me pls) * @created 1 Jun 2015 */ diff --git a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/PythonPluginLaunchStrategy.java b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/PythonPluginLaunchStrategy.java index df886914..391080c6 100644 --- a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/PythonPluginLaunchStrategy.java +++ b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/PythonPluginLaunchStrategy.java @@ -11,6 +11,7 @@ import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.plugin.PluginLaunchStrategy; /** + * @author Konloch * @author Bibl (don't ban me pls) * @created 1 Jun 2015 */ diff --git a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/RubyPluginLaunchStrategy.java b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/RubyPluginLaunchStrategy.java index 536d697a..0fb03443 100644 --- a/src/the/bytecode/club/bytecodeviewer/plugin/strategies/RubyPluginLaunchStrategy.java +++ b/src/the/bytecode/club/bytecodeviewer/plugin/strategies/RubyPluginLaunchStrategy.java @@ -11,6 +11,7 @@ import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.plugin.PluginLaunchStrategy; /** + * @author Konloch * @author Bibl (don't ban me pls) * @created 1 Jun 2015 */ diff --git a/src/the/bytecode/club/bytecodeviewer/searching/FieldCallSearch.java b/src/the/bytecode/club/bytecodeviewer/searching/FieldCallSearch.java index bee98dd3..83daf219 100644 --- a/src/the/bytecode/club/bytecodeviewer/searching/FieldCallSearch.java +++ b/src/the/bytecode/club/bytecodeviewer/searching/FieldCallSearch.java @@ -103,13 +103,13 @@ public class FieldCallSearch implements SearchTypeDetails { .toLowerCase()); } else { - if (name != null && !name.contains(min.name)) { + if (name != null && !min.name.contains(name)) { continue; } - if (owner != null && !owner.contains(min.owner)) { + if (owner != null && !min.owner.contains(owner)) { continue; } - if (desc != null && !desc.contains(min.desc)) { + if (desc != null && !min.desc.contains(desc)) { continue; } String desc2 = method.desc; diff --git a/src/the/bytecode/club/bytecodeviewer/searching/MethodCallSearch.java b/src/the/bytecode/club/bytecodeviewer/searching/MethodCallSearch.java index 7312f876..27f5edc8 100644 --- a/src/the/bytecode/club/bytecodeviewer/searching/MethodCallSearch.java +++ b/src/the/bytecode/club/bytecodeviewer/searching/MethodCallSearch.java @@ -102,13 +102,13 @@ public class MethodCallSearch implements SearchTypeDetails { + OpcodeInfo.OPCODES.get(insnNode.opcode()) .toLowerCase()); } else { - if (name != null && !name.contains(min.name)) { + if (name != null && !min.name.contains(name)) { continue; } - if (owner != null && !owner.contains(min.owner)) { + if (owner != null && !min.owner.contains(owner)) { continue; } - if (desc != null && !desc.contains(min.desc)) { + if (desc != null && !min.desc.contains(desc)) { continue; } String desc2 = method.desc;