Update JD GUI to 1.6.6

This commit is contained in:
Nico Mexis 2021-04-13 11:32:35 +02:00
parent 07c6d16af8
commit a2fe9b4f2d
No known key found for this signature in database
GPG key ID: 27D6E17CE092AB78
16 changed files with 162 additions and 639 deletions

Binary file not shown.

BIN
libs/jd-gui-1.6.6.jar Normal file

Binary file not shown.

View file

@ -634,7 +634,7 @@ the "copyright" line and a pointer to where the full notice is found.
JD-GUI, a standalone graphical utility that displays Java sources from
CLASS files
Copyright (C) 2008-2015 Emmanuel Dupuy
Copyright (C) 2008-2019 Emmanuel Dupuy
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
@ -654,7 +654,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
JD-GUI Copyright (C) 2008-2015 Emmanuel Dupuy
JD-GUI Copyright (C) 2008-2019 Emmanuel Dupuy
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@ -673,4 +673,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View file

@ -159,9 +159,9 @@
<dependency>
<groupId>com.jd</groupId>
<artifactId>jd-gui</artifactId>
<version>1.0.0-RC4</version>
<version>1.6.6</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/jd-gui-1.0.0-RC4.jar</systemPath>
<systemPath>${project.basedir}/libs/jd-gui-1.6.6.jar</systemPath>
</dependency>
<dependency>
<groupId>org.tinyjee.jgraphx</groupId>

View file

@ -634,7 +634,7 @@ the "copyright" line and a pointer to where the full notice is found.
JD-GUI, a standalone graphical utility that displays Java sources from
CLASS files
Copyright (C) 2008-2015 Emmanuel Dupuy
Copyright (C) 2008-2019 Emmanuel Dupuy
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
@ -654,7 +654,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
JD-GUI Copyright (C) 2008-2015 Emmanuel Dupuy
JD-GUI Copyright (C) 2008-2019 Emmanuel Dupuy
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@ -673,4 +673,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View file

@ -2,12 +2,13 @@ package jd.cli;
import java.io.File;
import java.io.PrintStream;
import java.util.ServiceLoader;
import jd.cli.loader.DirectoryLoader;
import jd.cli.preferences.CommonPreferences;
import jd.cli.printer.text.PlainTextPrinter;
import jd.cli.util.ClassFileUtil;
import jd.core.Decompiler;
import jd.core.process.DecompilerImpl;
import org.jd.core.v1.ClassFileToJavaSourceDecompiler;
import org.jd.core.v1.api.Decompiler;
public class Main {
@ -39,8 +40,8 @@ public class Main {
PrintStream ps = new PrintStream("test.txt");
PlainTextPrinter printer = new PlainTextPrinter(preferences, ps);
Decompiler decompiler = new DecompilerImpl();
decompiler.decompile(preferences, loader, printer, internalPath);
Decompiler decompiler = new ClassFileToJavaSourceDecompiler();
decompiler.decompile(loader, printer, internalPath, preferences.getPreferences());
System.out.println("done.");

View file

@ -1,7 +1,7 @@
package jd.cli.loader;
import java.io.File;
import jd.core.loader.Loader;
import org.jd.core.v1.api.loader.Loader;
public abstract class BaseLoader implements Loader {
protected String codebase;

View file

@ -1,11 +1,11 @@
package jd.cli.loader;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import jd.core.loader.LoaderException;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.jd.core.v1.api.loader.LoaderException;
public class DirectoryLoader extends BaseLoader {
@ -17,14 +17,14 @@ public class DirectoryLoader extends BaseLoader {
}
@Override
public DataInputStream load(String internalPath)
public byte[] load(String internalPath)
throws LoaderException {
File file = new File(this.codebase, internalPath);
try {
return new DataInputStream(
return IOUtils.toByteArray(
new BufferedInputStream(new FileInputStream(file)));
} catch (FileNotFoundException e) {
} catch (IOException e) {
throw new LoaderException(
"'" + file.getAbsolutePath() + "' not found.");
}

View file

@ -1,11 +1,11 @@
package jd.cli.loader;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import jd.core.loader.LoaderException;
import org.apache.commons.io.IOUtils;
import org.jd.core.v1.api.loader.LoaderException;
public class JarLoader extends BaseLoader {
@ -26,7 +26,7 @@ public class JarLoader extends BaseLoader {
}
@Override
public DataInputStream load(String internalPath)
public byte[] load(String internalPath)
throws LoaderException {
ZipEntry zipEntry = this.zipFile.getEntry(internalPath);
@ -35,7 +35,7 @@ public class JarLoader extends BaseLoader {
}
try {
return new DataInputStream(this.zipFile.getInputStream(zipEntry));
return IOUtils.toByteArray(this.zipFile.getInputStream(zipEntry));
} catch (IOException e) {
throw new LoaderException("Error reading '" + internalPath + "'");
}

View file

@ -3,7 +3,7 @@ package jd.cli.loader;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import jd.core.loader.LoaderException;
import org.jd.core.v1.api.loader.LoaderException;
public class LoaderManager {
protected final static String JAR_SUFFIX = ".jar";

View file

@ -1,8 +1,12 @@
package jd.cli.preferences;
import jd.core.preferences.Preferences;
import java.util.HashMap;
import java.util.Map;
public class CommonPreferences extends Preferences {
public class CommonPreferences {
private Map<String, Object> preferences;
protected boolean showDefaultConstructor;
protected boolean realignmentLineNumber;
protected boolean showPrefixThis;
protected boolean mergeEmptyLines;
protected boolean unicodeEscape;
@ -13,17 +17,28 @@ public class CommonPreferences extends Preferences {
this.mergeEmptyLines = false;
this.unicodeEscape = false;
this.showLineNumbers = true;
this.preferences = new HashMap<>();
}
public CommonPreferences(
boolean showDefaultConstructor, boolean realignmentLineNumber,
boolean showPrefixThis, boolean mergeEmptyLines,
boolean unicodeEscape, boolean showLineNumbers) {
super(showDefaultConstructor, realignmentLineNumber);
this.showDefaultConstructor = showDefaultConstructor;
this.realignmentLineNumber = realignmentLineNumber;
this.showPrefixThis = showPrefixThis;
this.mergeEmptyLines = mergeEmptyLines;
this.unicodeEscape = unicodeEscape;
this.showLineNumbers = showLineNumbers;
this.preferences = new HashMap<>();
}
public boolean isShowDefaultConstructor() {
return showDefaultConstructor;
}
public boolean isRealignmentLineNumber() {
return realignmentLineNumber;
}
public boolean isShowPrefixThis() {
@ -41,4 +56,8 @@ public class CommonPreferences extends Preferences {
public boolean isShowLineNumbers() {
return showLineNumbers;
}
public Map<String, Object> getPreferences() {
return preferences;
}
}

View file

@ -2,8 +2,7 @@ package jd.cli.printer.html;
import java.io.PrintStream;
import jd.cli.util.VersionUtil;
import jd.core.CoreConstants;
import jd.core.printer.Printer;
import org.jd.core.v1.api.printer.Printer;
/*
* CSS
@ -50,64 +49,6 @@ public class HtmlPrinter implements Printer {
this.sbCode = new StringBuffer(30 * 1024);
}
@Override
public void print(byte b) {
this.sbCode.append(String.valueOf(b));
}
@Override
public void print(char c) {
switch (c) {
case '<':
this.sbCode.append("&lt;");
break;
case '>':
this.sbCode.append("&gt;");
break;
default:
this.sbCode.append(c);
break;
}
}
@Override
public void print(int i) {
this.sbCode.append(i);
}
@Override
public void print(String s) {
this.sbCode.append(s);
}
@Override
public void printNumeric(String s) {
this.sbCode.append("<u>");
this.sbCode.append(s);
this.sbCode.append("</u>");
}
@Override
public void printString(String s, String scopeInternalName) {
this.sbCode.append("<u>");
// Replace '<' by '&lt;'
int length = s.length();
if (length > 0) {
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == '<')
this.sbCode.append("&lt;");
else
this.sbCode.append(c);
}
}
this.sbCode.append("</u>");
}
@Override
public void printKeyword(String s) {
if (this.commentJavadocErrorDepth == 0) {
@ -120,102 +61,11 @@ public class HtmlPrinter implements Printer {
}
@Override
public void printJavaWord(String s) {
printKeyword(s);
public void printDeclaration(int i, String s, String s1, String s2) {
}
@Override
public void printType(String internalName, String name, String scopeInternalName) {
this.sbCode.append(name);
}
@Override
public void printTypeDeclaration(String internalName, String name) {
this.sbCode.append(name);
}
@Override
public void printTypeImport(String internalName, String name) {
this.sbCode.append(name);
}
@Override
public void printField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printFieldDeclaration(internalName, name, descriptor);
}
@Override
public void printFieldDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append("<var>");
this.sbCode.append(name);
this.sbCode.append("</var>");
}
@Override
public void printStaticField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printStaticFieldDeclaration(internalName, name, descriptor);
}
@Override
public void printStaticFieldDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append("<em>");
this.sbCode.append(name);
this.sbCode.append("</em>");
}
@Override
public void printConstructor(
String internalName, String name,
String descriptor, String scopeInternalName) {
this.sbCode.append(name);
}
@Override
public void printConstructorDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append(name);
}
@Override
public void printStaticConstructorDeclaration(
String internalName, String name) {
this.sbCode.append("<samp>");
this.sbCode.append(name);
this.sbCode.append("</samp>");
}
@Override
public void printMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
this.sbCode.append(name);
}
@Override
public void printMethodDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append(name);
}
@Override
public void printStaticMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
printStaticMethodDeclaration(internalName, name, descriptor);
}
@Override
public void printStaticMethodDeclaration(
String internalName, String name, String descriptor) {
this.sbCode.append("<samp>");
this.sbCode.append(name);
this.sbCode.append("</samp>");
public void printReference(int i, String s, String s1, String s2, String s3) {
}
@Override
@ -308,25 +158,59 @@ public class HtmlPrinter implements Printer {
this.printStream.print("Java Class Version: " + VersionUtil.getJDKVersion(this.majorVersion,
this.minorVersion) + "<br>");
this.printStream.print("JD-CL Version: " + "0.1.0" + "<br>");
this.printStream.print("JD-Core Version: " + CoreConstants.JD_CORE_VERSION);
// TODO: Where can I find this dynamically?
this.printStream.print("JD-Core Version: " + "1.6.6");
this.printStream.print("</div>");
this.printStream.print("</div></div></div></body></html>");
}
@Override
public void printText(String s) {
this.sbCode.append(s);
}
@Override
public void printNumericConstant(String s) {
this.sbCode.append("<u>");
this.sbCode.append(s);
this.sbCode.append("</u>");
}
@Override
public void printStringConstant(String s, String s1) {
this.sbCode.append("<u>");
// Replace '<' by '&lt;'
int length = s.length();
if (length > 0) {
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == '<')
this.sbCode.append("&lt;");
else
this.sbCode.append(c);
}
}
this.sbCode.append("</u>");
}
@Override
public void indent() {
this.indentationCount++;
}
@Override
public void desindent() {
public void unindent() {
if (this.indentationCount > 0)
this.indentationCount--;
}
@Override
public void startOfLine(int lineNumber) {
public void startLine(int lineNumber) {
this.realLineNumber++;
if (this.maxLineNumber > 0) {
@ -354,7 +238,7 @@ public class HtmlPrinter implements Printer {
}
@Override
public void endOfLine() {
public void endLine() {
this.sbCode.append("<br>");
}
@ -383,187 +267,11 @@ public class HtmlPrinter implements Printer {
}
@Override
public void startOfComment() {
this.sbCode.append("<cite>");
this.commentJavadocErrorDepth++;
public void startMarker(int i) {
}
@Override
public void endOfComment() {
this.sbCode.append("</cite>");
this.commentJavadocErrorDepth--;
public void endMarker(int i) {
}
@Override
public void startOfJavadoc() {
this.sbCode.append("<dfn>");
this.commentJavadocErrorDepth++;
}
@Override
public void endOfJavadoc() {
this.sbCode.append("</dfn>");
this.commentJavadocErrorDepth--;
}
@Override
public void startOfXdoclet() {
this.sbCode.append("<b>");
}
@Override
public void endOfXdoclet() {
this.sbCode.append("</b>");
}
@Override
public void startOfError() {
this.sbCode.append("<span>");
this.commentJavadocErrorDepth++;
}
@Override
public void endOfError() {
this.sbCode.append("</span>");
this.commentJavadocErrorDepth--;
}
@Override
public void startOfImportStatements() {
}
@Override
public void endOfImportStatements() {
}
@Override
public void startOfTypeDeclaration(String internalPath) {
}
@Override
public void endOfTypeDeclaration() {
}
@Override
public void startOfAnnotationName() {
this.sbCode.append("<del>");
}
@Override
public void endOfAnnotationName() {
this.sbCode.append("</del>");
}
@Override
public void startOfOptionalPrefix() {
this.sbCode.append("<kbd>");
}
@Override
public void endOfOptionalPrefix() {
this.sbCode.append("</kbd>");
}
@Override
public void debugStartOfLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debuglayoutblock' alt='block'>");
}
}
@Override
public void debugEndOfLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");
}
}
@Override
public void debugStartOfSeparatorLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugseparatorlayoutblock' alr='separator'>");
}
}
@Override
public void debugEndOfSeparatorLayoutBlock(int min, int value, int max) {
if (DEBUG) {
// DEBUG // this.sb.append(min);
// DEBUG // this.sb.append("&lt;=");
// DEBUG // this.sb.append(value);
// DEBUG // this.sb.append("&lt;=");
// DEBUG // this.sb.append(max);
this.sbCode.append("</span>");
}
}
@Override
public void debugStartOfStatementsBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugstatementblocklayoutblock' alt='statement'>");
}
}
@Override
public void debugEndOfStatementsBlockLayoutBlock(int min, int value, int max) {
if (DEBUG) {
// DEBUG // this.sb.append(min);
// DEBUG // this.sb.append("&lt;=");
// DEBUG // this.sb.append(value);
// DEBUG // this.sb.append("&lt;=");
// DEBUG // this.sb.append(max);
this.sbCode.append("</span>");
}
}
@Override
public void debugStartOfInstructionBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugenumblocklayoutblock' alt='numeric block'>");
}
}
@Override
public void debugEndOfInstructionBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");
}
}
@Override
public void debugStartOfCommentDeprecatedLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugcommentdeprecatedlayoutblock' alt='comment deprecated'>");
}
}
@Override
public void debugEndOfCommentDeprecatedLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");
}
}
@Override
public void debugMarker(String marker) {
if (DEBUG) {
// DEBUG // this.sb.append("<span class='debugmarker'>");
// DEBUG // this.sb.append(marker);
// DEBUG // this.sb.append("</span>");
}
}
@Override
public void debugStartOfCaseBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("<span class='debugcaseblocklayoutblock' alt='case block'>");
}
}
@Override
public void debugEndOfCaseBlockLayoutBlock() {
if (DEBUG) {
this.sbCode.append("</span>");
}
}
}

View file

@ -2,8 +2,7 @@ package jd.cli.printer.text;
import java.io.PrintStream;
import jd.cli.preferences.CommonPreferences;
import jd.core.model.instruction.bytecode.instruction.Instruction;
import jd.core.printer.Printer;
import org.jd.core.v1.api.printer.Printer;
public class PlainTextPrinter implements Printer {
protected static final String TAB = " ";
@ -41,38 +40,6 @@ public class PlainTextPrinter implements Printer {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
@Override
public void print(byte b) {
this.printStream.append(String.valueOf(b));
}
@Override
public void print(int i) {
this.printStream.append(String.valueOf(i));
}
@Override
public void print(char c) {
if (this.display)
this.printStream.append(String.valueOf(c));
}
@Override
public void print(String s) {
if (this.display)
printEscape(s);
}
@Override
public void printNumeric(String s) {
this.printStream.append(s);
}
@Override
public void printString(String s, String scopeInternalName) {
this.printStream.append(s);
}
@Override
public void printKeyword(String s) {
if (this.display)
@ -80,95 +47,14 @@ public class PlainTextPrinter implements Printer {
}
@Override
public void printJavaWord(String s) {
this.printStream.append(s);
}
@Override
public void printType(String internalName, String name, String scopeInternalName) {
if (this.display)
printEscape(name);
}
@Override
public void printTypeDeclaration(String internalName, String name) {
printEscape(name);
}
@Override
public void printTypeImport(String internalName, String name) {
printEscape(name);
}
@Override
public void printField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printFieldDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printStaticField(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printStaticFieldDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printConstructor(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printConstructorDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printStaticConstructorDeclaration(
String internalName, String name) {
public void printDeclaration(int type, String internalTypeName, String name, String descriptor) {
this.printStream.append(name);
}
@Override
public void printMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printMethodDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
}
@Override
public void printStaticMethod(
String internalName, String name,
String descriptor, String scopeInternalName) {
printEscape(name);
}
@Override
public void printStaticMethodDeclaration(
String internalName, String name, String descriptor) {
printEscape(name);
public void printReference(int type, String internalTypeName, String name, String descriptor,
String ownerInternalName) {
this.printStream.append(name);
}
@Override
@ -212,23 +98,39 @@ public class PlainTextPrinter implements Printer {
public void end() {
}
@Override
public void printText(String s) {
if (this.display)
printEscape(s);
}
@Override
public void printNumericConstant(String s) {
this.printStream.append(s);
}
@Override
public void printStringConstant(String s, String s1) {
this.printStream.append(s);
}
@Override
public void indent() {
this.indentationCount++;
}
@Override
public void desindent() {
public void unindent() {
if (this.indentationCount > 0)
this.indentationCount--;
}
@Override
public void startOfLine(int lineNumber) {
public void startLine(int lineNumber) {
if (this.maxLineNumber > 0) {
this.printStream.append(this.lineNumberBeginPrefix);
if (lineNumber == Instruction.UNKNOWN_LINE_NUMBER) {
if (lineNumber == UNKNOWN_LINE_NUMBER) {
this.printStream.append(this.unknownLineNumberPrefix);
} else {
int left = 0;
@ -248,7 +150,7 @@ public class PlainTextPrinter implements Printer {
}
@Override
public void endOfLine() {
public void endLine() {
this.printStream.append(NEWLINE);
}
@ -268,124 +170,11 @@ public class PlainTextPrinter implements Printer {
}
@Override
public void startOfComment() {
public void startMarker(int i) {
}
@Override
public void endOfComment() {
}
@Override
public void startOfJavadoc() {
}
@Override
public void endOfJavadoc() {
}
@Override
public void startOfXdoclet() {
}
@Override
public void endOfXdoclet() {
}
@Override
public void startOfError() {
}
@Override
public void endOfError() {
}
@Override
public void startOfImportStatements() {
}
@Override
public void endOfImportStatements() {
}
@Override
public void startOfTypeDeclaration(String internalPath) {
}
@Override
public void endOfTypeDeclaration() {
}
@Override
public void startOfAnnotationName() {
}
@Override
public void endOfAnnotationName() {
}
@Override
public void startOfOptionalPrefix() {
if (!this.preferences.isShowPrefixThis())
this.display = false;
}
@Override
public void endOfOptionalPrefix() {
this.display = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
@Override
public void debugStartOfLayoutBlock() {
}
@Override
public void debugEndOfLayoutBlock() {
}
@Override
public void debugStartOfSeparatorLayoutBlock() {
}
@Override
public void debugEndOfSeparatorLayoutBlock(int min, int value, int max) {
}
@Override
public void debugStartOfStatementsBlockLayoutBlock() {
}
@Override
public void debugEndOfStatementsBlockLayoutBlock(int min, int value, int max) {
}
@Override
public void debugStartOfInstructionBlockLayoutBlock() {
}
@Override
public void debugEndOfInstructionBlockLayoutBlock() {
}
@Override
public void debugStartOfCommentDeprecatedLayoutBlock() {
}
@Override
public void debugEndOfCommentDeprecatedLayoutBlock() {
}
@Override
public void debugMarker(String marker) {
}
@Override
public void debugStartOfCaseBlockLayoutBlock() {
}
@Override
public void debugEndOfCaseBlockLayoutBlock() {
public void endMarker(int i) {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //

View file

@ -6,16 +6,17 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;
import jd.core.CoreConstants;
import jd.core.model.classfile.constant.Constant;
import jd.core.model.classfile.constant.ConstantClass;
import jd.core.model.classfile.constant.ConstantConstant;
import jd.core.model.classfile.constant.ConstantUtf8;
import jd.core.process.deserializer.ClassFormatException;
import jd.core.util.StringConstants;
import org.jd.core.v1.model.classfile.constant.Constant;
import org.jd.core.v1.model.classfile.constant.ConstantClass;
import org.jd.core.v1.model.classfile.constant.ConstantUtf8;
import org.jd.core.v1.service.deserializer.classfile.ClassFileFormatException;
import org.jd.core.v1.service.deserializer.classfile.ClassFileReader;
public class ClassFileUtil {
public static final char INTERNAL_PACKAGE_SEPARATOR = '/';
public static final String CLASS_FILE_SUFFIX = ".class";
/*
* Lecture rapide de la structure de la classe et extraction du nom du
* repoertoire de base.
@ -30,8 +31,8 @@ public class ClassFileUtil {
new FileInputStream(pathToClass)));
int magic = dis.readInt();
if (magic != CoreConstants.JAVA_MAGIC_NUMBER)
throw new ClassFormatException("Invalid Java .class file");
if (magic != ClassFileReader.JAVA_MAGIC_NUMBER)
throw new ClassFileFormatException("Invalid Java .class file");
/* int minor_version = */
dis.readUnsignedShort();
@ -44,23 +45,26 @@ public class ClassFileUtil {
dis.readUnsignedShort();
int this_class = dis.readUnsignedShort();
Constant c = Objects.requireNonNull(constants)[this_class];
if ((c == null) || (c.tag != ConstantConstant.CONSTANT_Class))
throw new ClassFormatException("Invalid contant pool");
if (this_class > Objects.requireNonNull(constants).length) {
throw new ClassFileFormatException("Unknown Java structure");
}
Constant c = constants[this_class];
if ((c == null) || (c.getTag() != Constant.CONSTANT_Class))
throw new ClassFileFormatException("Invalid constant pool");
c = constants[((ConstantClass) c).name_index];
if ((c == null) || (c.tag != ConstantConstant.CONSTANT_Utf8))
throw new ClassFormatException("Invalid contant pool");
c = constants[((ConstantClass) c).getNameIndex()];
if ((c == null) || (c.getTag() != Constant.CONSTANT_Utf8))
throw new ClassFileFormatException("Invalid constant pool");
String internalClassName = ((ConstantUtf8) c).bytes;
String internalClassName = ((ConstantUtf8) c).getValue();
String pathSuffix = internalClassName.replace(
StringConstants.INTERNAL_PACKAGE_SEPARATOR, File.separatorChar) +
StringConstants.CLASS_FILE_SUFFIX;
INTERNAL_PACKAGE_SEPARATOR, File.separatorChar) +
CLASS_FILE_SUFFIX;
int index = pathToClass.indexOf(pathSuffix);
if (index < 0)
throw new ClassFormatException("Invalid internal class name");
throw new ClassFileFormatException("Invalid internal class name");
directoryPath = pathToClass.substring(0, index);
} catch (IOException e) {
@ -85,7 +89,7 @@ public class ClassFileUtil {
String s = pathToClass.substring(directoryPath.length());
return s.replace(File.separatorChar, StringConstants.INTERNAL_PACKAGE_SEPARATOR);
return s.replace(File.separatorChar, INTERNAL_PACKAGE_SEPARATOR);
}
private static Constant[] DeserializeConstants(DataInputStream dis)
@ -100,28 +104,28 @@ public class ClassFileUtil {
byte tag = dis.readByte();
switch (tag) {
case ConstantConstant.CONSTANT_Class:
constants[i] = new ConstantClass(tag, dis.readUnsignedShort());
case Constant.CONSTANT_Class:
constants[i] = new ConstantClass(dis.readUnsignedShort());
break;
case ConstantConstant.CONSTANT_Utf8:
constants[i] = new ConstantUtf8(tag, dis.readUTF());
case Constant.CONSTANT_Utf8:
constants[i] = new ConstantUtf8(dis.readUTF());
break;
case ConstantConstant.CONSTANT_Long:
case ConstantConstant.CONSTANT_Double:
case Constant.CONSTANT_Long:
case Constant.CONSTANT_Double:
dis.read();
dis.read();
dis.read();
dis.read();
i++;
case ConstantConstant.CONSTANT_Fieldref:
case ConstantConstant.CONSTANT_Methodref:
case ConstantConstant.CONSTANT_InterfaceMethodref:
case ConstantConstant.CONSTANT_NameAndType:
case ConstantConstant.CONSTANT_Integer:
case ConstantConstant.CONSTANT_Float:
case Constant.CONSTANT_FieldRef:
case Constant.CONSTANT_MethodRef:
case Constant.CONSTANT_InterfaceMethodRef:
case Constant.CONSTANT_NameAndType:
case Constant.CONSTANT_Integer:
case Constant.CONSTANT_Float:
dis.read();
dis.read();
case ConstantConstant.CONSTANT_String:
case Constant.CONSTANT_String:
dis.read();
dis.read();
break;

View file

@ -1,10 +1,12 @@
package jd.cli.util;
import jd.core.util.TypeNameUtil;
public class CommonTypeNameUtil {
public static String InternalPathToQualifiedTypeName(String internalPath) {
String internalTypeName = internalPath.substring(0, internalPath.length() - 6);
return TypeNameUtil.InternalTypeNameToQualifiedTypeName(internalTypeName);
return InternalTypeNameToQualifiedTypeName(internalTypeName);
}
public static String InternalTypeNameToQualifiedTypeName(String path) {
return path.replace('/', '.').replace('$', '.');
}
}

View file

@ -10,8 +10,8 @@ import jd.cli.loader.DirectoryLoader;
import jd.cli.preferences.CommonPreferences;
import jd.cli.printer.text.PlainTextPrinter;
import jd.cli.util.ClassFileUtil;
import jd.core.process.DecompilerImpl;
import me.konloch.kontainer.io.DiskReader;
import org.jd.core.v1.ClassFileToJavaSourceDecompiler;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
@ -99,8 +99,8 @@ public class JDGUIDecompiler extends Decompiler {
PrintStream ps = new PrintStream(tempJava.getAbsolutePath());
PlainTextPrinter printer = new PlainTextPrinter(preferences, ps);
jd.core.Decompiler decompiler = new DecompilerImpl();
decompiler.decompile(preferences, loader, printer, internalPath);
org.jd.core.v1.api.Decompiler decompiler = new ClassFileToJavaSourceDecompiler();
decompiler.decompile(loader, printer, internalPath, preferences.getPreferences());
String decompiledSource;
decompiledSource = DiskReader.loadAsString(tempJava.getAbsolutePath());