JADX Decompiler Update

This commit is contained in:
Konloch 2024-10-02 18:49:44 -06:00
parent b1004792b6
commit a094e52add

AI 샘플 코드 생성 중입니다

Loading...

View File

@ -22,17 +22,19 @@ import jadx.api.JadxArgs;
import jadx.api.JadxDecompiler;
import me.konloch.kontainer.io.DiskReader;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.Settings;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import the.bytecode.club.bytecodeviewer.util.ExceptionUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.TempFile;
import java.io.*;
import static the.bytecode.club.bytecodeviewer.Constants.*;
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.ERROR;
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.JADX;
import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.*;
/**
* JADX Java Wrapper
@ -49,96 +51,80 @@ public class JADXDecompiler extends AbstractDecompiler
@Override
public String decompileClassNode(ClassNode cn, byte[] bytes)
{
String fileStart = TEMP_DIRECTORY + FS;
TempFile tempFile = null;
String exception;
String exception = "";
final File tempClass = new File(MiscUtils.getUniqueNameBroken(fileStart, ".class") + ".class");
try
{
//create the temporary files
tempFile = TempFile.createTemporaryFile(true, ".class");
File tempDirectory = tempFile.getParent();
File tempClassFile = tempFile.getFile();
try (FileOutputStream fos = new FileOutputStream(tempClass))
//write the class-file with bytes
try (FileOutputStream fos = new FileOutputStream(tempClassFile))
{
fos.write(bytes);
}
catch (IOException e)
{
BytecodeViewer.handleException(e);
}
File freeDirectory = new File(findUnusedFile(fileStart));
freeDirectory.mkdirs();
try
{
//setup JADX Args
JadxArgs args = new JadxArgs();
args.setInputFile(tempClass);
args.setOutDir(freeDirectory);
args.setOutDirSrc(freeDirectory);
args.setOutDirRes(freeDirectory);
args.setInputFile(tempClassFile);
args.setOutDir(tempDirectory);
args.setOutDirSrc(tempDirectory);
args.setOutDirRes(tempDirectory);
//init jadx decompiler
JadxDecompiler jadx = new JadxDecompiler(args);
//load jadx
jadx.load();
//decompile
jadx.saveSources();
//handle simulated errors
if(Constants.DEV_FLAG_DECOMPILERS_SIMULATED_ERRORS)
throw new RuntimeException(DEV_MODE_SIMULATED_ERROR.toString());
return searchForJavaFile(MiscUtils.listFiles(tempDirectory));
}
catch (StackOverflowError | Exception e)
catch (Throwable e)
{
StringWriter exceptionWriter = new StringWriter();
e.printStackTrace(new PrintWriter(exceptionWriter));
e.printStackTrace();
exception = exceptionWriter.toString();
exception = ExceptionUtils.exceptionToString(e);
}
tempClass.delete();
if (freeDirectory.exists())
return findFile(MiscUtils.listFiles(freeDirectory));
if (exception.isEmpty())
exception = "Decompiled source file not found!";
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
public String findUnusedFile(String start)
finally
{
long index = 0;
//cleanup temp files
if(tempFile != null)
tempFile.cleanup();
}
while (true)
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL
+ TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
public String searchForJavaFile(File[] files) throws Exception
{
File f = new File(start + index);
for (File file : files)
{
if (file.isDirectory())
return searchForJavaFile(MiscUtils.listFiles(file));
else if(file.getName().toLowerCase().endsWith(".java"))
{
String contents = DiskReader.loadAsString(file.getAbsolutePath());
if (!f.exists())
return f.toString();
//cleanup
if(Settings.DECOMPILERS_AUTOMATICALLY_CLEANUP)
file.delete();
return contents;
}
}
public String findFile(File[] fileArray)
{
for (File f : fileArray)
{
if (f.isDirectory())
return findFile(MiscUtils.listFiles(f));
else
{
String s;
try
{
s = DiskReader.loadAsString(f.getAbsolutePath());
}
catch (Exception e)
{
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
e.printStackTrace();
String exception = ExceptionUI.SEND_STACKTRACE_TO_NL + sw;
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception;
}
return s;
}
}
return "JADX error!" + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR;
return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL
+ TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL
+ "JADX failed to produce any Java files from the provided source.";
}
@Override