Resource Decompiling Refactor/Code Cleanup
This commit is contained in:
parent
7df1312741
commit
a39a13e9be
1 changed files with 206 additions and 331 deletions
|
@ -1,15 +1,14 @@
|
||||||
package the.bytecode.club.bytecodeviewer.resources;
|
package the.bytecode.club.bytecodeviewer.resources;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Objects;
|
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import me.konloch.kontainer.io.DiskWriter;
|
import me.konloch.kontainer.io.DiskWriter;
|
||||||
import org.objectweb.asm.ClassWriter;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||||
import the.bytecode.club.bytecodeviewer.Configuration;
|
import the.bytecode.club.bytecodeviewer.Configuration;
|
||||||
|
import the.bytecode.club.bytecodeviewer.api.BCV;
|
||||||
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
|
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
|
||||||
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
|
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
|
||||||
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
|
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
|
||||||
|
@ -44,366 +43,242 @@ import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
|
||||||
*/
|
*/
|
||||||
public class ResourceDecompiling
|
public class ResourceDecompiling
|
||||||
{
|
{
|
||||||
|
private static final int DECOMPILE_SAVE_ALL = 10;
|
||||||
|
private static final int DECOMPILE_SAVE_ALL_PROCYON = 11;
|
||||||
|
private static final int DECOMPILE_SAVE_ALL_CFR = 12;
|
||||||
|
private static final int DECOMPILE_SAVE_ALL_FERNFLOWER = 13;
|
||||||
|
private static final int DECOMPILE_SAVE_ALL_KRAKATAU = 14;
|
||||||
|
//TODO JDGUI,JADX
|
||||||
|
|
||||||
|
private static final int DECOMPILE_OPENED_ONLY_ALL = 20;
|
||||||
|
private static final int DECOMPILE_OPENED_ONLY_PROCYON = 21;
|
||||||
|
private static final int DECOMPILE_OPENED_ONLY_CFR = 22;
|
||||||
|
private static final int DECOMPILE_OPENED_ONLY_FERNFLOWER = 23;
|
||||||
|
private static final int DECOMPILE_OPENED_ONLY_KRAKATAU = 24;
|
||||||
|
//TODO JDGUI,JADX
|
||||||
|
|
||||||
public static void decompileSaveAll()
|
public static void decompileSaveAll()
|
||||||
{
|
{
|
||||||
|
//alert the user if no classes have been imported into BCV
|
||||||
if (BytecodeViewer.promptIfNoLoadedClasses())
|
if (BytecodeViewer.promptIfNoLoadedClasses())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Thread decompileThread = new Thread(() ->
|
MiscUtils.createNewThread("Decompile Save-All Thread", () ->
|
||||||
{
|
{
|
||||||
|
//signal to the user that BCV is performing an action in the background
|
||||||
|
BytecodeViewer.updateBusyStatus(true);
|
||||||
|
|
||||||
|
//auto compile before decompilation
|
||||||
if (!BytecodeViewer.autoCompileSuccessful())
|
if (!BytecodeViewer.autoCompileSuccessful())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
|
final JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(), "Select Zip Export",
|
||||||
"Select Zip Export",
|
"Zip Archives", "zip");
|
||||||
"Zip Archives",
|
|
||||||
"zip");
|
|
||||||
|
|
||||||
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
|
//if the user doesn't select a file then we should stop while we're ahead
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
if (fc.showSaveDialog(BytecodeViewer.viewer) != JFileChooser.APPROVE_OPTION)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//set the last touched save directory for BCV
|
||||||
|
Configuration.setLastSaveDirectory(fc.getSelectedFile());
|
||||||
|
|
||||||
|
//get the save file and auto append zip extension
|
||||||
|
final File outputZip = MiscUtils.autoAppendFileExtension(".zip", fc.getSelectedFile());
|
||||||
|
|
||||||
|
//prompt the user for a dialogue override-this-file option if the file already exists
|
||||||
|
if (!DialogUtils.canOverwriteFile(outputZip))
|
||||||
|
return;
|
||||||
|
|
||||||
|
//this temporary jar file will be used to store the classes while BCV performs decompilation
|
||||||
|
File temporaryTargetJar = MiscUtils.deleteExistingFile(new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar"));
|
||||||
|
|
||||||
|
//extract all the loaded classes imported into BCV to the temporary target jar
|
||||||
|
JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), temporaryTargetJar.getAbsolutePath());
|
||||||
|
|
||||||
|
//signal to the user that BCV is finished performing that action
|
||||||
|
BytecodeViewer.updateBusyStatus(false);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Configuration.setLastSaveDirectory(fc.getSelectedFile());
|
//handle the result of the user selection
|
||||||
|
switch (promptDecompilerUserSelect() + DECOMPILE_SAVE_ALL)
|
||||||
|
{
|
||||||
|
case DECOMPILE_SAVE_ALL:
|
||||||
|
//decompile using procyon
|
||||||
|
decompileSaveAll(Decompiler.PROCYON_DECOMPILER, temporaryTargetJar, outputZip, true);
|
||||||
|
|
||||||
File file = fc.getSelectedFile();
|
//decompile using CFR
|
||||||
|
decompileSaveAll(Decompiler.CFR_DECOMPILER, temporaryTargetJar, outputZip, true);
|
||||||
|
|
||||||
//auto appened zip
|
//decompile using fern
|
||||||
if (!file.getAbsolutePath().endsWith(".zip"))
|
decompileSaveAll(Decompiler.FERNFLOWER_DECOMPILER, temporaryTargetJar, outputZip, true);
|
||||||
file = new File(file.getAbsolutePath() + ".zip");
|
|
||||||
|
|
||||||
if (!DialogUtils.canOverwriteFile(file))
|
//decompile using krakatau
|
||||||
return;
|
decompileSaveAll(Decompiler.KRAKATAU_DECOMPILER, temporaryTargetJar, outputZip, true);
|
||||||
|
break;
|
||||||
|
|
||||||
final File javaSucks = file;
|
case DECOMPILE_SAVE_ALL_PROCYON:
|
||||||
final String path = MiscUtils.append(file, ".zip"); // cheap hax cause string is final
|
//decompile using procyon
|
||||||
|
decompileSaveAll(Decompiler.PROCYON_DECOMPILER, temporaryTargetJar, outputZip, false);
|
||||||
|
break;
|
||||||
|
|
||||||
JOptionPane pane = new JOptionPane("What decompiler will you use?");
|
case DECOMPILE_SAVE_ALL_CFR:
|
||||||
Object[] options = new String[]{"All", "Procyon", "CFR",
|
//decompile using CFR
|
||||||
"Fernflower", "Krakatau", "Cancel"};
|
decompileSaveAll(Decompiler.CFR_DECOMPILER, temporaryTargetJar, outputZip, false);
|
||||||
pane.setOptions(options);
|
break;
|
||||||
JDialog dialog = pane.createDialog(BytecodeViewer.viewer,
|
|
||||||
"Bytecode Viewer - Select Decompiler");
|
|
||||||
dialog.setVisible(true);
|
|
||||||
Object obj = pane.getValue();
|
|
||||||
int result = -1;
|
|
||||||
for (int k = 0; k < options.length; k++)
|
|
||||||
if (options[k].equals(obj))
|
|
||||||
result = k;
|
|
||||||
|
|
||||||
BytecodeViewer.updateBusyStatus(true);
|
case DECOMPILE_SAVE_ALL_FERNFLOWER:
|
||||||
|
//decompile using fern
|
||||||
|
decompileSaveAll(Decompiler.FERNFLOWER_DECOMPILER, temporaryTargetJar, outputZip, false);
|
||||||
|
break;
|
||||||
|
|
||||||
File tempZip = new File(tempDirectory + fs + "temp_" + MiscUtils.getRandomizedName() + ".jar");
|
case DECOMPILE_SAVE_ALL_KRAKATAU:
|
||||||
if (tempZip.exists())
|
//decompile using krakatau
|
||||||
tempZip.delete();
|
decompileSaveAll(Decompiler.KRAKATAU_DECOMPILER, temporaryTargetJar, outputZip, false);
|
||||||
|
break;
|
||||||
JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), tempZip.getAbsolutePath());
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
Thread t12 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
|
|
||||||
MiscUtils.append(javaSucks, "-procyon.zip"));
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t12.start();
|
|
||||||
Thread t2 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
BytecodeViewer.updateBusyStatus(true);
|
|
||||||
Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
|
|
||||||
MiscUtils.append(javaSucks, "-CFR.zip"));
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t2.start();
|
|
||||||
Thread t3 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
BytecodeViewer.updateBusyStatus(true);
|
|
||||||
Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
|
|
||||||
MiscUtils.append(javaSucks, "-fernflower.zip"));
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t3.start();
|
|
||||||
Thread t4 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
BytecodeViewer.updateBusyStatus(true);
|
|
||||||
Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(),
|
|
||||||
MiscUtils.append(javaSucks, "-kraktau.zip"));
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t4.start();
|
|
||||||
}
|
|
||||||
if (result == 1) {
|
|
||||||
Thread t12 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t12.start();
|
|
||||||
}
|
|
||||||
if (result == 2) {
|
|
||||||
Thread t12 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Decompiler.CFR_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t12.start();
|
|
||||||
}
|
|
||||||
if (result == 3) {
|
|
||||||
Thread t12 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t12.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == 4) {
|
|
||||||
Thread t12 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileToZip(tempZip.getAbsolutePath(), path);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t12.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == 5) {
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, "Decompile Thread");
|
catch (Exception e)
|
||||||
decompileThread.start();
|
{
|
||||||
|
BytecodeViewer.handleException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void decompileSaveOpenedOnly()
|
public static void decompileSaveOpenedResource()
|
||||||
{
|
{
|
||||||
|
//alert the user if no classes have been imported into BCV
|
||||||
if (BytecodeViewer.promptIfNoLoadedClasses())
|
if (BytecodeViewer.promptIfNoLoadedClasses())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//verify the active resource is a valid class file
|
||||||
if (!BytecodeViewer.isActiveResourceClass())
|
if (!BytecodeViewer.isActiveResourceClass())
|
||||||
{
|
{
|
||||||
BytecodeViewer.showMessage(TranslatedStrings.FIRST_VIEW_A_CLASS.toString());
|
BytecodeViewer.showMessage(TranslatedStrings.FIRST_VIEW_A_CLASS.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread decompileThread = new Thread(() ->
|
MiscUtils.createNewThread("Decompile Save Opened Resource", () ->
|
||||||
{
|
{
|
||||||
|
//signal to the user that BCV is performing an action in the background
|
||||||
|
BytecodeViewer.updateBusyStatus(true);
|
||||||
|
|
||||||
|
//auto compile before decompilation
|
||||||
if (!BytecodeViewer.autoCompileSuccessful())
|
if (!BytecodeViewer.autoCompileSuccessful())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final ClassNode cn = BytecodeViewer.getCurrentlyOpenedClassNode();
|
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(), "Select Java Files",
|
||||||
|
"Java Source Files", "java");
|
||||||
|
|
||||||
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
|
//if the user doesn't select a file then we should stop while we're ahead
|
||||||
"Select Java Files",
|
if(fc.showSaveDialog(BytecodeViewer.viewer) != JFileChooser.APPROVE_OPTION)
|
||||||
"Java Source Files",
|
return;
|
||||||
"java");
|
|
||||||
|
|
||||||
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
|
//set the last touched save directory for BCV
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
Configuration.setLastSaveDirectory(fc.getSelectedFile());
|
||||||
|
|
||||||
|
//get the save file and auto append java extension
|
||||||
|
File file = MiscUtils.autoAppendFileExtension(".java", fc.getSelectedFile());
|
||||||
|
|
||||||
|
//prompt the user for a dialogue override-this-file option if the file already exists
|
||||||
|
if (!DialogUtils.canOverwriteFile(file))
|
||||||
|
return;
|
||||||
|
|
||||||
|
//signal to the user that BCV is finished performing that action
|
||||||
|
BytecodeViewer.updateBusyStatus(false);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Configuration.setLastSaveDirectory(fc.getSelectedFile());
|
//handle the result of the user selection
|
||||||
|
switch(promptDecompilerUserSelect() + DECOMPILE_OPENED_ONLY_ALL)
|
||||||
|
{
|
||||||
|
case DECOMPILE_OPENED_ONLY_ALL:
|
||||||
|
//decompile using procyon
|
||||||
|
decompileCurrentlyOpenedResource(Decompiler.PROCYON_DECOMPILER, file, true);
|
||||||
|
|
||||||
File file = fc.getSelectedFile();
|
//decompile using cfr
|
||||||
|
decompileCurrentlyOpenedResource(Decompiler.CFR_DECOMPILER, file, true);
|
||||||
|
|
||||||
BytecodeViewer.updateBusyStatus(true);
|
//decompile using fernflower
|
||||||
final String path = MiscUtils.append(file, ".java");
|
decompileCurrentlyOpenedResource(Decompiler.FERNFLOWER_DECOMPILER, file, true);
|
||||||
|
|
||||||
if (!DialogUtils.canOverwriteFile(path))
|
//decompile using krakatau
|
||||||
return;
|
decompileCurrentlyOpenedResource(Decompiler.KRAKATAU_DECOMPILER, file, true);
|
||||||
|
break;
|
||||||
|
|
||||||
JOptionPane pane = new JOptionPane(
|
case DECOMPILE_OPENED_ONLY_PROCYON:
|
||||||
"What decompiler will you use?");
|
//decompile using procyon
|
||||||
Object[] options = new String[]{"All", "Procyon", "CFR",
|
decompileCurrentlyOpenedResource(Decompiler.PROCYON_DECOMPILER, file, false);
|
||||||
"Fernflower", "Krakatau", "Cancel"};
|
break;
|
||||||
pane.setOptions(options);
|
|
||||||
JDialog dialog = pane.createDialog(BytecodeViewer.viewer,
|
|
||||||
"Bytecode Viewer - Select Decompiler");
|
|
||||||
dialog.setVisible(true);
|
|
||||||
Object obj = pane.getValue();
|
|
||||||
int result = -1;
|
|
||||||
for (int k = 0; k < options.length; k++)
|
|
||||||
if (options[k].equals(obj))
|
|
||||||
result = k;
|
|
||||||
|
|
||||||
if (result == 0) {
|
case DECOMPILE_OPENED_ONLY_CFR:
|
||||||
Thread t1 = new Thread(() -> {
|
//decompile using cfr
|
||||||
try {
|
decompileCurrentlyOpenedResource(Decompiler.CFR_DECOMPILER, file, false);
|
||||||
final ClassWriter cw = new ClassWriter(0);
|
break;
|
||||||
try {
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
try {
|
|
||||||
Thread.sleep(200);
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
case DECOMPILE_OPENED_ONLY_FERNFLOWER:
|
||||||
DiskWriter.replaceFile(MiscUtils.append(file, "-procyon.java"),
|
//decompile using fernflower
|
||||||
Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()), false);
|
decompileCurrentlyOpenedResource(Decompiler.FERNFLOWER_DECOMPILER, file, false);
|
||||||
} catch (Exception e) {
|
break;
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
case DECOMPILE_OPENED_ONLY_KRAKATAU:
|
||||||
DiskWriter.replaceFile(MiscUtils.append(file, "-CFR.java"),
|
//decompile using krakatau
|
||||||
Decompiler.CFR_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()), false);
|
decompileCurrentlyOpenedResource(Decompiler.KRAKATAU_DECOMPILER, file, false);
|
||||||
} catch (Exception e) {
|
break;
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DiskWriter.replaceFile(MiscUtils.append(file, "-fernflower.java"),
|
|
||||||
Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()), false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DiskWriter.replaceFile(MiscUtils.append(file, "-kraktau.java"),
|
|
||||||
Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()), false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t1.start();
|
|
||||||
}
|
|
||||||
if (result == 1) {
|
|
||||||
Thread t1 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
final ClassWriter cw = new ClassWriter(0);
|
|
||||||
try {
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
try {
|
|
||||||
Thread.sleep(200);
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String contents = Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
|
|
||||||
DiskWriter.replaceFile(path, contents, false);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
BytecodeViewer.handleException(
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t1.start();
|
|
||||||
}
|
|
||||||
if (result == 2) {
|
|
||||||
Thread t1 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
final ClassWriter cw = new ClassWriter(0);
|
|
||||||
try {
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
try {
|
|
||||||
Thread.sleep(200);
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String contents = Decompiler.CFR_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
|
|
||||||
DiskWriter.replaceFile(path, contents, false);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
BytecodeViewer.handleException(
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t1.start();
|
|
||||||
}
|
|
||||||
if (result == 3) {
|
|
||||||
Thread t1 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
final ClassWriter cw = new ClassWriter(0);
|
|
||||||
try {
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
try {
|
|
||||||
Thread.sleep(200);
|
|
||||||
if (cn != null)
|
|
||||||
cn.accept(cw);
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String contents = Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileClassNode(cn,
|
|
||||||
cw.toByteArray());
|
|
||||||
DiskWriter.replaceFile(path, contents, false);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
BytecodeViewer.handleException(
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t1.start();
|
|
||||||
}
|
|
||||||
if (result == 4) {
|
|
||||||
Thread t1 = new Thread(() -> {
|
|
||||||
try {
|
|
||||||
final ClassWriter cw = new ClassWriter(0);
|
|
||||||
try {
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
try {
|
|
||||||
Thread.sleep(200);
|
|
||||||
Objects.requireNonNull(cn).accept(cw);
|
|
||||||
} catch (InterruptedException ignored) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
String contents = Decompiler.KRAKATAU_DECOMPILER.getDecompiler().
|
|
||||||
decompileClassNode(cn, cw.toByteArray());
|
|
||||||
DiskWriter.replaceFile(path, contents, false);
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
BytecodeViewer.handleException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t1.start();
|
|
||||||
}
|
|
||||||
if (result == 5) {
|
|
||||||
BytecodeViewer.updateBusyStatus(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, "Decompile Thread");
|
catch (Exception e)
|
||||||
decompileThread.start();
|
{
|
||||||
|
BytecodeViewer.handleException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int promptDecompilerUserSelect()
|
||||||
|
{
|
||||||
|
final JOptionPane pane = new JOptionPane("Which decompiler would you like to use?");
|
||||||
|
final Object[] options = new String[]{ "All", "Procyon", "CFR",
|
||||||
|
"Fernflower", "Krakatau", "Cancel"}; //TODO JDGUI,JADX
|
||||||
|
|
||||||
|
pane.setOptions(options);
|
||||||
|
final JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Select Decompiler");
|
||||||
|
dialog.setVisible(true);
|
||||||
|
final Object obj = pane.getValue();
|
||||||
|
|
||||||
|
int result = -1;
|
||||||
|
for (int k = 0; k < options.length; k++)
|
||||||
|
if (options[k].equals(obj))
|
||||||
|
result = k;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void decompileSaveAll(Decompiler decompiler, File targetJar, File outputZip, boolean saveAll)
|
||||||
|
{
|
||||||
|
//signal to the user that BCV is performing an action in the background
|
||||||
|
BytecodeViewer.updateBusyStatus(true);
|
||||||
|
|
||||||
|
//decompile all opened classes to zip
|
||||||
|
decompiler.getDecompiler().decompileToZip(targetJar.getAbsolutePath(), saveAll
|
||||||
|
? MiscUtils.append(outputZip, "-" + decompiler.getDecompilerNameProgrammic() + ".zip")
|
||||||
|
: outputZip.getAbsolutePath());
|
||||||
|
|
||||||
|
//signal to the user that BCV is finished performing that action
|
||||||
|
BytecodeViewer.updateBusyStatus(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void decompileCurrentlyOpenedResource(Decompiler decompiler, File outputFile, boolean saveAll)
|
||||||
|
{
|
||||||
|
//signal to the user that BCV is performing an action in the background
|
||||||
|
BytecodeViewer.updateBusyStatus(true);
|
||||||
|
|
||||||
|
//decompile the currently opened resource and save it to the specified file
|
||||||
|
DiskWriter.replaceFile(saveAll
|
||||||
|
? MiscUtils.append(outputFile, "-" + decompiler.getDecompilerNameProgrammic() + ".java")
|
||||||
|
: outputFile.getAbsolutePath(),
|
||||||
|
BCV.decompileCurrentlyOpenedClassNode(decompiler), false);
|
||||||
|
|
||||||
|
//signal to the user that BCV is finished performing that action
|
||||||
|
BytecodeViewer.updateBusyStatus(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue