diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java index 4395bc91a..e3ac9948a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java @@ -19,20 +19,26 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; import com.konloch.disklib.DiskReader; +import org.apache.commons.io.FilenameUtils; import org.jd.core.v1.ClassFileToJavaSourceDecompiler; import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InnerClassNode; +import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Constants; +import the.bytecode.club.bytecodeviewer.api.ASMUtil; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler; import the.bytecode.club.bytecodeviewer.decompilers.jdgui.CommonPreferences; import the.bytecode.club.bytecodeviewer.decompilers.jdgui.DirectoryLoader; import the.bytecode.club.bytecodeviewer.decompilers.jdgui.JDGUIClassFileUtil; import the.bytecode.club.bytecodeviewer.decompilers.jdgui.PlainTextPrinter; +import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.util.ExceptionUtils; import the.bytecode.club.bytecodeviewer.util.TempFile; import java.io.*; +import java.util.List; import static the.bytecode.club.bytecodeviewer.Constants.FS; import static the.bytecode.club.bytecodeviewer.Constants.NL; @@ -53,12 +59,32 @@ public JDGUIDecompiler() super("JD-GUI Decompiler", "jdgui"); } + private String[] inners; @Override public String decompileClassNode(ClassNode cn, byte[] bytes) { TempFile tempFile = null; String exception; + List innerClasses = cn.innerClasses; + inners = new String[innerClasses.size()]; + for (int i = 0; i < innerClasses.size(); i++) + { + if (innerClasses.get(i).outerName != null && innerClasses.get(i).outerName.equals(cn.name)) + { + inners[i] = innerClasses.get(i).name; + } + else if (innerClasses.get(i).outerName == null) + { + String name = innerClasses.get(i).name; + name = name.substring(name.lastIndexOf('/') + 1); + if (name.contains(cn.name.substring(cn.name.lastIndexOf('/') + 1))) + { + inners[i] = innerClasses.get(i).name; + } + } + } + try { //create the temporary files @@ -75,9 +101,33 @@ public String decompileClassNode(ClassNode cn, byte[] bytes) fos.write(bytes); } + // create the inner class temp files + File innerTempFile; + for (ResourceContainer container : BytecodeViewer.resourceContainers.values()) + { + for (String s : container.resourceClasses.keySet()) + { + for (String innerClassName : inners) + { + if (s.equals(innerClassName)) + { + ClassNode cn2 = container.resourceClasses.get(innerClassName); + tempFile.setUniqueName(cn2.name); + innerTempFile = tempFile.createFileFromExtension(false, false, ".class"); + try (FileOutputStream fos = new FileOutputStream(innerTempFile)) + { + fos.write(ASMUtil.nodeToBytes(cn2)); + } + } + } + } + } + String pathToClass = tempClassFile.getAbsolutePath().replace('/', File.separatorChar).replace('\\', File.separatorChar); String directoryPath = JDGUIClassFileUtil.ExtractDirectoryPath(pathToClass); - String internalPath = JDGUIClassFileUtil.ExtractInternalPath(directoryPath, pathToClass); + String internalPath = FilenameUtils.removeExtension(JDGUIClassFileUtil.ExtractInternalPath(directoryPath, + pathToClass)); + CommonPreferences preferences = new CommonPreferences() { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java index 882b56521..ba5a64ba4 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java @@ -46,6 +46,9 @@ public DirectoryLoader(File file) throws LoaderException @Override public byte[] load(String internalPath) throws LoaderException { + if (!internalPath.endsWith(".class")) + internalPath = internalPath + ".class"; + File file = new File(this.codebase, internalPath); try (FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis)) @@ -61,7 +64,7 @@ public byte[] load(String internalPath) throws LoaderException @Override public boolean canLoad(String internalPath) { - File file = new File(this.codebase, internalPath); + File file = new File(this.codebase, internalPath + ".class"); return file.exists() && file.isFile(); } }