File Chooser Cleanup

This commit is contained in:
Konloch 2021-06-26 08:03:11 -07:00
parent 6dac259299
commit b06db41efc
4 changed files with 111 additions and 118 deletions

View file

@ -84,7 +84,6 @@ import static the.bytecode.club.bytecodeviewer.Constants.*;
* + Krakatau Assembly compile - Needs to be fixed * + Krakatau Assembly compile - Needs to be fixed
* *
* TODO IN-PROGRESS: * TODO IN-PROGRESS:
* + Finish Compiler.JAVA_COMPILER
* + Finish dragging code * + Finish dragging code
* + Finish right-click tab menu detection * + Finish right-click tab menu detection
* + Fix hook inject for EZ-Injection * + Fix hook inject for EZ-Injection

View file

@ -35,6 +35,8 @@ import the.bytecode.club.bytecodeviewer.plugin.preinstalled.StackFramesRemover;
import the.bytecode.club.bytecodeviewer.plugin.preinstalled.ZKMStringDecrypter; import the.bytecode.club.bytecodeviewer.plugin.preinstalled.ZKMStringDecrypter;
import the.bytecode.club.bytecodeviewer.plugin.preinstalled.ZStringArrayDecrypter; import the.bytecode.club.bytecodeviewer.plugin.preinstalled.ZStringArrayDecrypter;
import the.bytecode.club.bytecodeviewer.util.*; import the.bytecode.club.bytecodeviewer.util.*;
import the.bytecode.club.bytecodeviewer.util.resources.ResourceDecompiling;
import the.bytecode.club.bytecodeviewer.util.resources.ResourceExporting;
import static the.bytecode.club.bytecodeviewer.Constants.*; import static the.bytecode.club.bytecodeviewer.Constants.*;
@ -829,6 +831,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) if (returnVal == JFileChooser.APPROVE_OPTION)
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.python = fc.getSelectedFile().getAbsolutePath(); Configuration.python = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -844,6 +847,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) if (returnVal == JFileChooser.APPROVE_OPTION)
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.javac = fc.getSelectedFile().getAbsolutePath(); Configuration.javac = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -859,6 +863,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) if (returnVal == JFileChooser.APPROVE_OPTION)
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.java = fc.getSelectedFile().getAbsolutePath(); Configuration.java = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -874,6 +879,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) if (returnVal == JFileChooser.APPROVE_OPTION)
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.python3 = fc.getSelectedFile().getAbsolutePath(); Configuration.python3 = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -893,6 +899,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) if (returnVal == JFileChooser.APPROVE_OPTION)
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.library = fc.getSelectedFile().getAbsolutePath(); Configuration.library = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -908,6 +915,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) if (returnVal == JFileChooser.APPROVE_OPTION)
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.rt = fc.getSelectedFile().getAbsolutePath(); Configuration.rt = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -925,6 +933,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) if (returnVal == JFileChooser.APPROVE_OPTION)
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(true);
BytecodeViewer.startPlugin(fc.getSelectedFile()); BytecodeViewer.startPlugin(fc.getSelectedFile());
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.viewer.updateBusyStatus(false);

View file

@ -1,11 +1,15 @@
package the.bytecode.club.bytecodeviewer.util; package the.bytecode.club.bytecodeviewer.util.resources;
import me.konloch.kontainer.io.DiskWriter; import me.konloch.kontainer.io.DiskWriter;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode; 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.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
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.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import javax.swing.*; import javax.swing.*;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
@ -23,35 +27,33 @@ public class ResourceDecompiling
{ {
public static void decompileSaveAll() public static void decompileSaveAll()
{ {
if (BytecodeViewer.getLoadedClasses().isEmpty()) { if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return; return;
} }
Thread t = new Thread(() -> { Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false)) if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return; return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() { JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
@Override "Select Zip Export",
public boolean accept(File f) { "Zip Archives",
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip"); "zip");
}
@Override
public String getDescription() {
return "Zip Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile(); File file = fc.getSelectedFile();
//auto appened zip
if (!file.getAbsolutePath().endsWith(".zip")) if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip"); file = new File(file.getAbsolutePath() + ".zip");
if (file.exists()) { if (file.exists())
{
JOptionPane pane = new JOptionPane( JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?"); "Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"}; Object[] options = new String[]{"Yes", "No"};
@ -73,11 +75,9 @@ public class ResourceDecompiling
} }
final File javaSucks = file; final File javaSucks = file;
final String path = MiscUtils.append(file, ".zip"); // cheap hax cause string is final final String path = MiscUtils.append(file, ".zip"); // cheap hax cause string is final
JOptionPane pane = new JOptionPane( JOptionPane pane = new JOptionPane("What decompiler will you use?");
"What decompiler will you use?");
Object[] options = new String[]{"All", "Procyon", "CFR", Object[] options = new String[]{"All", "Procyon", "CFR",
"Fernflower", "Krakatau", "Cancel"}; "Fernflower", "Krakatau", "Cancel"};
pane.setOptions(options); pane.setOptions(options);
@ -213,29 +213,22 @@ public class ResourceDecompiling
if (s == null) if (s == null)
return; return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() { JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
@Override "Select Java Files",
public boolean accept(File f) { "Java Source Files",
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("java"); "java");
}
@Override
public String getDescription() {
return "Java Source Files";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile(); File file = fc.getSelectedFile();
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(true);
final String path = MiscUtils.append(file, ".java"); // cheap hax cause final String path = MiscUtils.append(file, ".java"); // cheap hax because string is final
// string is final
if (new File(path).exists()) { if (new File(path).exists())
{
JOptionPane pane = new JOptionPane( JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?"); "Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"}; Object[] options = new String[]{"Yes", "No"};

View file

@ -1,7 +1,10 @@
package the.bytecode.club.bytecodeviewer.util; package the.bytecode.club.bytecodeviewer.util.resources;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.components.ExportJar; import the.bytecode.club.bytecodeviewer.gui.components.ExportJar;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
import the.bytecode.club.bytecodeviewer.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
@ -18,38 +21,36 @@ import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
*/ */
public class ResourceExporting public class ResourceExporting
{ {
public static void saveAsRunnableJar() public static void saveAsRunnableJar()
{ {
if (BytecodeViewer.getLoadedClasses().isEmpty()) { if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return; return;
} }
Thread t = new Thread(() -> {
Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false)) if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return; return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() { JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
@Override "Select Jar Export",
public boolean accept(File f) { "Jar Archives",
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip"); "jar");
}
@Override
public String getDescription() {
return "Zip Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile(); File file = fc.getSelectedFile();
String path = file.getAbsolutePath(); String path = file.getAbsolutePath();
//auto append .jar
if (!path.endsWith(".jar")) if (!path.endsWith(".jar"))
path = path + ".jar"; path = path + ".jar";
if (new File(path).exists()) { if (new File(path).exists())
{
JOptionPane pane = new JOptionPane( JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?"); "Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"}; Object[] options = new String[]{"Yes", "No"};
@ -78,30 +79,27 @@ public class ResourceExporting
public static void saveAsZip() public static void saveAsZip()
{ {
if (BytecodeViewer.getLoadedClasses().isEmpty()) { if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return; return;
} }
Thread t = new Thread(() -> { Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false)) if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return; return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() { JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
@Override "Select Zip Export",
public boolean accept(File f) { "Zip Archives",
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip"); "zip");
}
@Override
public String getDescription() {
return "Zip Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile(); File file = fc.getSelectedFile();
//auto append .zip
if (!file.getAbsolutePath().endsWith(".zip")) if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip"); file = new File(file.getAbsolutePath() + ".zip");
@ -142,38 +140,35 @@ public class ResourceExporting
public static void saveAsDex() public static void saveAsDex()
{ {
if (BytecodeViewer.getLoadedClasses().isEmpty()) { if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return; return;
} }
Thread t = new Thread(() -> { Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false)) if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return; return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() { JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
@Override "Select DEX Export",
public boolean accept(File f) { "Android DEX Files",
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("dex"); "dex");
}
@Override
public String getDescription() {
return "Android DEX Files";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION)
{
final File file = fc.getSelectedFile(); final File file = fc.getSelectedFile();
String output = file.getAbsolutePath(); String output = file.getAbsolutePath();
//auto append .dex
if (!output.endsWith(".dex")) if (!output.endsWith(".dex"))
output = output + ".dex"; output = output + ".dex";
final File file2 = new File(output); final File file2 = new File(output);
if (file2.exists())
if (file2.exists()) { {
JOptionPane pane = new JOptionPane( JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?"); "Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"}; Object[] options = new String[]{"Yes", "No"};
@ -259,33 +254,29 @@ public class ResourceExporting
final FileContainer finalContainer = container; final FileContainer finalContainer = container;
Thread t = new Thread(() -> { Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false)) if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return; return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() { JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
@Override "Select APK Export",
public boolean accept(File f) { "Android APK",
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("apk"); "apk");
}
@Override
public String getDescription() {
return "Android APK";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION)
{
final File file = fc.getSelectedFile(); final File file = fc.getSelectedFile();
String output = file.getAbsolutePath(); String output = file.getAbsolutePath();
//auto appened .apk
if (!output.endsWith(".apk")) if (!output.endsWith(".apk"))
output = output + ".apk"; output = output + ".apk";
final File file2 = new File(output); final File file2 = new File(output);
if (file2.exists())
if (file2.exists()) { {
JOptionPane pane = new JOptionPane( JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?"); "Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"}; Object[] options = new String[]{"Yes", "No"};
@ -306,14 +297,15 @@ public class ResourceExporting
} }
} }
Thread t14 = new Thread(() -> { Thread t14 = new Thread(() ->
{
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(true);
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar"; final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread t13 = new Thread(() -> { Thread t13 = new Thread(() ->
{
APKTool.buildAPK(new File(input), file2, finalContainer); APKTool.buildAPK(new File(input), file2, finalContainer);
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.viewer.updateBusyStatus(false);
}); });
t13.start(); t13.start();