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
*
* TODO IN-PROGRESS:
* + Finish Compiler.JAVA_COMPILER
* + Finish dragging code
* + Finish right-click tab menu detection
* + 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.ZStringArrayDecrypter;
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.*;
@ -829,6 +831,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.python = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -844,6 +847,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.javac = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -859,6 +863,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.java = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -874,6 +879,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.python3 = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -893,6 +899,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.library = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -908,6 +915,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.rt = fc.getSelectedFile().getAbsolutePath();
} catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
@ -925,6 +933,7 @@ public class MainViewerGUI extends JFrame
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
BytecodeViewer.viewer.updateBusyStatus(true);
BytecodeViewer.startPlugin(fc.getSelectedFile());
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 org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
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.filechooser.FileFilter;
@ -23,35 +27,33 @@ public class ResourceDecompiling
{
public static void decompileSaveAll()
{
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return;
}
Thread t = new Thread(() -> {
Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip");
}
@Override
public String getDescription() {
return "Zip Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
"Select Zip Export",
"Zip Archives",
"zip");
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
//auto appened zip
if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip");
if (file.exists()) {
if (file.exists())
{
JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"};
@ -73,11 +75,9 @@ public class ResourceDecompiling
}
final File javaSucks = file;
final String path = MiscUtils.append(file, ".zip"); // cheap hax cause string is final
JOptionPane pane = new JOptionPane(
"What decompiler will you use?");
JOptionPane pane = new JOptionPane("What decompiler will you use?");
Object[] options = new String[]{"All", "Procyon", "CFR",
"Fernflower", "Krakatau", "Cancel"};
pane.setOptions(options);
@ -213,29 +213,22 @@ public class ResourceDecompiling
if (s == null)
return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("java");
}
@Override
public String getDescription() {
return "Java Source Files";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
"Select Java Files",
"Java Source Files",
"java");
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
BytecodeViewer.viewer.updateBusyStatus(true);
final String path = MiscUtils.append(file, ".java"); // cheap hax cause
// string is final
final String path = MiscUtils.append(file, ".java"); // cheap hax because string is final
if (new File(path).exists()) {
if (new File(path).exists())
{
JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?");
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.Configuration;
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.filechooser.FileFilter;
@ -18,38 +21,36 @@ import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
*/
public class ResourceExporting
{
public static void saveAsRunnableJar()
{
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return;
}
Thread t = new Thread(() -> {
Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip");
}
@Override
public String getDescription() {
return "Zip Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
"Select Jar Export",
"Jar Archives",
"jar");
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
String path = file.getAbsolutePath();
//auto append .jar
if (!path.endsWith(".jar"))
path = path + ".jar";
if (new File(path).exists()) {
if (new File(path).exists())
{
JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"};
@ -78,30 +79,27 @@ public class ResourceExporting
public static void saveAsZip()
{
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return;
}
Thread t = new Thread(() -> {
Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip");
}
@Override
public String getDescription() {
return "Zip Archives";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
"Select Zip Export",
"Zip Archives",
"zip");
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
//auto append .zip
if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip");
@ -142,38 +140,35 @@ public class ResourceExporting
public static void saveAsDex()
{
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
if (BytecodeViewer.getLoadedClasses().isEmpty())
{
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
return;
}
Thread t = new Thread(() -> {
Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("dex");
}
@Override
public String getDescription() {
return "Android DEX Files";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
"Select DEX Export",
"Android DEX Files",
"dex");
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
if (returnVal == JFileChooser.APPROVE_OPTION)
{
final File file = fc.getSelectedFile();
String output = file.getAbsolutePath();
//auto append .dex
if (!output.endsWith(".dex"))
output = output + ".dex";
final File file2 = new File(output);
if (file2.exists()) {
if (file2.exists())
{
JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?");
Object[] options = new String[]{"Yes", "No"};
@ -259,33 +254,29 @@ public class ResourceExporting
final FileContainer finalContainer = container;
Thread t = new Thread(() -> {
Thread t = new Thread(() ->
{
if (BytecodeViewer.viewer.compileOnSave.isSelected() && !BytecodeViewer.compile(false))
return;
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("apk");
}
@Override
public String getDescription() {
return "Android APK";
}
});
fc.setFileHidingEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
"Select APK Export",
"Android APK",
"apk");
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION) {
if (returnVal == JFileChooser.APPROVE_OPTION)
{
final File file = fc.getSelectedFile();
String output = file.getAbsolutePath();
//auto appened .apk
if (!output.endsWith(".apk"))
output = output + ".apk";
final File file2 = new File(output);
if (file2.exists()) {
if (file2.exists())
{
JOptionPane pane = new JOptionPane(
"Are you sure you wish to overwrite this existing file?");
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);
final String input = tempDirectory + fs + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread t13 = new Thread(() -> {
Thread t13 = new Thread(() ->
{
APKTool.buildAPK(new File(input), file2, finalContainer);
BytecodeViewer.viewer.updateBusyStatus(false);
});
t13.start();