Skip to content

Commit

Permalink
Fix JDGUI not finding/decompiling inner classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bl3nd committed Oct 17, 2024
1 parent 5291651 commit a5f3153
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<InnerClassNode> 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
Expand All @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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();
}
}

0 comments on commit a5f3153

Please sign in to comment.