From 471ae44864f9423d2ec6c898981c0bab7287859b Mon Sep 17 00:00:00 2001 From: Konloch Date: Sat, 5 Oct 2024 00:21:07 -0600 Subject: [PATCH] saveAsJar Should Throw Exceptions --- .../club/bytecodeviewer/GlobalHotKeys.java | 15 ++++++++-- .../resources/exporting/impl/APKExport.java | 28 +++++++++++++------ .../resources/exporting/impl/DexExport.java | 28 +++++++++++++------ .../resources/exporting/impl/ZipExport.java | 15 ++++++++-- .../club/bytecodeviewer/util/JarUtils.java | 6 +--- 5 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java index dda8df13..22faf7fd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java @@ -27,6 +27,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils; import javax.swing.*; import java.awt.event.KeyEvent; import java.io.File; +import java.io.IOException; /** * Whenever a key is pressed on the swing UI it should get logged here @@ -121,8 +122,18 @@ public class GlobalHotKeys BytecodeViewer.updateBusyStatus(true); Thread jarExport = new Thread(() -> { - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath()); - BytecodeViewer.updateBusyStatus(false); + try + { + JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath()); + } + catch (IOException ex) + { + BytecodeViewer.handleException(ex); + } + finally + { + BytecodeViewer.updateBusyStatus(false); + } }, "Jar Export"); jarExport.start(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java index 8d1c92ba..a27e0d7a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java @@ -31,6 +31,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils; import javax.swing.*; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -109,17 +110,26 @@ public class APKExport implements Exporter Thread saveThread = new Thread(() -> { - BytecodeViewer.updateBusyStatus(true); - final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar"; - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input); - - Thread buildAPKThread = new Thread(() -> + try { - APKTool.buildAPK(new File(input), file, finalContainer); - BytecodeViewer.updateBusyStatus(false); - }, "Process APK"); + BytecodeViewer.updateBusyStatus(true); + final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar"; - 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"); saveThread.start(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java index 2c9e5348..e11b2502 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java @@ -29,6 +29,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils; import javax.swing.*; import java.io.File; +import java.io.IOException; import static the.bytecode.club.bytecodeviewer.Constants.FS; import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY; @@ -73,18 +74,27 @@ public class DexExport implements Exporter Thread saveAsJar = new Thread(() -> { - BytecodeViewer.updateBusyStatus(true); - final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar"; - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input); - - Thread saveAsDex = new Thread(() -> + try { - 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); - }, "Process DEX"); - - saveAsDex.start(); + BytecodeViewer.handleException(ex); + } }, "Jar Export"); saveAsJar.start(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java index be9b17bb..aba759ce 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java @@ -28,6 +28,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils; import javax.swing.*; import java.io.File; +import java.io.IOException; /** * @author Konloch @@ -65,8 +66,18 @@ public class ZipExport implements Exporter Thread saveThread = new Thread(() -> { - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath()); - BytecodeViewer.updateBusyStatus(false); + try + { + JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath()); + } + catch (IOException ex) + { + BytecodeViewer.handleException(ex); + } + finally + { + BytecodeViewer.updateBusyStatus(false); + } }, "Jar Export"); saveThread.start(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java index ac101883..9cc3888d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -405,7 +405,7 @@ public class JarUtils * @param nodeList The loaded ClassNodes * @param path the exact jar output path */ - public static void saveAsJar(List nodeList, String path) + public static void saveAsJar(List nodeList, String path) throws IOException { try (FileOutputStream fos = new FileOutputStream(path); JarOutputStream out = new JarOutputStream(fos)) @@ -448,9 +448,5 @@ public class JarUtils fileCollisionPrevention .clear(); } - catch (IOException e) - { - BytecodeViewer.handleException(e); - } } }