saveAsJar Should Throw Exceptions

This commit is contained in:
Konloch 2024-10-05 00:21:07 -06:00
parent cf92749337
commit 471ae44864

AI 샘플 코드 생성 중입니다

Loading...
5 changed files with 65 additions and 27 deletions

View File

@ -27,6 +27,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.io.File; import java.io.File;
import java.io.IOException;
/** /**
* Whenever a key is pressed on the swing UI it should get logged here * Whenever a key is pressed on the swing UI it should get logged here
@ -121,8 +122,18 @@ public class GlobalHotKeys
BytecodeViewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Thread jarExport = new Thread(() -> Thread jarExport = new Thread(() ->
{ {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath()); try
BytecodeViewer.updateBusyStatus(false); {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath());
}
catch (IOException ex)
{
BytecodeViewer.handleException(ex);
}
finally
{
BytecodeViewer.updateBusyStatus(false);
}
}, "Jar Export"); }, "Jar Export");
jarExport.start(); jarExport.start();
} }

View File

@ -31,6 +31,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -109,17 +110,26 @@ public class APKExport implements Exporter
Thread saveThread = new Thread(() -> Thread saveThread = new Thread(() ->
{ {
BytecodeViewer.updateBusyStatus(true); try
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread buildAPKThread = new Thread(() ->
{ {
APKTool.buildAPK(new File(input), file, finalContainer); BytecodeViewer.updateBusyStatus(true);
BytecodeViewer.updateBusyStatus(false); final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
}, "Process APK");
buildAPKThread.start(); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread buildAPKThread = new Thread(() ->
{
APKTool.buildAPK(new File(input), file, finalContainer);
BytecodeViewer.updateBusyStatus(false);
}, "Process APK");
buildAPKThread.start();
}
catch (IOException ex)
{
BytecodeViewer.updateBusyStatus(false);
BytecodeViewer.handleException(ex);
}
}, "Jar Export"); }, "Jar Export");
saveThread.start(); saveThread.start();

View File

@ -29,6 +29,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
import java.io.IOException;
import static the.bytecode.club.bytecodeviewer.Constants.FS; import static the.bytecode.club.bytecodeviewer.Constants.FS;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY; import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
@ -73,18 +74,27 @@ public class DexExport implements Exporter
Thread saveAsJar = new Thread(() -> Thread saveAsJar = new Thread(() ->
{ {
BytecodeViewer.updateBusyStatus(true); try
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread saveAsDex = new Thread(() ->
{ {
Dex2Jar.saveAsDex(new File(input), outputPath); BytecodeViewer.updateBusyStatus(true);
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
Thread saveAsDex = new Thread(() ->
{
Dex2Jar.saveAsDex(new File(input), outputPath);
BytecodeViewer.updateBusyStatus(false);
}, "Process DEX");
saveAsDex.start();
}
catch (IOException ex)
{
BytecodeViewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Process DEX"); BytecodeViewer.handleException(ex);
}
saveAsDex.start();
}, "Jar Export"); }, "Jar Export");
saveAsJar.start(); saveAsJar.start();

View File

@ -28,6 +28,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
import java.io.IOException;
/** /**
* @author Konloch * @author Konloch
@ -65,8 +66,18 @@ public class ZipExport implements Exporter
Thread saveThread = new Thread(() -> Thread saveThread = new Thread(() ->
{ {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath()); try
BytecodeViewer.updateBusyStatus(false); {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath());
}
catch (IOException ex)
{
BytecodeViewer.handleException(ex);
}
finally
{
BytecodeViewer.updateBusyStatus(false);
}
}, "Jar Export"); }, "Jar Export");
saveThread.start(); saveThread.start();

View File

@ -405,7 +405,7 @@ public class JarUtils
* @param nodeList The loaded ClassNodes * @param nodeList The loaded ClassNodes
* @param path the exact jar output path * @param path the exact jar output path
*/ */
public static void saveAsJar(List<ClassNode> nodeList, String path) public static void saveAsJar(List<ClassNode> nodeList, String path) throws IOException
{ {
try (FileOutputStream fos = new FileOutputStream(path); try (FileOutputStream fos = new FileOutputStream(path);
JarOutputStream out = new JarOutputStream(fos)) JarOutputStream out = new JarOutputStream(fos))
@ -448,9 +448,5 @@ public class JarUtils
fileCollisionPrevention .clear(); fileCollisionPrevention .clear();
} }
catch (IOException e)
{
BytecodeViewer.handleException(e);
}
} }
} }