Skip to content

Commit

Permalink
saveAsJar Should Throw Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Konloch committed Oct 5, 2024
1 parent cf92749 commit 471ae44
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 26 deletions.
15 changes: 13 additions & 2 deletions src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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
Expand Down Expand Up @@ -121,8 +122,18 @@ else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiersEx() & KeyEvent.CT
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -109,17 +110,26 @@ public void promptForExport()

Thread saveThread = new Thread(() ->
{
BytecodeViewer.updateBusyStatus(true);
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
try
{
BytecodeViewer.updateBusyStatus(true);
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";

JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);

Thread buildAPKThread = new Thread(() ->
Thread buildAPKThread = new Thread(() ->
{
APKTool.buildAPK(new File(input), file, finalContainer);
BytecodeViewer.updateBusyStatus(false);
}, "Process APK");

buildAPKThread.start();
}
catch (IOException ex)
{
APKTool.buildAPK(new File(input), file, finalContainer);
BytecodeViewer.updateBusyStatus(false);
}, "Process APK");

buildAPKThread.start();
BytecodeViewer.handleException(ex);
}
}, "Jar Export");

saveThread.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

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;
Expand Down Expand Up @@ -73,18 +74,27 @@ public void promptForExport()

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);

BytecodeViewer.updateBusyStatus(false);
}, "Process DEX");
Thread saveAsDex = new Thread(() ->
{
Dex2Jar.saveAsDex(new File(input), outputPath);

BytecodeViewer.updateBusyStatus(false);
}, "Process DEX");

saveAsDex.start();
saveAsDex.start();
}
catch (IOException ex)
{
BytecodeViewer.updateBusyStatus(false);
BytecodeViewer.handleException(ex);
}
}, "Jar Export");

saveAsJar.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import javax.swing.*;
import java.io.File;
import java.io.IOException;

/**
* @author Konloch
Expand Down Expand Up @@ -65,8 +66,18 @@ public void promptForExport()

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public static void saveAsJarClassesOnlyToDir(List<ClassNode> nodeList, String di
* @param nodeList The loaded ClassNodes
* @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);
JarOutputStream out = new JarOutputStream(fos))
Expand Down Expand Up @@ -448,9 +448,5 @@ public static void saveAsJar(List<ClassNode> nodeList, String path)

fileCollisionPrevention .clear();
}
catch (IOException e)
{
BytecodeViewer.handleException(e);
}
}
}

0 comments on commit 471ae44

Please sign in to comment.