From deb23d3dd3b52603009b432acae19395541c311e Mon Sep 17 00:00:00 2001 From: Konloch Date: Tue, 6 Jul 2021 19:46:12 -0700 Subject: [PATCH] Error Prompt Cleanup --- .../club/bytecodeviewer/BytecodeViewer.java | 22 +++++++++++++++++++ .../club/bytecodeviewer/GlobalHotKeys.java | 10 ++++----- .../club/bytecodeviewer/api/Plugin.java | 5 +---- .../bytecodeviewer/gui/MainViewerGUI.java | 4 +--- .../plugins/MaliciousCodeScannerOptions.java | 5 +---- .../gui/plugins/ReplaceStringsOptions.java | 5 ++--- .../preinstalled/CodeSequenceDiagram.java | 9 ++++---- .../resources/ResourceDecompiling.java | 10 ++------- .../resources/exporting/impl/APKExport.java | 5 +---- .../resources/exporting/impl/DexExport.java | 5 +---- .../exporting/impl/RunnableJarExporter.java | 5 +---- .../resources/exporting/impl/ZipExport.java | 5 +---- 12 files changed, 42 insertions(+), 48 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 24a16f91..1c976ff8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -523,6 +523,28 @@ public class BytecodeViewer viewer.clearBusyStatus(); } + /** + * Returns true if there are no loaded resource classes + */ + public static boolean promptIfNoLoadedClasses() + { + if (BytecodeViewer.getLoadedClasses().isEmpty()) + { + BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + return true; + } + + return false; + } + + /** + * Handle the exception by creating a new window for bug reporting + */ + public static void handleException(Throwable t) + { + new ExceptionUI(t); + } + /** * Refreshes the title on all of the opened tabs */ diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java index 45217b66..7faa3263 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java @@ -47,18 +47,16 @@ public class GlobalHotKeys t.start(); } else if ((e.getKeyCode() == KeyEvent.VK_R) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { Configuration.lastHotKeyExecuted = System.currentTimeMillis(); - if (BytecodeViewer.getLoadedClasses().isEmpty()) { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } + new RunOptions().setVisible(true); } else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { Configuration.lastHotKeyExecuted = System.currentTimeMillis(); - if (BytecodeViewer.getLoadedClasses().isEmpty()) { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } Thread resourceExport = new Thread(() -> { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java index 9280841d..0b5745d9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/Plugin.java @@ -37,11 +37,8 @@ public abstract class Plugin extends Thread try { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } execute(BytecodeViewer.getLoadedClasses()); } catch (Exception e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 88d0b250..c4244bc4 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -791,10 +791,8 @@ public class MainViewerGUI extends JFrame public void runResources() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } new RunOptions().setVisible(true); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java index 303e5874..04741343 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java @@ -41,11 +41,8 @@ public class MaliciousCodeScannerOptions extends JFrame public static void open() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } new MaliciousCodeScannerOptions().setVisible(true); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java index 4c8f52d5..46e54f74 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java @@ -40,10 +40,9 @@ public class ReplaceStringsOptions extends JFrame { public static void open() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } + new ReplaceStringsOptions().setVisible(true); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java index 191b9ca2..d00a5a01 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java @@ -46,17 +46,18 @@ public class CodeSequenceDiagram extends Plugin { public static void open() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } + PluginManager.runPlugin(new CodeSequenceDiagram()); } @Override public void execute(ArrayList classNodeList) { + if (BytecodeViewer.promptIfNoLoadedClasses()) + return; + if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) { BytecodeViewer.showMessage("First open a class file."); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java index 25652356..3a1d1061 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java @@ -28,11 +28,8 @@ public class ResourceDecompiling { public static void decompileSaveAll() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } Thread decompileThread = new Thread(() -> { @@ -182,11 +179,8 @@ public class ResourceDecompiling public static void decompileSaveOpenedOnly() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) { 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 66b26e7e..cd014119 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 @@ -24,11 +24,8 @@ public class APKExport implements Exporter @Override public void promptForExport() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } List containers = BytecodeViewer.getFiles(); List validContainers = new ArrayList<>(); 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 b74e3a10..dccbef88 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 @@ -25,11 +25,8 @@ public class DexExport implements Exporter @Override public void promptForExport() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } Thread exportThread = new Thread(() -> { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java index b3c3b79c..8aff04e4 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java @@ -19,11 +19,8 @@ public class RunnableJarExporter implements Exporter @Override public void promptForExport() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } Thread exportThread = new Thread(() -> { 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 b71e3586..34ef858a 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 @@ -19,11 +19,8 @@ public class ZipExport implements Exporter @Override public void promptForExport() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) - { - BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); + if (BytecodeViewer.promptIfNoLoadedClasses()) return; - } Thread exportThread = new Thread(() -> {