Skip to content

Commit a5f3153

Browse files
committed
Fix JDGUI not finding/decompiling inner classes.
1 parent 5291651 commit a5f3153

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@
1919
package the.bytecode.club.bytecodeviewer.decompilers.impl;
2020

2121
import com.konloch.disklib.DiskReader;
22+
import org.apache.commons.io.FilenameUtils;
2223
import org.jd.core.v1.ClassFileToJavaSourceDecompiler;
2324
import org.objectweb.asm.tree.ClassNode;
25+
import org.objectweb.asm.tree.InnerClassNode;
26+
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
2427
import the.bytecode.club.bytecodeviewer.Constants;
28+
import the.bytecode.club.bytecodeviewer.api.ASMUtil;
2529
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
2630
import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler;
2731
import the.bytecode.club.bytecodeviewer.decompilers.jdgui.CommonPreferences;
2832
import the.bytecode.club.bytecodeviewer.decompilers.jdgui.DirectoryLoader;
2933
import the.bytecode.club.bytecodeviewer.decompilers.jdgui.JDGUIClassFileUtil;
3034
import the.bytecode.club.bytecodeviewer.decompilers.jdgui.PlainTextPrinter;
35+
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
3136
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
3237
import the.bytecode.club.bytecodeviewer.util.ExceptionUtils;
3338
import the.bytecode.club.bytecodeviewer.util.TempFile;
3439

3540
import java.io.*;
41+
import java.util.List;
3642

3743
import static the.bytecode.club.bytecodeviewer.Constants.FS;
3844
import static the.bytecode.club.bytecodeviewer.Constants.NL;
@@ -53,12 +59,32 @@ public JDGUIDecompiler()
5359
super("JD-GUI Decompiler", "jdgui");
5460
}
5561

62+
private String[] inners;
5663
@Override
5764
public String decompileClassNode(ClassNode cn, byte[] bytes)
5865
{
5966
TempFile tempFile = null;
6067
String exception;
6168

69+
List<InnerClassNode> innerClasses = cn.innerClasses;
70+
inners = new String[innerClasses.size()];
71+
for (int i = 0; i < innerClasses.size(); i++)
72+
{
73+
if (innerClasses.get(i).outerName != null && innerClasses.get(i).outerName.equals(cn.name))
74+
{
75+
inners[i] = innerClasses.get(i).name;
76+
}
77+
else if (innerClasses.get(i).outerName == null)
78+
{
79+
String name = innerClasses.get(i).name;
80+
name = name.substring(name.lastIndexOf('/') + 1);
81+
if (name.contains(cn.name.substring(cn.name.lastIndexOf('/') + 1)))
82+
{
83+
inners[i] = innerClasses.get(i).name;
84+
}
85+
}
86+
}
87+
6288
try
6389
{
6490
//create the temporary files
@@ -75,9 +101,33 @@ public String decompileClassNode(ClassNode cn, byte[] bytes)
75101
fos.write(bytes);
76102
}
77103

104+
// create the inner class temp files
105+
File innerTempFile;
106+
for (ResourceContainer container : BytecodeViewer.resourceContainers.values())
107+
{
108+
for (String s : container.resourceClasses.keySet())
109+
{
110+
for (String innerClassName : inners)
111+
{
112+
if (s.equals(innerClassName))
113+
{
114+
ClassNode cn2 = container.resourceClasses.get(innerClassName);
115+
tempFile.setUniqueName(cn2.name);
116+
innerTempFile = tempFile.createFileFromExtension(false, false, ".class");
117+
try (FileOutputStream fos = new FileOutputStream(innerTempFile))
118+
{
119+
fos.write(ASMUtil.nodeToBytes(cn2));
120+
}
121+
}
122+
}
123+
}
124+
}
125+
78126
String pathToClass = tempClassFile.getAbsolutePath().replace('/', File.separatorChar).replace('\\', File.separatorChar);
79127
String directoryPath = JDGUIClassFileUtil.ExtractDirectoryPath(pathToClass);
80-
String internalPath = JDGUIClassFileUtil.ExtractInternalPath(directoryPath, pathToClass);
128+
String internalPath = FilenameUtils.removeExtension(JDGUIClassFileUtil.ExtractInternalPath(directoryPath,
129+
pathToClass));
130+
81131

82132
CommonPreferences preferences = new CommonPreferences()
83133
{

src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/DirectoryLoader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public DirectoryLoader(File file) throws LoaderException
4646
@Override
4747
public byte[] load(String internalPath) throws LoaderException
4848
{
49+
if (!internalPath.endsWith(".class"))
50+
internalPath = internalPath + ".class";
51+
4952
File file = new File(this.codebase, internalPath);
5053

5154
try (FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis))
@@ -61,7 +64,7 @@ public byte[] load(String internalPath) throws LoaderException
6164
@Override
6265
public boolean canLoad(String internalPath)
6366
{
64-
File file = new File(this.codebase, internalPath);
67+
File file = new File(this.codebase, internalPath + ".class");
6568
return file.exists() && file.isFile();
6669
}
6770
}

0 commit comments

Comments
 (0)