From f59823b185b6ba64dcab9ae2071d7fe6f5141263 Mon Sep 17 00:00:00 2001 From: Konloch Date: Thu, 26 Sep 2024 03:41:20 -0600 Subject: [PATCH 1/9] Code Style Update / Cleanup / Repackaging --- .../gui/resourceviewer/Workspace.java | 4 ++-- .../AbstractJTabbedPanePopupMenuHandler.java | 2 +- .../gui}/tabpopup/ITabPopupEventListener.java | 2 +- .../tabpopup/ITabZeroComponentEventListener.java | 2 +- .../gui}/tabpopup/JTabbedPanePopupEventHandler.java | 6 +++--- .../gui}/tabpopup/TabPopupEvent.java | 5 +---- .../gui}/tabpopup/closer/JTabbedPaneCloser.java | 13 +++++-------- .../closer/JTabbedPanePopupMenuTabsCloser.java | 7 +++---- .../closer/PopupMenuTabsCloseConfiguration.java | 2 +- 9 files changed, 18 insertions(+), 25 deletions(-) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/AbstractJTabbedPanePopupMenuHandler.java (97%) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/ITabPopupEventListener.java (96%) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/ITabZeroComponentEventListener.java (96%) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/JTabbedPanePopupEventHandler.java (97%) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/TabPopupEvent.java (96%) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/closer/JTabbedPaneCloser.java (95%) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java (93%) rename src/main/java/the/bytecode/club/{uikit => bytecodeviewer/gui}/tabpopup/closer/PopupMenuTabsCloseConfiguration.java (98%) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java index c402c010b..9875fda43 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java @@ -29,8 +29,8 @@ import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJButton; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedVisibleComponent; -import the.bytecode.club.uikit.tabpopup.closer.JTabbedPanePopupMenuTabsCloser; -import the.bytecode.club.uikit.tabpopup.closer.PopupMenuTabsCloseConfiguration; +import the.bytecode.club.bytecodeviewer.gui.tabpopup.closer.JTabbedPanePopupMenuTabsCloser; +import the.bytecode.club.bytecodeviewer.gui.tabpopup.closer.PopupMenuTabsCloseConfiguration; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/AbstractJTabbedPanePopupMenuHandler.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/AbstractJTabbedPanePopupMenuHandler.java similarity index 97% rename from src/main/java/the/bytecode/club/uikit/tabpopup/AbstractJTabbedPanePopupMenuHandler.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/AbstractJTabbedPanePopupMenuHandler.java index 3636736e4..f5340b353 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/AbstractJTabbedPanePopupMenuHandler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/AbstractJTabbedPanePopupMenuHandler.java @@ -16,7 +16,7 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup; +package the.bytecode.club.bytecodeviewer.gui.tabpopup; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/ITabPopupEventListener.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/ITabPopupEventListener.java similarity index 96% rename from src/main/java/the/bytecode/club/uikit/tabpopup/ITabPopupEventListener.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/ITabPopupEventListener.java index 5f7d035f1..7084e1330 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/ITabPopupEventListener.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/ITabPopupEventListener.java @@ -16,7 +16,7 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup; +package the.bytecode.club.bytecodeviewer.gui.tabpopup; import javax.swing.*; diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/ITabZeroComponentEventListener.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/ITabZeroComponentEventListener.java similarity index 96% rename from src/main/java/the/bytecode/club/uikit/tabpopup/ITabZeroComponentEventListener.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/ITabZeroComponentEventListener.java index 6b9a8ce98..ee9a895e3 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/ITabZeroComponentEventListener.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/ITabZeroComponentEventListener.java @@ -16,7 +16,7 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup; +package the.bytecode.club.bytecodeviewer.gui.tabpopup; import javax.swing.*; diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/JTabbedPanePopupEventHandler.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/JTabbedPanePopupEventHandler.java similarity index 97% rename from src/main/java/the/bytecode/club/uikit/tabpopup/JTabbedPanePopupEventHandler.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/JTabbedPanePopupEventHandler.java index 90778394c..234c5336d 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/JTabbedPanePopupEventHandler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/JTabbedPanePopupEventHandler.java @@ -16,7 +16,7 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup; +package the.bytecode.club.bytecodeviewer.gui.tabpopup; import javax.swing.*; import java.awt.*; @@ -68,13 +68,13 @@ protected void tryTriggerTabPopupEvent(MouseEvent e) if (e.isPopupTrigger()) { int index = tabbedPane.indexAtLocation(e.getX(), e.getY()); + if (index != -1) { Component popupOnTab = tabbedPane.getComponentAt(index); + if (this.tabPopupEventListener != null) - { this.tabPopupEventListener.onTabPopupEvent(tabbedPane, index, new TabPopupEvent(e, popupOnTab)); - } } } } diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/TabPopupEvent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/TabPopupEvent.java similarity index 96% rename from src/main/java/the/bytecode/club/uikit/tabpopup/TabPopupEvent.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/TabPopupEvent.java index 520ed4bc4..4cd3efc6d 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/TabPopupEvent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/TabPopupEvent.java @@ -16,16 +16,13 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup; +package the.bytecode.club.bytecodeviewer.gui.tabpopup; import java.awt.*; import java.awt.event.MouseEvent; public class TabPopupEvent extends MouseEvent { - /** - * - */ private static final long serialVersionUID = 2510164400674753411L; private final Component popupOnTab; diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/closer/JTabbedPaneCloser.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPaneCloser.java similarity index 95% rename from src/main/java/the/bytecode/club/uikit/tabpopup/closer/JTabbedPaneCloser.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPaneCloser.java index 4a69ad6b5..595d06992 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/closer/JTabbedPaneCloser.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPaneCloser.java @@ -16,9 +16,9 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup.closer; +package the.bytecode.club.bytecodeviewer.gui.tabpopup.closer; -import the.bytecode.club.uikit.tabpopup.ITabZeroComponentEventListener; +import the.bytecode.club.bytecodeviewer.gui.tabpopup.ITabZeroComponentEventListener; import javax.swing.*; import java.awt.*; @@ -61,17 +61,15 @@ public void removeOtherComponents(Component component) protected void removeOtherComponents(Component component, boolean equalStop) { int i = this.tabbedPane.getTabCount(); + while (i-- > 0) { Component c = this.tabbedPane.getComponentAt(i); + if (c != component) - { this.tabbedPane.remove(i); - } else if (equalStop) - { break; - } } tryTriggerTabZeroComponentEvent(); @@ -82,6 +80,7 @@ public void removeLeftComponents(Component component) int count = this.tabbedPane.getTabCount(); int i = 0; List removeTabs = new ArrayList<>(); + do { Component c = this.tabbedPane.getComponentAt(i); @@ -117,8 +116,6 @@ public void removeAllComponents() private void tryTriggerTabZeroComponentEvent() { if (this.tabbedPane.getTabCount() == 0 && tabZeroComponentEventListener != null) - { tabZeroComponentEventListener.onTabZeroComponent(this.tabbedPane); - } } } diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java similarity index 93% rename from src/main/java/the/bytecode/club/uikit/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java index c4121801a..0e9a1990e 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java @@ -16,9 +16,9 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup.closer; +package the.bytecode.club.bytecodeviewer.gui.tabpopup.closer; -import the.bytecode.club.uikit.tabpopup.AbstractJTabbedPanePopupMenuHandler; +import the.bytecode.club.bytecodeviewer.gui.tabpopup.AbstractJTabbedPanePopupMenuHandler; import javax.swing.*; import java.awt.*; @@ -79,8 +79,7 @@ protected void addItemCloseTab(JPopupMenu popUpMenu, Component popupOnTab) protected void addItemCloseOtherTabs(JPopupMenu popUpMenu, Component popupOnTab) { - addMenuItem(popUpMenu, "Close Others", e -> - {tabbedPaneCloser.removeOtherComponents(popupOnTab);}); + addMenuItem(popUpMenu, "Close Others", e -> tabbedPaneCloser.removeOtherComponents(popupOnTab)); } protected void addItemCloseAllTabs(JPopupMenu popUpMenu) diff --git a/src/main/java/the/bytecode/club/uikit/tabpopup/closer/PopupMenuTabsCloseConfiguration.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/PopupMenuTabsCloseConfiguration.java similarity index 98% rename from src/main/java/the/bytecode/club/uikit/tabpopup/closer/PopupMenuTabsCloseConfiguration.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/PopupMenuTabsCloseConfiguration.java index 659707c78..b25f32b45 100644 --- a/src/main/java/the/bytecode/club/uikit/tabpopup/closer/PopupMenuTabsCloseConfiguration.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/PopupMenuTabsCloseConfiguration.java @@ -16,7 +16,7 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.uikit.tabpopup.closer; +package the.bytecode.club.bytecodeviewer.gui.tabpopup.closer; /** * PopupMenu items configuration of close tabs From dd7e605db57fc60a6448eaf761bf16cf1d3ba07c Mon Sep 17 00:00:00 2001 From: cloudchamb3r Date: Fri, 27 Sep 2024 11:05:37 +0900 Subject: [PATCH 2/9] Add xapk extension in SUPPORTED_FILE_EXTENSIONS --- .../bytecode/club/bytecodeviewer/resources/ResourceType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java index aba5b328c..700f2e056 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java @@ -33,7 +33,7 @@ public enum ResourceType // TODO add the files icons for the missing files from the.bytecode.club.bytecodeviewer.util.SyntaxLanguage // or from org.fife.ui.rsyntaxtextarea.FileTypeUtil or from org.fife.ui.rsyntaxtextarea.SyntaxConstants - CLASS_FILE(IconResources.classIcon, "class"), JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"), ZIP_ARCHIVE(IconResources.zipIcon, "zip"), ANDROID_ARCHIVE(IconResources.androidIcon, "apk", "wapk", "dex"), IMAGE_FILE(IconResources.imageIcon, "png", "jpg", "jpeg", "bmp", "wbmp", "gif", "tif", "webp"), CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config", "csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess", "plugin", "attachprovider", "transportservice", "connector"), JAVA_FILE(IconResources.javaIcon, "java"), TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"), CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"), CSHARP_FILE(IconResources.csharpIcon, "cs"), BAT_FILE(IconResources.batIcon, "bat", "batch"), SH_FILE(IconResources.shIcon, "sh", "bash"), + CLASS_FILE(IconResources.classIcon, "class"), JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"), ZIP_ARCHIVE(IconResources.zipIcon, "zip"), ANDROID_ARCHIVE(IconResources.androidIcon, "apk", "wapk", "dex", "xapk"), IMAGE_FILE(IconResources.imageIcon, "png", "jpg", "jpeg", "bmp", "wbmp", "gif", "tif", "webp"), CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config", "csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess", "plugin", "attachprovider", "transportservice", "connector"), JAVA_FILE(IconResources.javaIcon, "java"), TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"), CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"), CSHARP_FILE(IconResources.csharpIcon, "cs"), BAT_FILE(IconResources.batIcon, "bat", "batch"), SH_FILE(IconResources.shIcon, "sh", "bash"), ; public static final Map extensionMap = new HashMap<>(); From ddd31b58d7e689d64cd9a5e7da2c0779560b5658 Mon Sep 17 00:00:00 2001 From: Konloch Date: Fri, 27 Sep 2024 01:34:28 -0600 Subject: [PATCH 3/9] Code Style Cleanup --- .../club/bytecodeviewer/resources/ResourceType.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java index 700f2e056..89918667c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java @@ -33,7 +33,18 @@ public enum ResourceType // TODO add the files icons for the missing files from the.bytecode.club.bytecodeviewer.util.SyntaxLanguage // or from org.fife.ui.rsyntaxtextarea.FileTypeUtil or from org.fife.ui.rsyntaxtextarea.SyntaxConstants - CLASS_FILE(IconResources.classIcon, "class"), JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"), ZIP_ARCHIVE(IconResources.zipIcon, "zip"), ANDROID_ARCHIVE(IconResources.androidIcon, "apk", "wapk", "dex", "xapk"), IMAGE_FILE(IconResources.imageIcon, "png", "jpg", "jpeg", "bmp", "wbmp", "gif", "tif", "webp"), CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config", "csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess", "plugin", "attachprovider", "transportservice", "connector"), JAVA_FILE(IconResources.javaIcon, "java"), TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"), CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"), CSHARP_FILE(IconResources.csharpIcon, "cs"), BAT_FILE(IconResources.batIcon, "bat", "batch"), SH_FILE(IconResources.shIcon, "sh", "bash"), + CLASS_FILE(IconResources.classIcon, "class"), + JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"), + ZIP_ARCHIVE(IconResources.zipIcon, "zip"), + ANDROID_ARCHIVE(IconResources.androidIcon, "apk", "wapk", "dex", "xapk"), + IMAGE_FILE(IconResources.imageIcon, "png", "jpg", "jpeg", "bmp", "wbmp", "gif", "tif", "webp"), + CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config", "csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess", "plugin", "attachprovider", "transportservice", "connector"), + JAVA_FILE(IconResources.javaIcon, "java"), + TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"), + CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"), + CSHARP_FILE(IconResources.csharpIcon, "cs"), + BAT_FILE(IconResources.batIcon, "bat", "batch"), + SH_FILE(IconResources.shIcon, "sh", "bash"), ; public static final Map extensionMap = new HashMap<>(); From 89a26407f84f43d9729c773ea118e47f46e19521 Mon Sep 17 00:00:00 2001 From: Konloch Date: Fri, 27 Sep 2024 01:34:46 -0600 Subject: [PATCH 4/9] Continue Decompiling On Parsing Error --- .../resources/classcontainer/ClassFileContainer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java index 7acd954b1..bc0001163 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java @@ -60,7 +60,7 @@ public void parse() CompilationUnit compilationUnit = StaticJavaParser.parse(this.content); compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null); } - catch (java.lang.ClassCastException | UnsolvedSymbolException | ParseProblemException e) + catch (java.util.NoSuchElementException | java.lang.ClassCastException | UnsolvedSymbolException | ParseProblemException e) { System.err.println("Parsing error!"); e.printStackTrace(); From 9922ec389c06a7acd92060e0580ad6554ff41bce Mon Sep 17 00:00:00 2001 From: Konloch Date: Fri, 27 Sep 2024 03:58:06 -0600 Subject: [PATCH 5/9] Continue Decompiling On Any Parsing Errors (Except IO) More of a pre-caution - if parsing fails we should still attempt to display the decompiled code. I've encountered a few errors and manually added them in, but I'm worried I missed one. To fix that I figure we just catch everything that isn't an IO Error. IO-Errors are probably user related (lack of space, insufficient permissions, etc) - So these errors we should forward to the user, the rest we can silence for developer eyes --- .../resources/classcontainer/ClassFileContainer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java index bc0001163..3e8c4bbbf 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java @@ -60,15 +60,15 @@ public void parse() CompilationUnit compilationUnit = StaticJavaParser.parse(this.content); compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null); } - catch (java.util.NoSuchElementException | java.lang.ClassCastException | UnsolvedSymbolException | ParseProblemException e) - { - System.err.println("Parsing error!"); - e.printStackTrace(); - } catch (IOException e) { throw new RuntimeException(e); } + catch (Exception e) + { + System.err.println("Parsing error: " + className); + e.printStackTrace(); + } } public String getName() From 5eed22ddb21ed5dd4a3ba3326e69b0e5b3aea58b Mon Sep 17 00:00:00 2001 From: Konloch Date: Fri, 27 Sep 2024 04:22:17 -0600 Subject: [PATCH 6/9] Move From CLI Magic Numbers --- .../bytecode/club/bytecodeviewer/BytecodeViewer.java | 8 ++++---- .../club/bytecodeviewer/CommandLineInput.java | 9 +++------ .../bytecode/club/bytecodeviewer/util/BootCheck.java | 5 ++--- .../bytecode/club/bytecodeviewer/util/CLIAction.java | 12 ++++++++++++ 4 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/util/CLIAction.java diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index e46a23af2..d94875e5d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -202,8 +202,8 @@ public static void main(String[] args) MiscUtils.setLanguage(MiscUtils.guessLanguage()); //handle CLI - int isCLI = CommandLineInput.parseCommandLine(args); - if (isCLI == CommandLineInput.STOP) + CLIAction isCLI = CommandLineInput.parseCommandLine(args); + if (isCLI == CLIAction.STOP) return; //load with shaded libraries @@ -214,11 +214,11 @@ public static void main(String[] args) else //load through bootloader { BOOT_CHECK.start(); - Boot.boot(args, isCLI != CommandLineInput.GUI); + Boot.boot(args, isCLI != CLIAction.GUI); } //CLI arguments say spawn the GUI - if (isCLI == CommandLineInput.GUI) + if (isCLI == CLIAction.GUI) { BytecodeViewer.boot(false); Configuration.bootState = BootState.GUI_SHOWING; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java index bcbc67646..dd0c944dd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java @@ -27,11 +27,13 @@ import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.translation.Language; +import the.bytecode.club.bytecodeviewer.util.CLIAction; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; import java.io.File; +import static the.bytecode.club.bytecodeviewer.util.CLIAction.*; import static the.bytecode.club.bytecodeviewer.Constants.*; /** @@ -46,11 +48,6 @@ public class CommandLineInput private static final Options OPTIONS = new Options(); private static final CommandLineParser PARSER = new DefaultParser(); - /*BECAUSE WHO DOESN'T LOVE MAGIC NUMBERS*/ - public static final int STOP = -1; - public static final int GUI = 0; - public static final int CLI = 1; - static { OPTIONS.addOption("help", false, "prints the help menu."); @@ -92,7 +89,7 @@ public static boolean containsCommand(String[] args) return false; } - public static int parseCommandLine(String[] args) + public static CLIAction parseCommandLine(String[] args) { if (!containsCommand(args)) return GUI; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java index d0cfd5101..c3608f710 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java @@ -109,10 +109,9 @@ public void failSafeLoadLibraries() Boot.hide(); - int CLI = CommandLineInput.parseCommandLine(BytecodeViewer.launchArgs); + CLIAction CLI = CommandLineInput.parseCommandLine(BytecodeViewer.launchArgs); - - if (CLI == CommandLineInput.GUI) + if (CLI == CLIAction.GUI) BytecodeViewer.boot(false); else { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/CLIAction.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/CLIAction.java new file mode 100644 index 000000000..5ab264096 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/CLIAction.java @@ -0,0 +1,12 @@ +package the.bytecode.club.bytecodeviewer.util; + +/** + * @author Konloch + * @since 9/27/2024 + */ +public enum CLIAction +{ + STOP, + GUI, + CLI +} From a028bba00b82f9e5ae99a54e3bbaaea3dd3ffa71 Mon Sep 17 00:00:00 2001 From: Konloch Date: Fri, 27 Sep 2024 04:23:42 -0600 Subject: [PATCH 7/9] Repackage CLI --- .../the/bytecode/club/bytecodeviewer/BytecodeViewer.java | 2 ++ .../club/bytecodeviewer/{util => cli}/CLIAction.java | 2 +- .../club/bytecodeviewer/{ => cli}/CommandLineInput.java | 8 +++++--- .../the/bytecode/club/bytecodeviewer/util/BootCheck.java | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) rename src/main/java/the/bytecode/club/bytecodeviewer/{util => cli}/CLIAction.java (68%) rename src/main/java/the/bytecode/club/bytecodeviewer/{ => cli}/CommandLineInput.java (98%) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index d94875e5d..c31fce834 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -29,6 +29,8 @@ import the.bytecode.club.bytecodeviewer.bootloader.BootState; import the.bytecode.club.bytecodeviewer.bootloader.InstallFatJar; import the.bytecode.club.bytecodeviewer.bootloader.UpdateCheck; +import the.bytecode.club.bytecodeviewer.cli.CLIAction; +import the.bytecode.club.bytecodeviewer.cli.CommandLineInput; import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; import the.bytecode.club.bytecodeviewer.gui.components.ExtendedJOptionPane; import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialog; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/CLIAction.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CLIAction.java similarity index 68% rename from src/main/java/the/bytecode/club/bytecodeviewer/util/CLIAction.java rename to src/main/java/the/bytecode/club/bytecodeviewer/cli/CLIAction.java index 5ab264096..a470090b3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/CLIAction.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CLIAction.java @@ -1,4 +1,4 @@ -package the.bytecode.club.bytecodeviewer.util; +package the.bytecode.club.bytecodeviewer.cli; /** * @author Konloch diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java similarity index 98% rename from src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java rename to src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java index dd0c944dd..0aa1f6386 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java @@ -16,7 +16,7 @@ * along with this program. If not, see . * ***************************************************************************/ -package the.bytecode.club.bytecodeviewer; +package the.bytecode.club.bytecodeviewer.cli; import me.konloch.kontainer.io.DiskWriter; import org.apache.commons.cli.CommandLine; @@ -25,15 +25,17 @@ import org.apache.commons.cli.Options; 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.Constants; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.translation.Language; -import the.bytecode.club.bytecodeviewer.util.CLIAction; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; import java.io.File; -import static the.bytecode.club.bytecodeviewer.util.CLIAction.*; +import static the.bytecode.club.bytecodeviewer.cli.CLIAction.*; import static the.bytecode.club.bytecodeviewer.Constants.*; /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java index c3608f710..c87450b16 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java @@ -19,7 +19,8 @@ package the.bytecode.club.bytecodeviewer.util; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.CommandLineInput; +import the.bytecode.club.bytecodeviewer.cli.CLIAction; +import the.bytecode.club.bytecodeviewer.cli.CommandLineInput; import the.bytecode.club.bytecodeviewer.bootloader.Boot; import the.bytecode.club.bytecodeviewer.bootloader.loader.ILoader; import the.bytecode.club.bytecodeviewer.bootloader.resource.external.EmptyExternalResource; From 3ab993242e2cf6892c9ab82745f09f5481e8f04d Mon Sep 17 00:00:00 2001 From: Konloch Date: Fri, 27 Sep 2024 05:45:03 -0600 Subject: [PATCH 8/9] Update Licenses --- .../LICENSES/{ASM.txt => ASM-license.txt} | 0 .../LICENSES/{BCV.txt => BCV-license.txt} | 0 .../LICENSES/byteanalysis-license.txt | 622 +++++++++++++++++- .../resources/LICENSES/janino-license.txt | 32 +- .../LICENSES/{smali.txt => smali-license.txt} | 0 5 files changed, 652 insertions(+), 2 deletions(-) rename src/main/resources/LICENSES/{ASM.txt => ASM-license.txt} (100%) rename src/main/resources/LICENSES/{BCV.txt => BCV-license.txt} (100%) rename src/main/resources/LICENSES/{smali.txt => smali-license.txt} (100%) diff --git a/src/main/resources/LICENSES/ASM.txt b/src/main/resources/LICENSES/ASM-license.txt similarity index 100% rename from src/main/resources/LICENSES/ASM.txt rename to src/main/resources/LICENSES/ASM-license.txt diff --git a/src/main/resources/LICENSES/BCV.txt b/src/main/resources/LICENSES/BCV-license.txt similarity index 100% rename from src/main/resources/LICENSES/BCV.txt rename to src/main/resources/LICENSES/BCV-license.txt diff --git a/src/main/resources/LICENSES/byteanalysis-license.txt b/src/main/resources/LICENSES/byteanalysis-license.txt index 6f942c081..94a045322 100644 --- a/src/main/resources/LICENSES/byteanalysis-license.txt +++ b/src/main/resources/LICENSES/byteanalysis-license.txt @@ -1 +1,621 @@ -NONE WHAT THE FUCK BIBL > https://github.com/TheBiblMan/Byte-Engineer-2 \ No newline at end of file + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS diff --git a/src/main/resources/LICENSES/janino-license.txt b/src/main/resources/LICENSES/janino-license.txt index 9df4ca687..ef871e242 100644 --- a/src/main/resources/LICENSES/janino-license.txt +++ b/src/main/resources/LICENSES/janino-license.txt @@ -1 +1,31 @@ -http://opensource.org/licenses/BSD-3-Clause \ No newline at end of file +Janino - An embedded Java[TM] compiler + +Copyright (c) 2001-2016, Arno Unkrig +Copyright (c) 2015-2016 TIBCO Software Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + 3. Neither the name of JANINO nor the names of its contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/main/resources/LICENSES/smali.txt b/src/main/resources/LICENSES/smali-license.txt similarity index 100% rename from src/main/resources/LICENSES/smali.txt rename to src/main/resources/LICENSES/smali-license.txt From 9353c968be53a13811e020295253dc5616d0a293 Mon Sep 17 00:00:00 2001 From: Konloch Date: Fri, 27 Sep 2024 05:51:50 -0600 Subject: [PATCH 9/9] Code Style Cleanup / General Code Improvements --- .../club/bytecodeviewer/Constants.java | 2 +- .../club/bytecodeviewer/GlobalHotKeys.java | 2 + .../club/bytecodeviewer/Settings.java | 6 + .../bytecodeviewer/SettingsSerializer.java | 3 + .../compilers/impl/JavaCompiler.java | 37 +++--- .../compilers/impl/KrakatauAssembler.java | 30 +++-- .../compilers/impl/SmaliAssembler.java | 19 ++-- .../decompilers/InternalDecompiler.java | 2 +- .../bytecode/FieldNodeDecompiler.java | 8 ++ .../bytecode/InstructionPrinter.java | 104 +++++++---------- .../bytecode/InstructionSearcher.java | 2 +- .../bytecode/MethodNodeDecompiler.java | 21 +++- .../bytecode/PrefixedStringBuilder.java | 12 +- .../impl/ASMTextifierDisassembler.java | 2 +- .../decompilers/impl/ASMifierGenerator.java | 2 +- .../impl/BytecodeDisassembler.java | 2 +- .../decompilers/impl/CFRDecompiler.java | 16 ++- .../impl/FernFlowerDecompiler.java | 25 ++++- .../decompilers/impl/JADXDecompiler.java | 40 +++---- .../decompilers/impl/JDGUIDecompiler.java | 9 +- .../decompilers/impl/JavapDisassembler.java | 7 +- .../decompilers/impl/KrakatauDecompiler.java | 105 +++++------------- .../impl/KrakatauDisassembler.java | 18 +-- .../decompilers/impl/ProcyonDecompiler.java | 36 +++--- .../decompilers/impl/SmaliDisassembler.java | 13 +-- .../decompilers/jdgui/JDGUIClassFileUtil.java | 4 +- .../components/DecompilerViewComponent.java | 2 + .../gui/components/ExportJar.java | 2 + .../gui/components/ExtendedJOptionPane.java | 1 + .../gui/components/FileChooser.java | 1 + .../gui/components/JFrameConsole.java | 3 +- .../gui/components/MethodsRenderer.java | 3 + .../gui/components/MultipleChoiceDialog.java | 1 + .../gui/components/MyErrorStripe.java | 9 ++ .../RSyntaxTextAreaHighlighterEx.java | 2 + .../gui/components/RunOptions.java | 1 + .../gui/components/SettingsDialog.java | 2 + .../gui/components/TextAreaSearchPanel.java | 2 + .../gui/components/WaitBusyIcon.java | 2 + .../gui/components/actions/GoToAction.java | 21 ++-- .../ResourceListIconRenderer.java | 2 +- .../gui/resourcesearch/SearchRadius.java | 3 +- .../gui/resourcesearch/SearchType.java | 6 +- .../DecompilerSelectionPane.java | 7 ++ .../gui/resourceviewer/TabComponent.java | 9 +- .../gui/resourceviewer/viewer/FileViewer.java | 2 +- .../AbstractJTabbedPanePopupMenuHandler.java | 2 + .../tabpopup/closer/JTabbedPaneCloser.java | 5 +- .../JTabbedPanePopupMenuTabsCloser.java | 1 + .../malwarescanner/MalwareScanModule.java | 11 +- .../malwarescanner/impl/AWTRobotScanner.java | 1 + .../malwarescanner/impl/JavaIOScanner.java | 1 + .../malwarescanner/impl/JavaNetScanner.java | 1 + .../impl/JavaRuntimeScanner.java | 1 + .../impl/NullSecurityManagerScanner.java | 7 +- .../impl/ReflectionScanner.java | 1 + .../obfuscators/JavaObfuscator.java | 19 ++-- .../obfuscators/RenameClasses.java | 1 + .../obfuscators/RenameFields.java | 1 + .../obfuscators/RenameMethods.java | 1 + .../obfuscators/mapping/RefactorMapper.java | 9 ++ .../obfuscators/mapping/Refactorer.java | 2 + .../obfuscators/mapping/Remapper.java | 45 +++++--- .../mapping/RemappingMethodAdapter.java | 7 +- .../mapping/data/FieldMappingData.java | 6 +- .../obfuscators/mapping/data/MappingData.java | 5 +- .../mapping/data/MethodMappingData.java | 6 +- .../obfuscators/rename/RenameClasses.java | 5 +- .../obfuscators/rename/RenameFields.java | 2 + .../obfuscators/rename/RenameMethods.java | 2 + .../preinstalled/AllatoriStringDecrypter.java | 4 +- .../plugin/preinstalled/ReplaceStrings.java | 4 + .../ViewAPKAndroidPermissions.java | 2 + .../plugin/preinstalled/ViewManifest.java | 2 + .../preinstalled/ZStringArrayDecrypter.java | 7 +- .../CompiledJavaPluginLaunchStrategy.java | 25 ++--- .../resources/ResourceDecompiling.java | 12 +- .../resources/ResourceType.java | 24 ++-- .../club/bytecodeviewer/util/JarUtils.java | 9 +- .../club/bytecodeviewer/util/MiscUtils.java | 25 ++++- .../util/NewlineOutputStream.java | 4 + .../bytecodeviewer/util/SyntaxLanguage.java | 39 ++++++- .../util/WindowStateChangeAdapter.java | 4 - .../club/bytecodeviewer/util/ZipUtils.java | 17 +-- 84 files changed, 544 insertions(+), 384 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java index fbba77434..98811d10d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java @@ -68,7 +68,7 @@ public class Constants public static final String FS = System.getProperty("file.separator"); public static final String NL = System.getProperty("line.separator"); - public static final String[] SUPPORTED_FILE_EXTENSIONS = ResourceType.supportedBCVExtensionMap.keySet().toArray(new String[0]); + public static final String[] SUPPORTED_FILE_EXTENSIONS = ResourceType.SUPPORTED_BCV_EXTENSION_MAP.keySet().toArray(new String[0]); public static final int ASM_VERSION = Opcodes.ASM9; public static final File BCVDir = resolveBCVRoot(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java index 7f6971dfa..46011af29 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java @@ -106,6 +106,7 @@ else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiersEx() & KeyEvent.CT JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(), "Select Zip Export", "Zip Archives", "zip"); int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); + if (returnVal == JFileChooser.APPROVE_OPTION) { Configuration.setLastSaveDirectory(fc.getSelectedFile()); @@ -124,6 +125,7 @@ else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiersEx() & KeyEvent.CT jarExport.start(); } }, "Resource Export"); + resourceExport.start(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java index c3eb39c79..943745844 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java @@ -127,32 +127,38 @@ protected static void resetRecentFilesMenu() { //build recent files BytecodeViewer.viewer.recentFilesSecondaryMenu.removeAll(); + for (String s : recentFiles) { if (!s.isEmpty()) { JMenuItem m = new JMenuItem(s); + m.addActionListener(e -> { JMenuItem m12 = (JMenuItem) e.getSource(); BytecodeViewer.openFiles(new File[]{new File(m12.getText())}, true); }); + BytecodeViewer.viewer.recentFilesSecondaryMenu.add(m); } } //build recent plugins BytecodeViewer.viewer.recentPluginsSecondaryMenu.removeAll(); + for (String s : recentPlugins) { if (!s.isEmpty()) { JMenuItem m = new JMenuItem(s); + m.addActionListener(e -> { JMenuItem m1 = (JMenuItem) e.getSource(); BytecodeViewer.startPlugin(new File(m1.getText())); }); + BytecodeViewer.viewer.recentPluginsSecondaryMenu.add(m); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java index a6fc470fe..dce2b1b62 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java @@ -338,11 +338,13 @@ public static void loadSettings() BytecodeViewer.viewer.refreshOnChange.setSelected(asBoolean(84)); boolean bool = Boolean.parseBoolean(asString(85)); + if (bool) { BytecodeViewer.viewer.setExtendedState(JFrame.MAXIMIZED_BOTH); BytecodeViewer.viewer.isMaximized = true; } + //86 is deprecated //87 is deprecated Configuration.lastOpenDirectory = asString(88); @@ -388,6 +390,7 @@ public static void loadSettings() //line 130 is used for preload if (Configuration.language != Language.ENGLISH) Configuration.language.setLanguageTranslations(); //load language translations + Settings.hasSetLanguageAsSystemLanguage = true; BytecodeViewer.viewer.viewPane1.setPaneEditable(asBoolean(131)); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java index 54c8483d0..7c45d0656 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java @@ -43,20 +43,23 @@ public class JavaCompiler extends InternalCompiler @Override public byte[] compile(String contents, String fullyQualifiedName) { - String fileStart = TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(12) + FS; - String fileStart2 = TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(12) + FS; - File java = new File(fileStart + FS + fullyQualifiedName + ".java"); - File clazz = new File(fileStart2 + FS + fullyQualifiedName + ".class"); - File cp = new File(TEMP_DIRECTORY + FS + "cpath_" + MiscUtils.randomString(12) + ".jar"); - File tempD = new File(fileStart + FS + fullyQualifiedName.substring(0, fullyQualifiedName.length() - + final String fileStart = TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(12) + FS; + final String fileStart2 = TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(12) + FS; + + final File javaFile = new File(fileStart + FS + fullyQualifiedName + ".java"); + final File classFile = new File(fileStart2 + FS + fullyQualifiedName + ".class"); + final File classPath = new File(TEMP_DIRECTORY + FS + "cpath_" + MiscUtils.randomString(12) + ".jar"); + final File tempDirectory = new File(fileStart + FS + fullyQualifiedName.substring(0, fullyQualifiedName.length() - fullyQualifiedName.split("/")[fullyQualifiedName.split("/").length - 1].length())); - tempD.mkdirs(); + //create the temp directories + tempDirectory.mkdirs(); new File(fileStart2).mkdirs(); if (Configuration.javac.isEmpty() || !new File(Configuration.javac).exists()) { - BytecodeViewer.showMessage("You need to set your Javac path, this requires the JDK to be downloaded." + NL + "(C:/Program Files/Java/JDK_xx/bin/javac.exe)"); + BytecodeViewer.showMessage("You need to set your Javac path, this requires the JDK to be downloaded." + + NL + "(C:/Program Files/Java/JDK_xx/bin/javac.exe)"); ExternalResources.getSingleton().selectJavac(); } @@ -66,8 +69,11 @@ public byte[] compile(String contents, String fullyQualifiedName) return null; } - DiskWriter.replaceFile(java.getAbsolutePath(), contents, false); - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), cp.getAbsolutePath()); + //write the file we're assembling to disk + DiskWriter.replaceFile(javaFile.getAbsolutePath(), contents, false); + + //write the entire temporary classpath to disk + JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), classPath.getAbsolutePath()); boolean cont = true; try @@ -77,10 +83,10 @@ public byte[] compile(String contents, String fullyQualifiedName) if (Configuration.library.isEmpty()) pb = new ProcessBuilder(Configuration.javac, "-d", fileStart2, - "-classpath", cp.getAbsolutePath(), java.getAbsolutePath()); + "-classpath", classPath.getAbsolutePath(), javaFile.getAbsolutePath()); else pb = new ProcessBuilder(Configuration.javac, "-d", fileStart2, - "-classpath", cp.getAbsolutePath() + System.getProperty("path.separator") + Configuration.library, java.getAbsolutePath()); + "-classpath", classPath.getAbsolutePath() + System.getProperty("path.separator") + Configuration.library, javaFile.getAbsolutePath()); Process process = pb.start(); BytecodeViewer.createdProcesses.add(process); @@ -111,6 +117,7 @@ public byte[] compile(String contents, String fullyQualifiedName) } log.append(NL).append(NL).append(TranslatedStrings.ERROR2).append(NL).append(NL); + try (InputStream is = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) @@ -123,7 +130,7 @@ public byte[] compile(String contents, String fullyQualifiedName) log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue); System.out.println(log); - if (!clazz.exists()) + if (!classFile.exists()) throw new Exception(log.toString()); } catch (Exception e) @@ -132,12 +139,12 @@ public byte[] compile(String contents, String fullyQualifiedName) e.printStackTrace(); } - cp.delete(); + classPath.delete(); if (cont) try { - return org.apache.commons.io.FileUtils.readFileToByteArray(clazz); + return org.apache.commons.io.FileUtils.readFileToByteArray(classFile); } catch (IOException e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java index c745d02e7..9f396ac33 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java @@ -51,16 +51,19 @@ public byte[] compile(String contents, String fullyQualifiedName) if (!ExternalResources.getSingleton().hasSetPython2Command()) return null; - File tempD = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); - tempD.mkdir(); + final File tempDirectory1 = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); + final File tempDirectory2 = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); + final File javaFile = new File(tempDirectory1.getAbsolutePath() + FS + fullyQualifiedName + ".j"); + final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar"); - File tempJ = new File(tempD.getAbsolutePath() + FS + fullyQualifiedName + ".j"); - DiskWriter.replaceFile(tempJ.getAbsolutePath(), contents, true); + //create the temp directories + tempDirectory1.mkdir(); + tempDirectory2.mkdir(); - final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); - tempDirectory.mkdir(); + //write the file we're assembling to disk + DiskWriter.replaceFile(javaFile.getAbsolutePath(), contents, true); - final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar"); + //write the entire temporary classpath to disk JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); StringBuilder log = new StringBuilder(); @@ -72,7 +75,7 @@ public byte[] compile(String contents, String fullyQualifiedName) pythonCommands = ArrayUtils.addAll(pythonCommands, "-2"); ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3 - krakatauWorkingDirectory + FS + "assemble.py", "-out", tempDirectory.getAbsolutePath(), tempJ.getAbsolutePath())); + krakatauWorkingDirectory + FS + "assemble.py", "-out", tempDirectory2.getAbsolutePath(), javaFile.getAbsolutePath())); Process process = pb.start(); BytecodeViewer.createdProcesses.add(process); @@ -101,10 +104,15 @@ public byte[] compile(String contents, String fullyQualifiedName) log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue); System.err.println(log); - byte[] b = FileUtils.readFileToByteArray(Objects.requireNonNull(ExternalResources.getSingleton().findFile(tempDirectory, ".class"))); - tempDirectory.delete(); + //read the assembled bytes from disk + byte[] assembledBytes = FileUtils.readFileToByteArray(Objects.requireNonNull(ExternalResources.getSingleton().findFile(tempDirectory2, ".class"))); + + //cleanup + tempDirectory2.delete(); tempJar.delete(); - return b; + + //return the assembled file + return assembledBytes; } catch (Exception e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java index 58e6e7328..fc2d5fef6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java @@ -44,19 +44,21 @@ public class SmaliAssembler extends InternalCompiler @Override public byte[] compile(String contents, String fullyQualifiedName) { - String fileStart = TEMP_DIRECTORY + FS + "temp"; - int fileNumber = MiscUtils.getClassNumber(fileStart, ".dex"); - + final String fileStart = TEMP_DIRECTORY + FS + "temp"; + final int fileNumber = MiscUtils.getClassNumber(fileStart, ".dex"); final File tempSmaliFolder = new File(fileStart + fileNumber + "-smalifolder" + FS); - tempSmaliFolder.mkdir(); - File tempSmali = new File(tempSmaliFolder.getAbsolutePath() + FS + fileNumber + ".smali"); - File tempDex = new File("./out.dex"); - File tempJar = new File(fileStart + fileNumber + ".jar"); - File tempJarFolder = new File(fileStart + fileNumber + "-jar" + FS); + final File tempSmali = new File(tempSmaliFolder.getAbsolutePath() + FS + fileNumber + ".smali"); + final File tempDex = new File("./out.dex"); + final File tempJar = new File(fileStart + fileNumber + ".jar"); + final File tempJarFolder = new File(fileStart + fileNumber + "-jar" + FS); + + //create the temp directory + tempSmaliFolder.mkdir(); try { + //write the file we're assembling to disk DiskWriter.replaceFile(tempSmali.getAbsolutePath(), contents, false); } catch (Exception e) @@ -107,6 +109,7 @@ else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.view System.out.println("Saved as: " + outputClass.getAbsolutePath()); + //return the assembled file return FileUtils.readFileToByteArray(outputClass); } catch (java.lang.NullPointerException ignored) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/InternalDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/InternalDecompiler.java index 9aa144349..5cba6872a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/InternalDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/InternalDecompiler.java @@ -27,7 +27,7 @@ */ public abstract class InternalDecompiler { - public abstract String decompileClassNode(ClassNode cn, byte[] b); + public abstract String decompileClassNode(ClassNode cn, byte[] bytes); public abstract void decompileToZip(String sourceJar, String zipName); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/FieldNodeDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/FieldNodeDecompiler.java index 1c9a0b683..1c08d5407 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/FieldNodeDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/FieldNodeDecompiler.java @@ -37,11 +37,14 @@ public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, FieldNod { String s = getAccessString(f.access); sb.append(s); + if (s.length() > 0) sb.append(" "); + sb.append(Type.getType(f.desc).getClassName()); sb.append(" "); sb.append(f.name); + if (f.value != null) { sb.append(" = "); @@ -59,13 +62,16 @@ public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, FieldNod sb.append(")"); } } + sb.append(";"); + return sb; } private static String getAccessString(int access) { List tokens = new ArrayList<>(); + if ((access & Opcodes.ACC_PUBLIC) != 0) tokens.add("public"); if ((access & Opcodes.ACC_PRIVATE) != 0) @@ -84,6 +90,7 @@ private static String getAccessString(int access) tokens.add("volatile"); if (tokens.size() == 0) return ""; + // hackery delimeters StringBuilder sb = new StringBuilder(tokens.get(0)); for (int i = 1; i < tokens.size(); i++) @@ -91,6 +98,7 @@ private static String getAccessString(int access) sb.append(" "); sb.append(tokens.get(i)); } + return sb.toString(); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java index 7d05456ce..a96e1929d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java @@ -61,8 +61,6 @@ public InstructionPrinter(MethodNode m, TypeAndName[] args) mNode = m; labels = new HashMap<>(); precalculateLabelIndexes(m); - // matchedInsns = new ArrayList(); // ingnored because - // match = false match = false; } @@ -125,97 +123,39 @@ public String printInstruction(AbstractInsnNode ain) { String line = ""; if (ain instanceof VarInsnNode) - { line = printVarInsnNode((VarInsnNode) ain); - } else if (ain instanceof IntInsnNode) - { line = printIntInsnNode((IntInsnNode) ain); - } else if (ain instanceof FieldInsnNode) - { line = printFieldInsnNode((FieldInsnNode) ain); - } else if (ain instanceof MethodInsnNode) - { line = printMethodInsnNode((MethodInsnNode) ain); - } else if (ain instanceof LdcInsnNode) - { line = printLdcInsnNode((LdcInsnNode) ain); - } else if (ain instanceof InsnNode) - { line = printInsnNode((InsnNode) ain); - } else if (ain instanceof JumpInsnNode) - { line = printJumpInsnNode((JumpInsnNode) ain); - } else if (ain instanceof LineNumberNode) - { line = printLineNumberNode((LineNumberNode) ain); - } else if (ain instanceof LabelNode) - { - if (firstLabel && BytecodeViewer.viewer.appendBracketsToLabels.isSelected()) - info.add("}"); - - LabelNode label = (LabelNode) ain; - if (mNode.tryCatchBlocks != null) - { - List tcbs = mNode.tryCatchBlocks; - String starting = tcbs.stream().filter(tcb -> tcb.start == label).map(tcb -> "start TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); - String ending = tcbs.stream().filter(tcb -> tcb.end == label).map(tcb -> "end TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); - String handlers = tcbs.stream().filter(tcb -> tcb.handler == label).map(tcb -> "handle TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); - if (!ending.isEmpty()) - info.add("// " + ending); - if (!starting.isEmpty()) - info.add("// " + starting); - if (!handlers.isEmpty()) - info.add("// " + handlers); - } line = printLabelNode((LabelNode) ain); - - if (BytecodeViewer.viewer.appendBracketsToLabels.isSelected()) - { - if (!firstLabel) - firstLabel = true; - line += " {"; - } - } else if (ain instanceof TypeInsnNode) - { line = printTypeInsnNode((TypeInsnNode) ain); - } else if (ain instanceof FrameNode) - { line = printFrameNode((FrameNode) ain); - } else if (ain instanceof IincInsnNode) - { line = printIincInsnNode((IincInsnNode) ain); - } else if (ain instanceof TableSwitchInsnNode) - { line = printTableSwitchInsnNode((TableSwitchInsnNode) ain); - } else if (ain instanceof LookupSwitchInsnNode) - { line = printLookupSwitchInsnNode((LookupSwitchInsnNode) ain); - } else if (ain instanceof InvokeDynamicInsnNode) - { line = printInvokeDynamicInsNode((InvokeDynamicInsnNode) ain); - } else if (ain instanceof MultiANewArrayInsnNode) - { line = printMultiANewArrayInsNode((MultiANewArrayInsnNode) ain); - } else - { line += "UNADDED OPCODE: " + nameOpcode(ain.getOpcode()) + " " + ain; - } return line; } @@ -312,11 +252,44 @@ protected String printLineNumberNode(LineNumberNode lnn) return ""; } - protected String printLabelNode(LabelNode label) + protected String printOnlyLabelNode(LabelNode label) { return "L" + resolveLabel(label); } + protected String printLabelNode(LabelNode label) + { + if (firstLabel && BytecodeViewer.viewer.appendBracketsToLabels.isSelected()) + info.add("}"); + + String line = ""; + + if (mNode.tryCatchBlocks != null) + { + List tcbs = mNode.tryCatchBlocks; + String starting = tcbs.stream().filter(tcb -> tcb.start == label).map(tcb -> "start TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); + String ending = tcbs.stream().filter(tcb -> tcb.end == label).map(tcb -> "end TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); + String handlers = tcbs.stream().filter(tcb -> tcb.handler == label).map(tcb -> "handle TCB" + tcbs.indexOf(tcb)).collect(Collectors.joining(", ")); + if (!ending.isEmpty()) + info.add("// " + ending); + if (!starting.isEmpty()) + info.add("// " + starting); + if (!handlers.isEmpty()) + info.add("// " + handlers); + } + + line = printOnlyLabelNode(label); + + if (BytecodeViewer.viewer.appendBracketsToLabels.isSelected()) + { + if (!firstLabel) + firstLabel = true; + line += " {"; + } + + return line; + } + protected String printTypeInsnNode(TypeInsnNode tin) { try @@ -403,6 +376,7 @@ private String printFrameNode(FrameNode frame) { StringBuilder sb = new StringBuilder(); sb.append(nameFrameType(frame.type)).append(" "); + sb.append("(Locals"); if (frame.local != null && !frame.local.isEmpty()) { @@ -490,15 +464,13 @@ protected String nameOpcode(int opcode) protected int resolveLabel(LabelNode label) { if (labels.containsKey(label)) - { return labels.get(label); - } else { - /*int newLabelIndex = labels.size() + 1; + //NOTE: Should NEVER enter this state, but if it ever does, here's the fall-back solution + int newLabelIndex = labels.size() + 1; labels.put(label, newLabelIndex); - return newLabelIndex;*/ - throw new IllegalStateException("LabelNode index not found. (Label not in InsnList?)"); + return newLabelIndex; } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionSearcher.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionSearcher.java index c04500ddf..390786917 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionSearcher.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionSearcher.java @@ -36,7 +36,6 @@ public class InstructionSearcher implements Opcodes protected InsnList insns; protected InstructionPattern pattern; - protected List matches; public InstructionSearcher(InsnList insns, int[] opcodes) @@ -62,6 +61,7 @@ public boolean search() { if (ain instanceof LineNumberNode || ain instanceof FrameNode) continue; + if (pattern.accept(ain)) { matches.add(pattern.getLastMatch()); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/MethodNodeDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/MethodNodeDecompiler.java index bb6cd09b4..ed7b255df 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/MethodNodeDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/MethodNodeDecompiler.java @@ -40,14 +40,17 @@ public class MethodNodeDecompiler public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, MethodNode m, ClassNode cn) { String className; + if (cn.name.contains("/")) className = cn.name.substring(cn.name.lastIndexOf("/") + 1); else className = cn.name; String s = getAccessString(m.access); + sb.append(" "); sb.append(s); + if (s.length() > 0) sb.append(" "); @@ -73,7 +76,6 @@ else if (!m.name.equals("")) for (int i = 0; i < argTypes.length; i++) { final Type type = argTypes[i]; - final TypeAndName tan = new TypeAndName(); final String argName = "arg" + i; @@ -89,10 +91,12 @@ else if (!m.name.equals("")) } int amountOfThrows = m.exceptions.size(); + if (amountOfThrows > 0) { sb.append(" throws "); sb.append(m.exceptions.get(0));// exceptions is list + for (int i = 1; i < amountOfThrows; i++) { sb.append(", "); @@ -109,7 +113,6 @@ else if (!m.name.equals("")) } else { - sb.append(" {"); if (BytecodeViewer.viewer.debugHelpers.isSelected()) @@ -161,10 +164,12 @@ else if (m.name.equals("")) sb.append(" handled by L"); sb.append(insnPrinter.resolveLabel(o.handler)); sb.append(": "); + if (o.type != null) sb.append(o.type); else sb.append("Type is null."); + sb.append(NL); } @@ -174,8 +179,10 @@ else if (m.name.equals("")) sb.append(insn); sb.append(NL); } + sb.append(" }" + NL); } + return sb; } @@ -194,6 +201,7 @@ private static void addAttrList(List list, String name, PrefixedStringBuilder sb.append(">"); sb.append(NL); } + sb.append(NL); } } @@ -203,7 +211,8 @@ private static String printAttr(Object o, InstructionPrinter insnPrinter) if (o instanceof LocalVariableNode) { LocalVariableNode lvn = (LocalVariableNode) o; - return "index=" + lvn.index + " , name=" + lvn.name + " , desc=" + lvn.desc + ", sig=" + lvn.signature + ", start=L" + insnPrinter.resolveLabel(lvn.start) + ", end=L" + insnPrinter.resolveLabel(lvn.end); + return "index=" + lvn.index + " , name=" + lvn.name + " , desc=" + lvn.desc + ", sig=" + lvn.signature + + ", start=L" + insnPrinter.resolveLabel(lvn.start) + ", end=L" + insnPrinter.resolveLabel(lvn.end); } else if (o instanceof AnnotationNode) { @@ -212,6 +221,7 @@ else if (o instanceof AnnotationNode) sb.append("desc = "); sb.append(an.desc); sb.append(" , values = "); + if (an.values != null) { sb.append(Arrays.toString(an.values.toArray())); @@ -220,10 +230,13 @@ else if (o instanceof AnnotationNode) { sb.append("[]"); } + return sb.toString(); } + if (o == null) return ""; + return o.toString(); } @@ -258,6 +271,7 @@ private static String getAccessString(int access) tokens.add("varargs"); if (tokens.isEmpty()) return ""; + // hackery delimeters StringBuilder sb = new StringBuilder(tokens.get(0)); for (int i = 1; i < tokens.size(); i++) @@ -265,6 +279,7 @@ private static String getAccessString(int access) sb.append(" "); sb.append(tokens.get(i)); } + return sb.toString(); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/PrefixedStringBuilder.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/PrefixedStringBuilder.java index 3f8c62a30..5c8d4c9b9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/PrefixedStringBuilder.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/bytecode/PrefixedStringBuilder.java @@ -36,15 +36,11 @@ public PrefixedStringBuilder() public PrefixedStringBuilder append(String s) { sb.append(s); - if (s.contains("\n") && (prefix != null) && (prefix.length() > 0))// insert - // the - // prefix - // at - // every - // new - // line, - // overridable + + // insert the prefix at every new line, overridable + if (s.contains("\n") && (prefix != null) && (prefix.length() > 0)) sb.append(prefix); + return this; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java index 963efbefc..d52fc3d3a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java @@ -34,7 +34,7 @@ public class ASMTextifierDisassembler extends InternalDecompiler { @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { StringWriter writer = new StringWriter(); cn.accept(new TraceClassVisitor(null, new Textifier(), new PrintWriter(writer))); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java index d58604e93..578d85250 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java @@ -34,7 +34,7 @@ public class ASMifierGenerator extends InternalDecompiler { @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { StringWriter writer = new StringWriter(); cn.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer))); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BytecodeDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BytecodeDisassembler.java index ebcc8b60f..53ed17ca4 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BytecodeDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/BytecodeDisassembler.java @@ -32,7 +32,7 @@ public class BytecodeDisassembler extends InternalDecompiler { @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { return ClassNodeDecompiler.decompile(new PrefixedStringBuilder(), new ArrayList<>(), cn).toString(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/CFRDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/CFRDecompiler.java index 112ec4e6c..0c85d98ad 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/CFRDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/CFRDecompiler.java @@ -59,9 +59,9 @@ public class CFRDecompiler extends InternalDecompiler private static final String CLASS_SUFFIX = ".class"; @Override - public String decompileClassNode(ClassNode cn, byte[] content) + public String decompileClassNode(ClassNode cn, byte[] bytes) { - return decompile(cn, cn.name, content); + return decompile(cn, cn.name, bytes); } private String decompile(ClassNode cn, String name, byte[] content) @@ -93,7 +93,10 @@ private String decompile(ClassNode cn, String name, byte[] content) @Override public void decompileToZip(String sourceJar, String outJar) { - try (JarFile jfile = new JarFile(new File(sourceJar)); FileOutputStream dest = new FileOutputStream(outJar); BufferedOutputStream buffDest = new BufferedOutputStream(dest); ZipOutputStream out = new ZipOutputStream(buffDest)) + try (JarFile jfile = new JarFile(new File(sourceJar)); + FileOutputStream dest = new FileOutputStream(outJar); + BufferedOutputStream buffDest = new BufferedOutputStream(dest); + ZipOutputStream out = new ZipOutputStream(buffDest)) { byte[] data = new byte[1024]; @@ -105,6 +108,7 @@ public void decompileToZip(String sourceJar, String outJar) if (entry.getName().endsWith(CLASS_SUFFIX)) { JarEntry etn = new JarEntry(entry.getName().replace(CLASS_SUFFIX, ".java")); + if (history.add(etn)) { out.putNextEntry(etn); @@ -203,6 +207,7 @@ public Options generateOptions() options.put("recovertypehints", String.valueOf(BytecodeViewer.viewer.recoveryTypehInts.isSelected())); options.put("forcereturningifs", String.valueOf(BytecodeViewer.viewer.forceTurningIFs.isSelected())); options.put("forloopaggcapture", String.valueOf(BytecodeViewer.viewer.forLoopAGGCapture.isSelected())); + return new OptionsImpl(options); } @@ -226,11 +231,15 @@ public Pair getClassFileContent(String classFilePath) throws IOE { if (classFilePath.equals(this.classFilePath) && content != null) return Pair.make(content, classFilePath); + if (container == null) return super.getClassFileContent(classFilePath); + byte[] data = container.resourceClassBytes.get(classFilePath); + if (data == null) return super.getClassFileContent(classFilePath); + return Pair.make(data, classFilePath); } @@ -259,6 +268,7 @@ public Sink getSink(SinkType sinkType, SinkClass sinkClass) { return x -> dumpDecompiled.accept((SinkReturns.Decompiled) x); } + return ignore -> { }; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java index 6ae2f8f09..2187e2e22 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/FernFlowerDecompiler.java @@ -65,7 +65,7 @@ public void decompileToZip(String sourceJar, String zipName) } @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { String start = TEMP_DIRECTORY + FS + MiscUtils.getUniqueName("", ".class"); @@ -74,7 +74,7 @@ public String decompileClassNode(ClassNode cn, byte[] b) String exception = ""; try (FileOutputStream fos = new FileOutputStream(tempClass)) { - fos.write(b); + fos.write(bytes); } catch (IOException e) { @@ -154,7 +154,26 @@ public String decompileClassNode(ClassNode cn, byte[] b) private String[] generateMainMethod(String className, String folder) { - return new String[]{"-rbr=" + r(BytecodeViewer.viewer.rbr.isSelected()), "-rsy=" + r(BytecodeViewer.viewer.rsy.isSelected()), "-din=" + r(BytecodeViewer.viewer.din.isSelected()), "-dc4=" + r(BytecodeViewer.viewer.dc4.isSelected()), "-das=" + r(BytecodeViewer.viewer.das.isSelected()), "-hes=" + r(BytecodeViewer.viewer.hes.isSelected()), "-hdc=" + r(BytecodeViewer.viewer.hdc.isSelected()), "-dgs=" + r(BytecodeViewer.viewer.dgs.isSelected()), "-ner=" + r(BytecodeViewer.viewer.ner.isSelected()), "-den=" + r(BytecodeViewer.viewer.den.isSelected()), "-rgn=" + r(BytecodeViewer.viewer.rgn.isSelected()), "-bto=" + r(BytecodeViewer.viewer.bto.isSelected()), "-nns=" + r(BytecodeViewer.viewer.nns.isSelected()), "-uto=" + r(BytecodeViewer.viewer.uto.isSelected()), "-udv=" + r(BytecodeViewer.viewer.udv.isSelected()), "-rer=" + r(BytecodeViewer.viewer.rer.isSelected()), "-fdi=" + r(BytecodeViewer.viewer.fdi.isSelected()), "-asc=" + r(BytecodeViewer.viewer.asc.isSelected()), "-ren=" + r(BytecodeViewer.viewer.ren.isSelected()), className, folder}; + return new String[]{"-rbr=" + r(BytecodeViewer.viewer.rbr.isSelected()), + "-rsy=" + r(BytecodeViewer.viewer.rsy.isSelected()), + "-din=" + r(BytecodeViewer.viewer.din.isSelected()), + "-dc4=" + r(BytecodeViewer.viewer.dc4.isSelected()), + "-das=" + r(BytecodeViewer.viewer.das.isSelected()), + "-hes=" + r(BytecodeViewer.viewer.hes.isSelected()), + "-hdc=" + r(BytecodeViewer.viewer.hdc.isSelected()), + "-dgs=" + r(BytecodeViewer.viewer.dgs.isSelected()), + "-ner=" + r(BytecodeViewer.viewer.ner.isSelected()), + "-den=" + r(BytecodeViewer.viewer.den.isSelected()), + "-rgn=" + r(BytecodeViewer.viewer.rgn.isSelected()), + "-bto=" + r(BytecodeViewer.viewer.bto.isSelected()), + "-nns=" + r(BytecodeViewer.viewer.nns.isSelected()), + "-uto=" + r(BytecodeViewer.viewer.uto.isSelected()), + "-udv=" + r(BytecodeViewer.viewer.udv.isSelected()), + "-rer=" + r(BytecodeViewer.viewer.rer.isSelected()), + "-fdi=" + r(BytecodeViewer.viewer.fdi.isSelected()), + "-asc=" + r(BytecodeViewer.viewer.asc.isSelected()), + "-ren=" + r(BytecodeViewer.viewer.ren.isSelected()), + className, folder}; } private String r(boolean b) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java index c55e8ecc1..c69a35354 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JADXDecompiler.java @@ -42,10 +42,8 @@ */ public class JADXDecompiler extends InternalDecompiler { - private final Random r = new Random(); - @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { String fileStart = TEMP_DIRECTORY + FS; @@ -54,23 +52,23 @@ public String decompileClassNode(ClassNode cn, byte[] b) try (FileOutputStream fos = new FileOutputStream(tempClass)) { - fos.write(b); + fos.write(bytes); } catch (IOException e) { BytecodeViewer.handleException(e); } - File fuckery = new File(fuckery(fileStart)); - fuckery.mkdirs(); + File freeDirectory = new File(findUnusedFile(fileStart)); + freeDirectory.mkdirs(); try { JadxArgs args = new JadxArgs(); args.setInputFile(tempClass); - args.setOutDir(fuckery); - args.setOutDirSrc(fuckery); - args.setOutDirRes(fuckery); + args.setOutDir(freeDirectory); + args.setOutDirSrc(freeDirectory); + args.setOutDirRes(freeDirectory); JadxDecompiler jadx = new JadxDecompiler(args); jadx.load(); @@ -86,8 +84,8 @@ public String decompileClassNode(ClassNode cn, byte[] b) tempClass.delete(); - if (fuckery.exists()) - return findFile(MiscUtils.listFiles(fuckery)); + if (freeDirectory.exists()) + return findFile(MiscUtils.listFiles(freeDirectory)); if (exception.isEmpty()) exception = "Decompiled source file not found!"; @@ -95,29 +93,29 @@ public String decompileClassNode(ClassNode cn, byte[] b) return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception; } - //TODO remove - public String fuckery(String start) + public String findUnusedFile(String start) { - int failSafe = 0; - while (failSafe++ <= 42069) + long index = 0; + + while (true) { - File f = new File(start + r.nextInt(Integer.MAX_VALUE)); + File f = new File(start + index); + if (!f.exists()) return f.toString(); } - - return null; } - public String findFile(File[] fA) + public String findFile(File[] fileArray) { - for (File f : fA) + for (File f : fileArray) { if (f.isDirectory()) return findFile(MiscUtils.listFiles(f)); else { String s; + try { s = DiskReader.loadAsString(f.getAbsolutePath()); @@ -131,6 +129,7 @@ public String findFile(File[] fA) return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception; } + return s; } } @@ -141,5 +140,6 @@ public String findFile(File[] fA) @Override public void decompileToZip(String sourceJar, String zipName) { + //TODO } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java index 177356335..13af2a4fb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JDGUIDecompiler.java @@ -50,9 +50,10 @@ public class JDGUIDecompiler extends InternalDecompiler { @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { String exception; + try { final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); @@ -75,14 +76,13 @@ public String decompileClassNode(ClassNode cn, byte[] b) try (FileOutputStream fos = new FileOutputStream(tempClass)) { - fos.write(b); + fos.write(bytes); } catch (IOException e) { BytecodeViewer.handleException(e); } - String pathToClass = tempClass.getAbsolutePath().replace('/', File.separatorChar).replace('\\', File.separatorChar); String directoryPath = JDGUIClassFileUtil.ExtractDirectoryPath(pathToClass); String internalPath = JDGUIClassFileUtil.ExtractInternalPath(directoryPath, pathToClass); @@ -104,8 +104,6 @@ public boolean isMergeEmptyLines() DirectoryLoader loader = new DirectoryLoader(new File(directoryPath)); - //PrintStream ps = new PrintStream("test.html"); - //HtmlPrinter printer = new HtmlPrinter(ps); org.jd.core.v1.api.Decompiler decompiler = new ClassFileToJavaSourceDecompiler(); try (PrintStream ps = new PrintStream(tempJava.getAbsolutePath()); PlainTextPrinter printer = new PlainTextPrinter(preferences, ps)) @@ -130,5 +128,6 @@ public boolean isMergeEmptyLines() @Override public void decompileToZip(String sourceJar, String zipName) { + //TODO } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java index 853cacda2..90c300b43 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/JavapDisassembler.java @@ -49,20 +49,21 @@ public class JavapDisassembler extends InternalDecompiler { @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { if (!ExternalResources.getSingleton().hasJavaToolsSet()) return "Set Java Tools Path!"; - return synchronizedDecompilation(cn, b); + return synchronizedDecompilation(cn, bytes); } private synchronized String synchronizedDecompilation(ClassNode cn, byte[] b) { final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); - tempDirectory.mkdir(); final File tempClass = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".class"); + tempDirectory.mkdir(); + DiskWriter.replaceFileBytes(tempClass.getAbsolutePath(), b, false); JFrameConsolePrintStream sysOutBuffer = null; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java index cd004f194..902c4c88a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDecompiler.java @@ -64,12 +64,14 @@ public String buildCLIArguments() return ";" + Arrays.stream(files).filter(File::isFile).map(File::getAbsolutePath).collect(Collectors.joining(";")); } - public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, ClassNode cn) + @Override + public String decompileClassNode(ClassNode cn, byte[] bytes) { if (!ExternalResources.getSingleton().hasSetPython2Command()) return TranslatedStrings.YOU_NEED_TO_SET_YOUR_PYTHON_2_PATH.toString(); ExternalResources.getSingleton().rtCheck(); + if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage(TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_A + "\r\n" + TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_B); @@ -82,74 +84,23 @@ public String decompileClassNode(File krakatauTempJar, File krakatauTempDir, Cla return TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_A + " " + TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_B; } - String s = ExceptionUI.SEND_STACKTRACE_TO_NL; - - try - { - String[] pythonCommands = new String[]{Configuration.python2}; - if (Configuration.python2Extra) - pythonCommands = ArrayUtils.addAll(pythonCommands, "-2"); - - ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3 - krakatauWorkingDirectory + FS + "decompile.py", "-skip", //love you storyyeller <3 - "-nauto", "-path", Configuration.rt + ";" + krakatauTempJar.getAbsolutePath() + buildCLIArguments(), "-out", krakatauTempDir.getAbsolutePath(), cn.name + ".class")); - - Process process = pb.start(); - BytecodeViewer.createdProcesses.add(process); - - StringBuilder log = new StringBuilder(TranslatedStrings.PROCESS2 + NL + NL); - - //Read out dir output - try (InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr)) - { - String line; - while ((line = br.readLine()) != null) - { - log.append(NL).append(line); - } - } - - log.append(NL).append(NL).append(TranslatedStrings.ERROR2).append(NL).append(NL); - - try (InputStream is = process.getErrorStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr)) - { - String line; - while ((line = br.readLine()) != null) - { - log.append(NL).append(line); - } - } + final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); + final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar"); - int exitValue = process.waitFor(); - log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue); - s = log.toString(); + tempDirectory.mkdir(); - //if the motherfucker failed this'll fail, aka wont set. - s = DiskReader.loadAsString(krakatauTempDir.getAbsolutePath() + FS + cn.name + ".java"); - } - catch (Exception e) - { - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - e.printStackTrace(); - s += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw; - } + JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); - return s; + return decompileClassNode(tempJar, tempDirectory, cn); } - @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(File tempJar, File tempDir, ClassNode cn) { - //TODO look into transforming through krakatau as a zip rather than direct classfile - if (!ExternalResources.getSingleton().hasSetPython2Command()) return TranslatedStrings.YOU_NEED_TO_SET_YOUR_PYTHON_2_PATH.toString(); + ExternalResources.getSingleton().rtCheck(); + if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage(TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_A + "\r\n" + TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_B); @@ -158,17 +109,11 @@ public String decompileClassNode(ClassNode cn, byte[] b) if (Configuration.rt.isEmpty()) { - BytecodeViewer.showMessage("You need to set RT.jar!"); - return "Set your paths"; + BytecodeViewer.showMessage(TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_A + "\r\n" + TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_B); + return TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_A + " " + TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_B; } - String s = ExceptionUI.SEND_STACKTRACE_TO_NL; - - final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); - tempDirectory.mkdir(); - final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar"); - - JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath()); + String returnString = ExceptionUI.SEND_STACKTRACE_TO_NL; try { @@ -178,7 +123,8 @@ public String decompileClassNode(ClassNode cn, byte[] b) ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3 krakatauWorkingDirectory + FS + "decompile.py", "-skip", //love you storyyeller <3 - "-nauto", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath() + buildCLIArguments(), "-out", tempDirectory.getAbsolutePath(), cn.name + ".class")); + "-nauto", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath() + buildCLIArguments(), + "-out", tempDir.getAbsolutePath(), cn.name + ".class")); Process process = pb.start(); BytecodeViewer.createdProcesses.add(process); @@ -212,22 +158,20 @@ public String decompileClassNode(ClassNode cn, byte[] b) int exitValue = process.waitFor(); log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue); - s = log.toString(); + returnString = log.toString(); - //if the motherfucker failed this'll fail, aka wont set. - s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + FS + cn.name + ".java"); - tempDirectory.delete(); - tempJar.delete(); + // update the string on a successful disassemble + returnString = DiskReader.loadAsString(tempDir.getAbsolutePath() + FS + cn.name + ".java"); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(); - s += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw; + returnString += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw; } - return s; + return returnString; } @Override @@ -237,18 +181,19 @@ public void decompileToZip(String sourceJar, String zipName) return; ExternalResources.getSingleton().rtCheck(); + if (Configuration.rt.isEmpty()) { BytecodeViewer.showMessage(TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_A + "\r\n" + TranslatedStrings.YOU_NEED_TO_SET_YOUR_JAVA_RT_PATH_B); ExternalResources.getSingleton().selectJRERTLibrary(); } - String ran = MiscUtils.randomString(32); + final String ran = MiscUtils.randomString(32); final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + ran + FS); - tempDirectory.mkdir(); - final File tempJar = new File(sourceJar); + tempDirectory.mkdir(); + try { String[] pythonCommands = new String[]{Configuration.python2}; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java index f67a255f9..da42c6908 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/KrakatauDisassembler.java @@ -45,12 +45,12 @@ public class KrakatauDisassembler extends InternalDecompiler { @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { if (!ExternalResources.getSingleton().hasSetPython2Command()) return TranslatedStrings.YOU_NEED_TO_SET_YOUR_PYTHON_2_PATH.toString(); - String s = ExceptionUI.SEND_STACKTRACE_TO_NL; + String returnString = ExceptionUI.SEND_STACKTRACE_TO_NL; final File tempDirectory = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS); tempDirectory.mkdir(); @@ -98,19 +98,20 @@ public String decompileClassNode(ClassNode cn, byte[] b) int exitValue = process.waitFor(); log.append(NL).append(NL).append(TranslatedStrings.EXIT_VALUE_IS).append(" ").append(exitValue); - s = log.toString(); + returnString = log.toString(); - // if the motherfucker failed this'll fail, aka won't set. - s = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + FS + cn.name + ".j"); + // update the string on a successful disassemble + returnString = DiskReader.loadAsString(tempDirectory.getAbsolutePath() + FS + cn.name + ".j"); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(); - s += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw; + returnString += NL + ExceptionUI.SEND_STACKTRACE_TO_NL + sw; } - return s; + + return returnString; } @Override @@ -132,7 +133,8 @@ public void decompileToZip(String sourceJar, String zipName) pythonCommands = ArrayUtils.addAll(pythonCommands, "-2"); ProcessBuilder pb = new ProcessBuilder(ArrayUtils.addAll(pythonCommands, "-O", //love you storyyeller <3 - krakatauWorkingDirectory + FS + "disassemble.py", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath(), "-out", tempDirectory.getAbsolutePath(), tempJar.getAbsolutePath())); + krakatauWorkingDirectory + FS + "disassemble.py", "-path", Configuration.rt + ";" + tempJar.getAbsolutePath(), + "-out", tempDirectory.getAbsolutePath(), tempJar.getAbsolutePath())); Process process = pb.start(); BytecodeViewer.createdProcesses.add(process); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ProcyonDecompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ProcyonDecompiler.java index 8aab8ab08..a125fd463 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ProcyonDecompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ProcyonDecompiler.java @@ -75,18 +75,17 @@ public DecompilerSettings getDecompilerSettings() } @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { String exception; try { - String fileStart = TEMP_DIRECTORY + FS + "temp"; - + final String fileStart = TEMP_DIRECTORY + FS + "temp"; final File tempClass = new File(MiscUtils.getUniqueName(fileStart, ".class") + ".class"); try (FileOutputStream fos = new FileOutputStream(tempClass)) { - fos.write(b); + fos.write(bytes); } catch (IOException e) { @@ -104,6 +103,7 @@ public String decompileClassNode(ClassNode cn, byte[] b) decompilationOptions.setFullDecompilation(true); TypeDefinition resolvedType; + if (type == null || ((resolvedType = type.resolve()) == null)) throw new Exception("Unable to resolve type."); @@ -142,7 +142,10 @@ public void decompileToZip(String sourceJar, String zipName) */ private void doSaveJarDecompiled(File inFile, File outFile) throws Exception { - try (JarFile jfile = new JarFile(inFile); FileOutputStream dest = new FileOutputStream(outFile); BufferedOutputStream buffDest = new BufferedOutputStream(dest); ZipOutputStream out = new ZipOutputStream(buffDest)) + try (JarFile jfile = new JarFile(inFile); + FileOutputStream dest = new FileOutputStream(outFile); + BufferedOutputStream buffDest = new BufferedOutputStream(dest); + ZipOutputStream out = new ZipOutputStream(buffDest)) { byte[] data = new byte[1024]; DecompilerSettings settings = getDecompilerSettings(); @@ -157,24 +160,30 @@ private void doSaveJarDecompiled(File inFile, File outFile) throws Exception Enumeration ent = jfile.entries(); Set history = new HashSet<>(); + while (ent.hasMoreElements()) { JarEntry entry = ent.nextElement(); + if (entry.getName().endsWith(".class")) { JarEntry etn = new JarEntry(entry.getName().replace(".class", ".java")); + if (history.add(etn)) { out.putNextEntry(etn); + try { String internalName = StringUtilities.removeRight(entry.getName(), ".class"); TypeReference type = metadataSystem.lookupType(internalName); TypeDefinition resolvedType; + if ((type == null) || ((resolvedType = type.resolve()) == null)) { throw new Exception("Unable to resolve type."); } + Writer writer = new OutputStreamWriter(out); settings.getLanguage().decompileType(resolvedType, new PlainTextOutput(writer), decompilationOptions); writer.flush(); @@ -190,10 +199,13 @@ private void doSaveJarDecompiled(File inFile, File outFile) throws Exception try { JarEntry etn = new JarEntry(entry.getName()); + if (history.add(etn)) continue; + history.add(etn); out.putNextEntry(etn); + try (InputStream in = jfile.getInputStream(entry)) { if (in != null) @@ -214,9 +226,7 @@ private void doSaveJarDecompiled(File inFile, File outFile) throws Exception { // some jars contain duplicate pom.xml entries: ignore it if (!ze.getMessage().contains("duplicate")) - { throw ze; - } } } } @@ -229,28 +239,26 @@ private void doSaveJarDecompiled(File inFile, File outFile) throws Exception public static final class LuytenTypeLoader implements ITypeLoader { - private final List _typeLoaders; + private final List typeLoaders; public LuytenTypeLoader() { - _typeLoaders = new ArrayList<>(); - _typeLoaders.add(new InputTypeLoader()); + typeLoaders = new ArrayList<>(); + typeLoaders.add(new InputTypeLoader()); } public List getTypeLoaders() { - return _typeLoaders; + return typeLoaders; } @Override public boolean tryLoadType(String internalName, Buffer buffer) { - for (ITypeLoader typeLoader : _typeLoaders) + for (ITypeLoader typeLoader : typeLoaders) { if (typeLoader.tryLoadType(internalName, buffer)) - { return true; - } buffer.reset(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java index 5bd45b56d..66c8c12a7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/SmaliDisassembler.java @@ -44,21 +44,20 @@ public class SmaliDisassembler extends InternalDecompiler { @Override - public String decompileClassNode(ClassNode cn, byte[] b) + public String decompileClassNode(ClassNode cn, byte[] bytes) { - String exception = ""; - String fileStart = TEMP_DIRECTORY + FS + "temp"; - - String start = MiscUtils.getUniqueName(fileStart, ".class"); - + final String fileStart = TEMP_DIRECTORY + FS + "temp"; + final String start = MiscUtils.getUniqueName(fileStart, ".class"); final File tempClass = new File(start + ".class"); final File tempDex = new File(start + ".dex"); final File tempDexOut = new File(start + "-out"); final File tempSmali = new File(start + "-smali"); //output directory + String exception = ""; + try (FileOutputStream fos = new FileOutputStream(tempClass)) { - fos.write(b); + fos.write(bytes); } catch (IOException e) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java index 2b418dd41..b841e1980 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/jdgui/JDGUIClassFileUtil.java @@ -40,7 +40,9 @@ public static String ExtractDirectoryPath(String pathToClass) { String directoryPath; - try (FileInputStream fis = new FileInputStream(pathToClass); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis)) + try (FileInputStream fis = new FileInputStream(pathToClass); + BufferedInputStream bis = new BufferedInputStream(fis); + DataInputStream dis = new DataInputStream(bis)) { int magic = dis.readInt(); if (magic != ClassFileReader.JAVA_MAGIC_NUMBER) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java index 7a4c77eb9..bf01013e9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java @@ -59,6 +59,7 @@ private void createMenu() { if (type == JAVA || type == JAVA_NON_EDITABLE || type == JAVA_AND_BYTECODE) menu.add(java); + if (type == BYTECODE || type == JAVA_AND_BYTECODE || type == BYTECODE_NON_EDITABLE) menu.add(bytecode); @@ -75,6 +76,7 @@ public void addToGroup(ButtonGroup group) { if (type == JAVA || type == JAVA_NON_EDITABLE || type == JAVA_AND_BYTECODE) group.add(java); + if (type == BYTECODE || type == JAVA_AND_BYTECODE || type == BYTECODE_NON_EDITABLE) group.add(bytecode); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java index 8f2f55460..5dfe1877d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExportJar.java @@ -57,11 +57,13 @@ public ExportJar(String jarPath) btnNewButton.addActionListener(arg0 -> { BytecodeViewer.updateBusyStatus(true); + Thread t = new Thread(() -> { JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath, manifest.getText()); BytecodeViewer.updateBusyStatus(false); }, "Jar Export"); + t.start(); dispose(); }); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExtendedJOptionPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExtendedJOptionPane.java index ae4a9fc01..fa7811947 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExtendedJOptionPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/ExtendedJOptionPane.java @@ -151,6 +151,7 @@ public static void showJPanelDialog(Component parentComponent, JScrollPane panel private static JDialog createNewJDialog(Component parentComponent, JOptionPane pane, String title, int style, OnCreate onCreate) { JDialog dialog = pane.createDialog(parentComponent, title); + if (JDialog.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java index 3796a7451..f6e9d5303 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java @@ -45,6 +45,7 @@ public FileChooser(boolean skipFileFilter, File file, String title, String descr Set extensionSet = new HashSet<>(Arrays.asList(extensions)); setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + try { setSelectedFile(file); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java index 349b96d3d..91d60fe58 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JFrameConsole.java @@ -144,7 +144,8 @@ public String trimConsoleText(String s) String trimmed = s.substring(0, max); if (!trimmed.startsWith("WARNING: Skipping")) - trimmed = ("WARNING: Skipping " + skipped + " chars, allowing " + max + "\n\r") + "Full log saved to: " + tempFile.getAbsolutePath() + "\n\r\n\r" + trimmed; + trimmed = ("WARNING: Skipping " + skipped + " chars, allowing " + max + "\n\r") + + "Full log saved to: " + tempFile.getAbsolutePath() + "\n\r\n\r" + trimmed; return trimmed; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MethodsRenderer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MethodsRenderer.java index 42c5881c4..95667673a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MethodsRenderer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MethodsRenderer.java @@ -48,6 +48,7 @@ public Component getListCellRendererComponent(JList list, Object value, int i MethodParser methods; List methodParsers = bytecodeViewPanelUpdater.viewer.methods; BytecodeViewPanel bytecodeViewPanel = bytecodeViewPanelUpdater.bytecodeViewPanel; + try { methods = methodParsers.get(bytecodeViewPanel.decompiler.ordinal()); @@ -56,8 +57,10 @@ public Component getListCellRendererComponent(JList list, Object value, int i { methods = methodParsers.get(bytecodeViewPanel.panelIndex); } + MethodParser.Method method = methods.getMethod(methodIndex); setText(method.toString()); + return this; } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MultipleChoiceDialog.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MultipleChoiceDialog.java index 9d21e8ccb..4b3ebd23d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MultipleChoiceDialog.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MultipleChoiceDialog.java @@ -47,6 +47,7 @@ public int promptChoice() dialog.setVisible(true); Object obj = pane.getValue(); int result = -1; + for (int k = 0; k < options.length; k++) if (options[k].equals(obj)) result = k; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MyErrorStripe.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MyErrorStripe.java index 60ec11392..5f9deff71 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MyErrorStripe.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/MyErrorStripe.java @@ -71,6 +71,7 @@ private int lineToY(int line, Rectangle r) float lineCount = textArea.getLineCount(); int lineHeight = textArea.getLineHeight(); int linesPerVisibleRect = h / lineHeight; + return Math.round((h - 1) * line / Math.max(lineCount, linesPerVisibleRect)); } @@ -81,6 +82,7 @@ private int yToLine(int y) int lineHeight = textArea.getLineHeight(); int linesPerVisibleRect = h / lineHeight; int lineCount = textArea.getLineCount(); + if (y < h) { float at = y / (float) h; @@ -119,6 +121,7 @@ private void addMarkersForRanges(List occurrences, Map occurrences, Map -1) { try @@ -353,6 +359,7 @@ private void addNotice(ParserNotice notice) protected void paintComponent(Graphics g) { final ParserNotice notice = getHighestPriorityNotice(); + if (notice != null) paintParserNoticeMarker((Graphics2D) g, notice, getWidth(), getHeight()); } @@ -362,6 +369,7 @@ protected void mouseClicked(MouseEvent e) ParserNotice pn = notices.get(0); int offs = pn.getOffset(); int len = pn.getLength(); + if (offs > -1 && len > -1) // These values are optional { DocumentRange range = new DocumentRange(offs, offs + len); @@ -370,6 +378,7 @@ protected void mouseClicked(MouseEvent e) else { int line = pn.getLine(); + try { offs = textArea.getLineStartOffset(line); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RSyntaxTextAreaHighlighterEx.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RSyntaxTextAreaHighlighterEx.java index ef0507fe4..ca334a5b2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RSyntaxTextAreaHighlighterEx.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RSyntaxTextAreaHighlighterEx.java @@ -72,6 +72,7 @@ public List getMarkedOccurrences() { int start = info.getStartOffset(); int end = info.getEndOffset() + 1; // HACK + if (start <= end) { // Occasionally a Marked Occurrence can have a lost end offset @@ -116,6 +117,7 @@ public Color getColor() if (notice != null) { color = notice.getColor(); + if (color == null) color = DEFAULT_PARSER_NOTICE_COLOR; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java index b5dc8bb0f..4d0f92555 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/RunOptions.java @@ -111,6 +111,7 @@ public RunOptions() printToCommandLine.setBounds(6, 315, 232, 23); getContentPane().add(printToCommandLine); this.setLocationRelativeTo(null); + btnNewButton.addActionListener(arg0 -> { PluginManager.runPlugin(new EZInjection(accessModifiers.isSelected(), injectHooks.isSelected(), debugMethodCalls.isSelected(), invokeMethod.isSelected(), mainMethodFQN.getText(), false, false, debugClasses.getText(), this.socksProxy.getText(), forceProxy.isSelected(), launchReflectionKit.isSelected(), console.isSelected(), printToCommandLine.isSelected())); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SettingsDialog.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SettingsDialog.java index 9c241546a..fc5828d15 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SettingsDialog.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SettingsDialog.java @@ -49,6 +49,7 @@ public SettingsDialog(JMenu menu, JPanel display) return; List options = new ArrayList<>(); + for (Component child : menu.getMenuComponents()) { if (!(child instanceof JMenuItem)) @@ -83,6 +84,7 @@ public void showDialog() private void buildPanel() { display.setLayout(new BoxLayout(display, BoxLayout.Y_AXIS)); + for (JMenuItem menuItem : options) display.add(menuItem); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/TextAreaSearchPanel.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/TextAreaSearchPanel.java index 15250bff9..b3b9bf647 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/TextAreaSearchPanel.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/TextAreaSearchPanel.java @@ -42,7 +42,9 @@ public class TextAreaSearchPanel extends JPanel public TextAreaSearchPanel(JTextArea textArea) { super(new BorderLayout()); + this.textArea = textArea; + setup(); setVisible(true); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java index 0e14afe15..693ae0e01 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/WaitBusyIcon.java @@ -35,7 +35,9 @@ public class WaitBusyIcon extends JMenuItemIcon public WaitBusyIcon() { super(new RotatableIcon(IconResources.busyIcon)); + animator = new RotatableIconAnimator(8, (RotatableIcon) getIcon(), this); + addHierarchyListener(e -> { if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/actions/GoToAction.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/actions/GoToAction.java index a71f90931..327478cd4 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/actions/GoToAction.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/actions/GoToAction.java @@ -90,6 +90,7 @@ public void actionPerformed(ActionEvent e) if (localMember.line == line && localMember.columnStart - 1 <= column && localMember.columnEnd >= column) { Element root = textArea.getDocument().getDefaultRootElement(); + if (localMember.decRef.equals("declaration")) { int startOffset = root.getElement(localMember.line - 1).getStartOffset() + (localMember.columnStart - 1); @@ -115,6 +116,7 @@ public void actionPerformed(ActionEvent e) if (method.line == line && method.columnStart - 1 <= column && method.columnEnd >= column) { Element root = textArea.getDocument().getDefaultRootElement(); + if (method.decRef.equalsIgnoreCase("declaration")) { int startOffset = root.getElement(method.line - 1).getStartOffset() + (method.columnStart - 1); @@ -131,7 +133,6 @@ public void actionPerformed(ActionEvent e) } }); - open(textArea, false, false, true); } } @@ -144,6 +145,7 @@ public void actionPerformed(ActionEvent e) { name = clazz.owner; Element root = textArea.getDocument().getDefaultRootElement(); + if (clazz.type.equals("declaration")) { int startOffset = root.getElement(clazz.line - 1).getStartOffset() + (clazz.columnStart - 1); @@ -173,6 +175,7 @@ private ClassFileContainer openClass(String lexeme, boolean field, boolean metho return null; ResourceContainer resourceContainer = BytecodeViewer.getFileContainer(container.getParentContainer()); + if (resourceContainer == null) return null; @@ -188,6 +191,7 @@ else if (method) { ClassMethodLocation classMethodLocation = container.getMethodLocationsFor(lexeme).get(0); ClassReferenceLocation classReferenceLocation = null; + try { classReferenceLocation = container.getClassReferenceLocationsFor(classMethodLocation.owner).get(0); @@ -200,10 +204,12 @@ else if (method) return null; String packagePath = classReferenceLocation.packagePath; + if (packagePath.startsWith("java") || packagePath.startsWith("javax") || packagePath.startsWith("com.sun")) return null; String resourceName = packagePath + "/" + classMethodLocation.owner; + if (resourceContainer.resourceClasses.containsKey(resourceName)) { BytecodeViewer.viewer.workPane.addClassResource(resourceContainer, resourceName + ".class"); @@ -216,10 +222,12 @@ else if (method) { ClassReferenceLocation classReferenceLocation = container.getClassReferenceLocationsFor(lexeme).get(0); String packagePath = classReferenceLocation.packagePath; + if (packagePath.startsWith("java") || packagePath.startsWith("javax") || packagePath.startsWith("com.sun")) return null; String resourceName = packagePath + "/" + lexeme; + if (resourceContainer.resourceClasses.containsKey(resourceName)) { BytecodeViewer.viewer.workPane.addClassResource(resourceContainer, resourceName + ".class"); @@ -240,9 +248,11 @@ private void open(RSyntaxTextArea textArea, boolean isClass, boolean isField, bo token = TokenUtil.getToken(textArea, token); String lexeme = token.getLexeme(); ClassFileContainer classFileContainer; + if (isClass) { classFileContainer = openClass(lexeme, false, false); + if (classFileContainer == null) return; @@ -253,9 +263,7 @@ private void open(RSyntaxTextArea textArea, boolean isClass, boolean isField, bo classReference.forEach(classReferenceLocation -> { if (classReferenceLocation.type.equals("declaration")) - { moveCursor(classReferenceLocation.line, classReferenceLocation.columnStart); - } }); } }); @@ -273,9 +281,7 @@ else if (isField) fields.forEach(classFieldLocation -> { if (classFieldLocation.type.equals("declaration")) - { moveCursor(classFieldLocation.line, classFieldLocation.columnStart); - } }); } }); @@ -283,6 +289,7 @@ else if (isField) else if (isMethod) { classFileContainer = openClass(lexeme, false, true); + if (classFileContainer == null) return; @@ -293,14 +300,13 @@ else if (isMethod) methods.forEach(method -> { if (method.decRef.equalsIgnoreCase("declaration")) - { moveCursor(method.line, method.columnStart); - } }); } }); } }, "Open Class"); + thread.start(); } @@ -352,6 +358,7 @@ private void moveCursor(int line, int columnStart) if (caretListener instanceof BytecodeViewPanelUpdater.MarkerCaretListener) { BytecodeViewPanelUpdater.MarkerCaretListener markerCaretListener = (BytecodeViewPanelUpdater.MarkerCaretListener) caretListener; + markerCaretListener.caretUpdate(new CaretEvent(panel.textArea) { @Override diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListIconRenderer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListIconRenderer.java index a0dcf922b..3e361dd3d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListIconRenderer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListIconRenderer.java @@ -63,7 +63,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean boolean iconSet = false; //guess file type based on extension - ResourceType knownResourceType = onlyName.contains(":") ? null : ResourceType.extensionMap.get(FilenameUtils.getExtension(onlyName).toLowerCase()); + ResourceType knownResourceType = onlyName.contains(":") ? null : ResourceType.EXTENSION_MAP.get(FilenameUtils.getExtension(onlyName).toLowerCase()); //set the icon to a known file type if (knownResourceType != null diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchRadius.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchRadius.java index 26f7df5c2..e5c53e679 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchRadius.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchRadius.java @@ -24,5 +24,6 @@ */ public enum SearchRadius { - All_Classes, Current_Class + All_Classes, + Current_Class } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchType.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchType.java index 131fafcd8..b3f7a72e9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchType.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchType.java @@ -27,7 +27,11 @@ */ public enum SearchType { - Strings(new LDCSearch()), Regex(new RegexSearch()), MethodCall(new MethodCallSearch()), FieldCall(new FieldCallSearch()), MemberWithAnnotation(new MemberWithAnnotationSearch()); + Strings(new LDCSearch()), + Regex(new RegexSearch()), + MethodCall(new MethodCallSearch()), + FieldCall(new FieldCallSearch()), + MemberWithAnnotation(new MemberWithAnnotationSearch()); public final SearchPanel panel; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/DecompilerSelectionPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/DecompilerSelectionPane.java index d6a1be7ff..70a8e2537 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/DecompilerSelectionPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/DecompilerSelectionPane.java @@ -107,6 +107,7 @@ public void buildMenu() //build the action commands none.setActionCommand(Decompiler.NONE.name()); hexcode.setActionCommand(Decompiler.HEXCODE_VIEWER.name()); + for (DecompilerViewComponent component : components) { for (Decompiler decompiler : component.getDecompilers()) @@ -123,6 +124,7 @@ public void buildMenu() //auto-save on decompiler change Enumeration it = group.getElements(); + while (it.hasMoreElements()) { AbstractButton button = it.nextElement(); @@ -140,14 +142,18 @@ public void buildMenu() menu.add(new JSeparator()); menu.add(procyon.getMenu()); menu.add(CFR.getMenu()); + if (!Configuration.jadxGroupedWithSmali) menu.add(JADX.getMenu()); + menu.add(JD.getMenu()); menu.add(fern.getMenu()); menu.add(krakatau.getMenu()); menu.add(new JSeparator()); + if (Configuration.jadxGroupedWithSmali) menu.add(JADX.getMenu()); + menu.add(smali.getMenu()); menu.add(new JSeparator()); menu.add(bytecode.getMenu()); @@ -166,6 +172,7 @@ public Decompiler getSelectedDecompiler() public void setSelectedDecompiler(Decompiler decompiler) { Enumeration it = group.getElements(); + while (it.hasMoreElements()) { AbstractButton button = it.nextElement(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabComponent.java index 42d58f7d1..74985a2d2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/TabComponent.java @@ -36,10 +36,9 @@ public class TabComponent extends JPanel public TabComponent(JTabbedPane pane) { super(new FlowLayout(FlowLayout.LEFT, 0, 0)); + if (pane == null) - { throw new NullPointerException("TabbedPane is null"); - } this.pane = pane; @@ -50,9 +49,7 @@ public String getText() { int i = pane.indexOfTabComponent(TabComponent.this); if (i != -1) - { return pane.getTitleAt(i); - } return null; } @@ -102,13 +99,9 @@ public String getText() return; if (pane.indexOfTabComponent(TabComponent.this) != 0) - { removeTab(0); - } else - { removeTab(1); - } } }); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java index 4fe3fdff8..366b8031f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java @@ -82,7 +82,7 @@ public void setContents() // (If none selected, try Pane2, Pane3, default to Procyon) //check by file extension to display image - if (!onlyName.contains(":") && ResourceType.imageExtensionMap.containsKey(FilenameUtils.getExtension(onlyName)) && !hexViewerOnly) + if (!onlyName.contains(":") && ResourceType.IMAGE_EXTENSION_MAP.containsKey(FilenameUtils.getExtension(onlyName)) && !hexViewerOnly) { canRefresh = true; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/AbstractJTabbedPanePopupMenuHandler.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/AbstractJTabbedPanePopupMenuHandler.java index f5340b353..057340220 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/AbstractJTabbedPanePopupMenuHandler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/AbstractJTabbedPanePopupMenuHandler.java @@ -32,6 +32,7 @@ public abstract class AbstractJTabbedPanePopupMenuHandler extends JTabbedPanePop public AbstractJTabbedPanePopupMenuHandler(JTabbedPane tabbedPane) { super(tabbedPane); + registerPopupEventListener(this); } @@ -39,6 +40,7 @@ public AbstractJTabbedPanePopupMenuHandler(JTabbedPane tabbedPane) public void onTabPopupEvent(JTabbedPane tabbedPane, int index, TabPopupEvent e) { JPopupMenu popupMenu = toBuildTabPopupMenu(tabbedPane, e.getPopupOnTab()); + popupTabMenuWithEvent(popupMenu, e); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPaneCloser.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPaneCloser.java index 595d06992..77debc564 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPaneCloser.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPaneCloser.java @@ -84,14 +84,11 @@ public void removeLeftComponents(Component component) do { Component c = this.tabbedPane.getComponentAt(i); + if (c != component) - { removeTabs.add(c); - } else - { break; - } } while (i++ < count); for (Component c : removeTabs) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java index 0e9a1990e..386d1bfbc 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/tabpopup/closer/JTabbedPanePopupMenuTabsCloser.java @@ -54,6 +54,7 @@ public PopupMenuTabsCloseConfiguration getCloseConfiguration() public JPopupMenu toBuildTabPopupMenu(JTabbedPane tabbedPane, Component popupOnTab) { JPopupMenu popUpMenu = new JPopupMenu(); + if (closeConfiguration.isClose()) addItemCloseTab(popUpMenu, popupOnTab); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/MalwareScanModule.java b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/MalwareScanModule.java index 4bd20eafa..64dfe683d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/MalwareScanModule.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/MalwareScanModule.java @@ -23,15 +23,20 @@ import the.bytecode.club.bytecodeviewer.malwarescanner.impl.*; /** - * All of the installed malware scan modules + * All the installed malware scan modules * * @author Konloch * @since 6/27/2021 */ public enum MalwareScanModule { - URL_SCANNER("Scan String URLs", new URLScanner(), true), REFLECTION_SCANNER("Scan Java Reflection", new ReflectionScanner(), false), JAVA_RUNTIME_SCANNER("Scan Java Runtime", new JavaRuntimeScanner(), true), JAVA_NET_SCANNER("Scan Java Net", new JavaNetScanner(), false), JAVA_IO_SCANNER("Scan Java IO", new JavaIOScanner(), false), AWT_ROBOT_SCANNER("Scan AWT Robot", new AWTRobotScanner(), true), NULL_SECURITY_MANAGER("Scan Null SecurityManager", new NullSecurityManagerScanner(), true), - ; + URL_SCANNER("Scan String URLs", new URLScanner(), true), + REFLECTION_SCANNER("Scan Java Reflection", new ReflectionScanner(), false), + JAVA_RUNTIME_SCANNER("Scan Java Runtime", new JavaRuntimeScanner(), true), + JAVA_NET_SCANNER("Scan Java Net", new JavaNetScanner(), false), + JAVA_IO_SCANNER("Scan Java IO", new JavaIOScanner(), false), + AWT_ROBOT_SCANNER("Scan AWT Robot", new AWTRobotScanner(), true), + NULL_SECURITY_MANAGER("Scan Null SecurityManager", new NullSecurityManagerScanner(), true); static { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/AWTRobotScanner.java b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/AWTRobotScanner.java index 1a0f32da4..7e29c982a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/AWTRobotScanner.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/AWTRobotScanner.java @@ -53,6 +53,7 @@ public void scanMethodInstruction(MalwareScan scan, ClassNode cn, MethodNode met if (instruction instanceof MethodInsnNode) { final MethodInsnNode min = (MethodInsnNode) instruction; + if (min.owner.startsWith("java/awt/Robot")) foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaIOScanner.java b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaIOScanner.java index 1b8564c31..88aff7684 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaIOScanner.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaIOScanner.java @@ -47,6 +47,7 @@ public void scanMethodInstruction(MalwareScan scan, ClassNode cn, MethodNode met if (instruction instanceof MethodInsnNode) { final MethodInsnNode min = (MethodInsnNode) instruction; + if (min.owner.startsWith("java/io")) foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaNetScanner.java b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaNetScanner.java index 90ceb0563..bf7954fed 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaNetScanner.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaNetScanner.java @@ -48,6 +48,7 @@ public void scanMethodInstruction(MalwareScan scan, ClassNode cn, MethodNode met if (instruction instanceof MethodInsnNode) { final MethodInsnNode min = (MethodInsnNode) instruction; + if (min.owner.startsWith("java/net")) foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaRuntimeScanner.java b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaRuntimeScanner.java index aa2bef5d6..f96005f10 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaRuntimeScanner.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/JavaRuntimeScanner.java @@ -53,6 +53,7 @@ public void scanMethodInstruction(MalwareScan scan, ClassNode cn, MethodNode met if (instruction instanceof MethodInsnNode) { final MethodInsnNode min = (MethodInsnNode) instruction; + if (min.owner.startsWith("java/lang/Runtime")) foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/NullSecurityManagerScanner.java b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/NullSecurityManagerScanner.java index 931909726..dce482b43 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/NullSecurityManagerScanner.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/NullSecurityManagerScanner.java @@ -57,10 +57,10 @@ public void scanMethodInstruction(MalwareScan scan, ClassNode cn, MethodNode met final String owner = min.owner; final String name = min.name; - if (lastInstruction == OpCode.ACONST_NULL.getCode() && owner.equals("java/lang/System") && name.equals("setSecurityManager")) - { + if (lastInstruction == OpCode.ACONST_NULL.getCode() + && owner.equals("java/lang/System") + && name.equals("setSecurityManager")) found(scan, "Security Manager set to null at method " + methodToString(cn, method) + NL); - } } lastInstruction = instruction.getOpcode(); @@ -70,6 +70,7 @@ public void scanMethodInstruction(MalwareScan scan, ClassNode cn, MethodNode met public void scanningClass(MalwareScan scan, ClassNode cn) { lastInstruction = 0; + super.scanningClass(scan, cn); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/ReflectionScanner.java b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/ReflectionScanner.java index 6a84c9caa..abe7d5b11 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/ReflectionScanner.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/malwarescanner/impl/ReflectionScanner.java @@ -50,6 +50,7 @@ public void scanMethodInstruction(MalwareScan scan, ClassNode cn, MethodNode met if (instruction instanceof MethodInsnNode) { final MethodInsnNode min = (MethodInsnNode) instruction; + if (min.owner.startsWith("java/lang/reflect")) foundMethod(scan, instructionToString(instruction) + " at " + methodToString(cn, method) + NL); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java index 40239d6ab..f11844ebb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java @@ -34,12 +34,18 @@ public abstract class JavaObfuscator extends Thread { + public static int MAX_STRING_LENGTH = 25; + public static int MIN_STRING_LENGTH = 5; + private final List names = new ArrayList<>(); + @Override public void run() { BytecodeViewer.updateBusyStatus(true); Configuration.runningObfuscation = true; + obfuscate(); + BytecodeViewer.refactorer.run(); Configuration.runningObfuscation = false; BytecodeViewer.updateBusyStatus(false); @@ -48,24 +54,16 @@ public void run() public int getStringLength() { if (BytecodeViewer.viewer.obfuscatorGroup.isSelected(BytecodeViewer.viewer.strongObf.getModel())) - { return MAX_STRING_LENGTH; - } - else - { // if(BytecodeViewer.viewer.obfuscatorGroup.isSelected(BytecodeViewer.viewer.lightObf.getModel())) - // { + else // if(BytecodeViewer.viewer.obfuscatorGroup.isSelected(BytecodeViewer.viewer.lightObf.getModel())) return MIN_STRING_LENGTH; - } } - public static int MAX_STRING_LENGTH = 25; - public static int MIN_STRING_LENGTH = 5; - private final List names = new ArrayList<>(); - protected String generateUniqueName(int length) { boolean found = false; String name = ""; + while (!found) { String nameTry = MiscUtils.randomString(1) + MiscUtils.randomStringNum(length - 1); @@ -79,6 +77,7 @@ protected String generateUniqueName(int length) found = true; } } + return name; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java index 56a923e4b..e5e42228a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java @@ -37,6 +37,7 @@ public void obfuscate() int stringLength = getStringLength(); System.out.println("Obfuscating class names..."); + for (ClassNode c : BytecodeViewer.getLoadedClasses()) { String newName = generateUniqueName(stringLength); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java index be8e982a2..148839fe0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java @@ -38,6 +38,7 @@ public void obfuscate() int stringLength = getStringLength(); System.out.println("Obfuscating fields names..."); + for (ClassNode c : BytecodeViewer.getLoadedClasses()) { for (Object o : c.fields.toArray()) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java index b01574e9d..e3c62936e 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java @@ -39,6 +39,7 @@ public void obfuscate() int stringLength = getStringLength(); System.out.println("Obfuscating method names..."); + for (ClassNode c : BytecodeViewer.getLoadedClasses()) { for (Object o : c.methods.toArray()) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java index 8ed71ddce..a6feb712f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java @@ -47,6 +47,7 @@ public RefactorMapper(HookMap hookMap) sortedFields = new HashMap<>(); mappingList = new ArrayList<>(); builder = new StringBuilder(); + for (MappingData hook : hookMap.getClasses()) { if (hook.getObfuscatedName().contains("$")) @@ -56,6 +57,7 @@ public RefactorMapper(HookMap hookMap) sortedClasses.put(obfuscatedName, hook); sortedClasses.put(refactoredName, hook); } + for (MethodMappingData hook : hookMap.getMethods()) { String obfuscatedName = hook.getMethodName().getObfuscatedName(); @@ -63,6 +65,7 @@ public RefactorMapper(HookMap hookMap) String obfuscatedCname = hook.getMethodOwner(); sortedMethods.put(obfuscatedCname + "$$$$" + obfuscatedName + "$$$$" + obfuscatedDesc, hook); } + for (FieldMappingData hook : hookMap.getFields()) { String obfuscatedName = hook.getName().getObfuscatedName(); @@ -83,6 +86,7 @@ public String map(String type) return sortedClasses.get(type).getRefactoredName(); } + return type; } @@ -90,6 +94,7 @@ public String map(String type) public String mapFieldName(String owner, String name, String desc) { String obfKey = owner + "$$$$" + name + "$$$$" + desc; + if (sortedFields.containsKey(obfKey)) { String map = owner + "." + name + " --> " + owner + sortedFields.get(obfKey).getName().getRefactoredName() + "\n"; @@ -97,6 +102,7 @@ public String mapFieldName(String owner, String name, String desc) mappingList.add(map); name = sortedFields.get(obfKey).getName().getRefactoredName(); } + return name; } @@ -104,6 +110,7 @@ public String mapFieldName(String owner, String name, String desc) public String mapMethodName(String owner, String name, String desc) { String obfKey = owner + "$$$$" + name + "$$$$" + desc; + if (sortedMethods.containsKey(obfKey)) { String map = owner + "." + name + " --> " + owner + sortedMethods.get(obfKey).getMethodName().getRefactoredName() + "\n"; @@ -111,6 +118,7 @@ public String mapMethodName(String owner, String name, String desc) mappingList.add(map); name = sortedMethods.get(obfKey).getMethodName().getRefactoredName(); } + return name; } @@ -120,6 +128,7 @@ public void printMap() { builder.append(map); } + System.out.println(builder.toString()); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java index 7c8935644..3a4d9b91b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java @@ -60,9 +60,11 @@ public void run() cr.accept(cn, 0); //refactored.put(oldName, cn); } + /*for (Map.Entry factor : refactored.entrySet()) { BytecodeViewer.relocate(factor.getKey(), factor.getValue()); }*/ + mapper.printMap(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java index 510bb0d90..cf01e028c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java @@ -56,22 +56,26 @@ public abstract class Remapper extends org.objectweb.asm.commons.Remapper public String mapDesc(String desc) { Type t = Type.getType(desc); + switch (t.getSort()) { case Type.ARRAY: StringBuilder s = new StringBuilder(mapDesc(t.getElementType().getDescriptor())); + for (int i = 0; i < t.getDimensions(); ++i) { s.insert(0, '['); } + return s.toString(); + case Type.OBJECT: String newType = map(t.getInternalName()); + if (newType != null) - { return 'L' + newType + ';'; - } } + return desc; } @@ -81,17 +85,22 @@ private Type mapType(Type t) { case Type.ARRAY: StringBuilder s = new StringBuilder(mapDesc(t.getElementType().getDescriptor())); + for (int i = 0; i < t.getDimensions(); ++i) { s.insert(0, '['); } + return Type.getType(s.toString()); + case Type.OBJECT: s = new StringBuilder(map(t.getInternalName())); return Type.getObjectType(s.toString()); + case Type.METHOD: return Type.getMethodType(mapMethodDesc(t.getDescriptor())); } + return t; } @@ -99,9 +108,8 @@ private Type mapType(Type t) public String mapType(String type) { if (type == null) - { return null; - } + return mapType(Type.getObjectType(type)).getInternalName(); } @@ -110,24 +118,26 @@ public String[] mapTypes(String[] types) { String[] newTypes = null; boolean needMapping = false; + for (int i = 0; i < types.length; i++) { String type = types[i]; String newType = map(type); + if (newType != null && newTypes == null) { newTypes = new String[types.length]; + if (i > 0) - { System.arraycopy(types, 0, newTypes, 0, i); - } + needMapping = true; } + if (needMapping) - { newTypes[i] = newType == null ? type : newType; - } } + return needMapping ? newTypes : types; } @@ -135,22 +145,24 @@ public String[] mapTypes(String[] types) public String mapMethodDesc(String desc) { if ("()V".equals(desc)) - { return desc; - } Type[] args = Type.getArgumentTypes(desc); StringBuilder sb = new StringBuilder("("); + for (Type arg : args) { sb.append(mapDesc(arg.getDescriptor())); } + Type returnType = Type.getReturnType(desc); + if (returnType == Type.VOID_TYPE) { sb.append(")V"); return sb.toString(); } + sb.append(')').append(mapDesc(returnType.getDescriptor())); return sb.toString(); } @@ -159,14 +171,14 @@ public String mapMethodDesc(String desc) public Object mapValue(Object value) { if (value instanceof Type) - { return mapType((Type) value); - } + if (value instanceof Handle) { Handle h = (Handle) value; return new Handle(h.getTag(), mapType(h.getOwner()), mapMethodName(h.getOwner(), h.getName(), h.getDesc()), mapMethodDesc(h.getDesc()), h.getTag() == Opcodes.H_INVOKEINTERFACE); } + return value; } @@ -179,20 +191,17 @@ public Object mapValue(Object value) public String mapSignature(String signature, boolean typeSignature) { if (signature == null) - { return null; - } + SignatureReader r = new SignatureReader(signature); SignatureWriter w = new SignatureWriter(); SignatureVisitor a = createSignatureRemapper(w); + if (typeSignature) - { r.acceptType(a); - } else - { r.accept(a); - } + return w.toString(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingMethodAdapter.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingMethodAdapter.java index 8a20dde5f..f08ea1231 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingMethodAdapter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingMethodAdapter.java @@ -106,9 +106,11 @@ private Object[] remapEntries(int n, Object[] entries) Object t = entries[i]; newEntries[i++] = t instanceof String ? remapper.mapType((String) t) : t; } while (i < n); + return newEntries; } } + return entries; } @@ -127,6 +129,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc) super.visitMethodInsn(opcode, owner, name, desc); return; } + doVisitMethodInsn(opcode, owner, name, desc, opcode == Opcodes.INVOKEINTERFACE); } @@ -138,6 +141,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc, super.visitMethodInsn(opcode, owner, name, desc, itf); return; } + doVisitMethodInsn(opcode, owner, name, desc, itf); } @@ -150,9 +154,7 @@ private void doVisitMethodInsn(int opcode, String owner, String name, String des // IMPORTANT: THIS ASSUMES THAT visitMethodInsn IS NOT OVERRIDDEN IN // LocalVariableSorter. if (mv != null) - { mv.visitMethodInsn(opcode, remapper.mapType(owner), remapper.mapMethodName(owner, name, desc), remapper.mapMethodDesc(desc), itf); - } } @Override @@ -162,6 +164,7 @@ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object. { bsmArgs[i] = remapper.mapValue(bsmArgs[i]); } + super.visitInvokeDynamicInsn(remapper.mapInvokeDynamicMethodName(name, desc), remapper.mapMethodDesc(desc), (Handle) remapper.mapValue(bsm), bsmArgs); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/FieldMappingData.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/FieldMappingData.java index ffec29399..717218684 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/FieldMappingData.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/FieldMappingData.java @@ -90,7 +90,9 @@ public boolean equals(Object obj) return false; if (getClass() != obj.getClass()) return false; + FieldMappingData other = (FieldMappingData) obj; + if (desc == null) { if (other.desc != null) @@ -98,6 +100,7 @@ public boolean equals(Object obj) } else if (!desc.equals(other.desc)) return false; + if (fieldOwner == null) { if (other.fieldOwner != null) @@ -105,10 +108,9 @@ else if (!desc.equals(other.desc)) } else if (!fieldOwner.equals(other.fieldOwner)) return false; + if (name == null) - { return other.name == null; - } else return name.equals(other.name); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MappingData.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MappingData.java index e0db408f2..cd3487012 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MappingData.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MappingData.java @@ -76,7 +76,9 @@ public boolean equals(Object obj) return false; if (getClass() != obj.getClass()) return false; + MappingData other = (MappingData) obj; + if (obfuscatedName == null) { if (other.obfuscatedName != null) @@ -84,10 +86,9 @@ public boolean equals(Object obj) } else if (!obfuscatedName.equals(other.obfuscatedName)) return false; + if (refactoredName == null) - { return other.refactoredName == null; - } else return refactoredName.equals(other.refactoredName); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MethodMappingData.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MethodMappingData.java index 2833f6d3e..1e3cb37b5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MethodMappingData.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MethodMappingData.java @@ -90,7 +90,9 @@ public boolean equals(Object obj) return false; if (getClass() != obj.getClass()) return false; + MethodMappingData other = (MethodMappingData) obj; + if (methodDesc == null) { if (other.methodDesc != null) @@ -98,6 +100,7 @@ public boolean equals(Object obj) } else if (!methodDesc.equals(other.methodDesc)) return false; + if (methodName == null) { if (other.methodName != null) @@ -105,10 +108,9 @@ else if (!methodDesc.equals(other.methodDesc)) } else if (!methodName.equals(other.methodName)) return false; + if (methodOwner == null) - { return other.methodOwner == null; - } else return methodOwner.equals(other.methodOwner); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java index 4e32c42ee..ef538d62a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java @@ -42,7 +42,9 @@ public static void open() BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" + "."); return; } + new RenameClasses().start(); + BytecodeViewer.viewer.workPane.refreshClass.doClick(); BytecodeViewer.viewer.resourcePane.tree.updateUI(); } @@ -61,7 +63,8 @@ public void obfuscate() for (MethodNode o : c.methods) { /* As we dont want to rename any main-classes */ - if (o.name.equals("main") && o.desc.equals("([Ljava/lang/String;)V") || o.name.equals("init") && c.superName.equals("java/applet/Applet")) + if (o.name.equals("main") && o.desc.equals("([Ljava/lang/String;)V") + || o.name.equals("init") && c.superName.equals("java/applet/Applet")) continue classLoop; /* As we dont want to rename native dll methods */ diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java index bc85f8758..a374d16d1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java @@ -42,7 +42,9 @@ public static void open() BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish."); return; } + new RenameFields().start(); + BytecodeViewer.viewer.workPane.refreshClass.doClick(); BytecodeViewer.viewer.resourcePane.tree.updateUI(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java index d290e986f..c08643c9f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java @@ -43,7 +43,9 @@ public static void open() BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish" + "."); return; } + new RenameMethods().start(); + BytecodeViewer.viewer.workPane.refreshClass.doClick(); BytecodeViewer.viewer.resourcePane.tree.updateUI(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java index c5ebadd8d..935255441 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/AllatoriStringDecrypter.java @@ -219,14 +219,13 @@ private boolean scanDecrypter(MethodNode decryptermethodnode, int newHashCode) if (i instanceof MethodInsnNode) { MethodInsnNode methodi = ((MethodInsnNode) i); + if ("currentThread".equals(methodi.name)) // find code form this instruction { insn = i; break; } - } - } if (insn == null) @@ -241,6 +240,7 @@ private boolean scanDecrypter(MethodNode decryptermethodnode, int newHashCode) if ("hashCode".equals(methodi.name)) // to this instruction break; } + removeInsn = insn; insn = insn.getNext(); iList.remove(removeInsn); // and remove it diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java index 44629fb9f..29634f919 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java @@ -75,6 +75,7 @@ public void scanClassNode(ClassNode classNode) if (v instanceof String) { String s = (String) v; + if (contains) { if (s.contains(originalLDC)) @@ -92,6 +93,7 @@ public void scanClassNode(ClassNode classNode) for (int i = 0; i < ((String[]) v).length; i++) { String s = ((String[]) v)[i]; + if (contains) { if (s.contains(originalLDC)) @@ -118,6 +120,7 @@ public void scanClassNode(ClassNode classNode) { MethodNode m = (MethodNode) o; InsnList iList = m.instructions; + for (AbstractInsnNode a : iList.toArray()) { if (a instanceof LdcInsnNode) @@ -125,6 +128,7 @@ public void scanClassNode(ClassNode classNode) if (((LdcInsnNode) a).cst instanceof String) { final String s = (String) ((LdcInsnNode) a).cst; + if (contains) { if (s.contains(originalLDC)) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java index 96dbe6f6b..726e5a5ef 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewAPKAndroidPermissions.java @@ -38,6 +38,7 @@ public void execute(List classNodeList) frame.setVisible(true); byte[] encodedAndroidManifest = activeContainer.getFileContents("AndroidManifest.xml"); + if (encodedAndroidManifest == null) { frame.appendText("This plugin only works on valid Android APKs"); @@ -45,6 +46,7 @@ public void execute(List classNodeList) } byte[] decodedAndroidManifest = activeContainer.getFileContents("Decoded Resources/AndroidManifest.xml"); + if (decodedAndroidManifest != null) { String manifest = new String(decodedAndroidManifest, StandardCharsets.UTF_8); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java index b323a856c..b0c751895 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ViewManifest.java @@ -39,6 +39,7 @@ public void execute(List classNodeList) //TODO android APKs may have AndroidManifests that can be viewed normally, this should be checked byte[] encodedAndroidManifest = activeContainer.getFileContents("AndroidManifest.xml"); + if (encodedAndroidManifest != null) { frame.appendText("Android APK Manifest:\r"); @@ -50,6 +51,7 @@ public void execute(List classNodeList) } byte[] jarManifest = activeContainer.getFileContents("META-INF/MANIFEST.MF"); + if (jarManifest != null) { if (!frame.getTextArea().getText().isEmpty()) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java index a91e94c7d..4094b0552 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java @@ -52,11 +52,13 @@ public void execute(List classNodeList) if (dialog.promptChoice() == 0) { boolean needsWarning = false; + for (Class cn : Objects.requireNonNull(BCV.loadClassesIntoClassLoader())) { try { Field[] fields = cn.getDeclaredFields(); + for (Field field : fields) { if (field.getName().equals("z")) @@ -81,9 +83,8 @@ public void execute(List classNodeList) } if (needsWarning) - { - BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them" + NL + "makes sure you include ALL the libraries it requires."); - } + BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them" + + NL + "makes sure you include ALL the libraries it requires."); gui.setText(out.toString()); gui.setVisible(true); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/strategies/CompiledJavaPluginLaunchStrategy.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/strategies/CompiledJavaPluginLaunchStrategy.java index 35ce7a001..397c4b427 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/strategies/CompiledJavaPluginLaunchStrategy.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/strategies/CompiledJavaPluginLaunchStrategy.java @@ -56,13 +56,9 @@ public Plugin run(File file) throws Throwable if (Objects.equals(cn.superName, PLUGIN_CLASS_NAME)) { if (pdata == null) - { pdata = d; - } else - { throw new RuntimeException("Multiple plugin subclasses."); - } } } @@ -92,9 +88,11 @@ private static Set loadData(File jarFile) throws Throwable try { String name = entry.getName(); + if (name.endsWith(".class")) { byte[] bytes = MiscUtils.getBytes(jis); + if (FileHeaderUtils.doesFileHeaderMatch(bytes, FileHeaderUtils.JAVA_CLASS_FILE_HEADER)) { try @@ -174,20 +172,20 @@ public Plugin getPlugin() public static class LoadingClassLoader extends ClassLoader { private final LoadedNodeData data; - private final Map cache; - private final Map> ccache; + private final Map nodeCache; + private final Map> classCache; private final Class pluginKlass; public LoadingClassLoader(LoadedNodeData data, Set set) throws Throwable { this.data = data; - cache = new HashMap<>(); - ccache = new HashMap<>(); + nodeCache = new HashMap<>(); + classCache = new HashMap<>(); for (LoadedNodeData d : set) { - cache.put(d.node.name, d); + nodeCache.put(d.node.name, d); } @SuppressWarnings("unchecked") Class pluginKlass = (Class) loadClass(data.node.name.replace("/", ".")); @@ -205,15 +203,16 @@ public Class findClass(String name) throws ClassNotFoundException System.out.println("finding " + name); - if (ccache.containsKey(name)) - return ccache.get(name); + if (classCache.containsKey(name)) + return classCache.get(name); + + LoadedNodeData data = nodeCache.get(name); - LoadedNodeData data = cache.get(name); if (data != null) { byte[] bytes = data.bytes; Class klass = defineClass(data.node.name.replace("/", "."), bytes, 0, bytes.length); - ccache.put(name, klass); + classCache.put(name, klass); return klass; } 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 f44cdc2af..e10044ad1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java @@ -70,7 +70,8 @@ public static void decompileSaveAll() if (!BytecodeViewer.autoCompileSuccessful()) return; - final JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(), "Select Zip Export", "Zip Archives", "zip"); + final JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(), + "Select Zip Export", "Zip Archives", "zip"); //if the user doesn't select a file then we should stop while we're ahead if (fc.showSaveDialog(BytecodeViewer.viewer) != JFileChooser.APPROVE_OPTION) @@ -87,7 +88,8 @@ public static void decompileSaveAll() return; //this temporary jar file will be used to store the classes while BCV performs decompilation - File temporaryTargetJar = MiscUtils.deleteExistingFile(new File(TEMP_DIRECTORY + FS + "temp_" + MiscUtils.getRandomizedName() + ".jar")); + File temporaryTargetJar = MiscUtils.deleteExistingFile(new File(TEMP_DIRECTORY + FS + + "temp_" + MiscUtils.getRandomizedName() + ".jar")); //extract all the loaded classes imported into BCV to the temporary target jar JarUtils.saveAsJarClassesOnly(BytecodeViewer.getLoadedClasses(), temporaryTargetJar.getAbsolutePath()); @@ -254,7 +256,8 @@ public static void decompileSaveAll(Decompiler decompiler, File targetJar, File BytecodeViewer.updateBusyStatus(true); //decompile all opened classes to zip - decompiler.getDecompiler().decompileToZip(targetJar.getAbsolutePath(), saveAll ? MiscUtils.append(outputZip, "-" + decompiler.getDecompilerNameProgrammic() + ".zip") : outputZip.getAbsolutePath()); + decompiler.getDecompiler().decompileToZip(targetJar.getAbsolutePath(), saveAll ? MiscUtils.append(outputZip, + "-" + decompiler.getDecompilerNameProgrammic() + ".zip") : outputZip.getAbsolutePath()); //signal to the user that BCV is finished performing that action BytecodeViewer.updateBusyStatus(false); @@ -266,7 +269,8 @@ public static void decompileCurrentlyOpenedResource(Decompiler decompiler, File BytecodeViewer.updateBusyStatus(true); //decompile the currently opened resource and save it to the specified file - DiskWriter.replaceFile(saveAll ? MiscUtils.append(outputFile, "-" + decompiler.getDecompilerNameProgrammic() + ".java") : outputFile.getAbsolutePath(), BCV.decompileCurrentlyOpenedClassNode(decompiler), false); + DiskWriter.replaceFile(saveAll ? MiscUtils.append(outputFile, + "-" + decompiler.getDecompilerNameProgrammic() + ".java") : outputFile.getAbsolutePath(), BCV.decompileCurrentlyOpenedClassNode(decompiler), false); //signal to the user that BCV is finished performing that action BytecodeViewer.updateBusyStatus(false); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java index 89918667c..441484c50 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java @@ -38,18 +38,18 @@ public enum ResourceType ZIP_ARCHIVE(IconResources.zipIcon, "zip"), ANDROID_ARCHIVE(IconResources.androidIcon, "apk", "wapk", "dex", "xapk"), IMAGE_FILE(IconResources.imageIcon, "png", "jpg", "jpeg", "bmp", "wbmp", "gif", "tif", "webp"), - CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config", "csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess", "plugin", "attachprovider", "transportservice", "connector"), + CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config", "csv", "yml", "yaml", "ini", + "json", "sql", "gradle", "dockerfile", "htaccess", "plugin", "attachprovider", "transportservice", "connector"), JAVA_FILE(IconResources.javaIcon, "java"), TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"), CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"), CSHARP_FILE(IconResources.csharpIcon, "cs"), BAT_FILE(IconResources.batIcon, "bat", "batch"), - SH_FILE(IconResources.shIcon, "sh", "bash"), - ; + SH_FILE(IconResources.shIcon, "sh", "bash"); - public static final Map extensionMap = new HashMap<>(); - public static final Map imageExtensionMap = new HashMap<>(); - public static final Map supportedBCVExtensionMap = new HashMap<>(); + public static final Map EXTENSION_MAP = new HashMap<>(); + public static final Map IMAGE_EXTENSION_MAP = new HashMap<>(); + public static final Map SUPPORTED_BCV_EXTENSION_MAP = new HashMap<>(); private final Icon icon; private final String[] extensions; @@ -60,21 +60,21 @@ public enum ResourceType //add all extensions for (ResourceType t : values()) for (String extension : t.extensions) - extensionMap.put(extension, t); + EXTENSION_MAP.put(extension, t); //add image extensions for (String extension : IMAGE_FILE.extensions) - imageExtensionMap.put(extension, IMAGE_FILE); + IMAGE_EXTENSION_MAP.put(extension, IMAGE_FILE); //add extensions BCV can be opened with for (String extension : CLASS_FILE.extensions) - supportedBCVExtensionMap.put(extension, CLASS_FILE); + SUPPORTED_BCV_EXTENSION_MAP.put(extension, CLASS_FILE); for (String extension : JAVA_ARCHIVE.extensions) - supportedBCVExtensionMap.put(extension, JAVA_ARCHIVE); + SUPPORTED_BCV_EXTENSION_MAP.put(extension, JAVA_ARCHIVE); for (String extension : ZIP_ARCHIVE.extensions) - supportedBCVExtensionMap.put(extension, ZIP_ARCHIVE); + SUPPORTED_BCV_EXTENSION_MAP.put(extension, ZIP_ARCHIVE); for (String extension : ANDROID_ARCHIVE.extensions) - supportedBCVExtensionMap.put(extension, ANDROID_ARCHIVE); + SUPPORTED_BCV_EXTENSION_MAP.put(extension, ANDROID_ARCHIVE); } ResourceType(Icon icon, String... extensions) 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 5f9e64fed..5f9c7c9cf 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -64,7 +64,8 @@ public static void importArchiveA(File jarFile) throws IOException ResourceContainer container = new ResourceContainer(jarFile); Map files = new LinkedHashMap<>(); - try (FileInputStream fis = new FileInputStream(jarFile); ZipInputStream jis = new ZipInputStream(fis)) + try (FileInputStream fis = new FileInputStream(jarFile); + ZipInputStream jis = new ZipInputStream(fis)) { ZipEntry entry; while ((entry = jis.getNextEntry()) != null) @@ -184,7 +185,8 @@ public static void importArchiveB(File jarFile) throws IOException public static List loadClasses(File jarFile) throws IOException { List classes = new ArrayList<>(); - try (FileInputStream fis = new FileInputStream(jarFile); ZipInputStream jis = new ZipInputStream(fis)) + try (FileInputStream fis = new FileInputStream(jarFile); + ZipInputStream jis = new ZipInputStream(fis)) { ZipEntry entry; while ((entry = jis.getNextEntry()) != null) @@ -405,7 +407,8 @@ public static void saveAsJarClassesOnlyToDir(List nodeList, String di */ public static void saveAsJar(List nodeList, String path) { - try (FileOutputStream fos = new FileOutputStream(path); JarOutputStream out = new JarOutputStream(fos)) + try (FileOutputStream fos = new FileOutputStream(path); + JarOutputStream out = new JarOutputStream(fos)) { List noDupe = new ArrayList<>(); for (ClassNode cn : nodeList) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java index 992482dc1..d171785f7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java @@ -56,8 +56,10 @@ public class MiscUtils public static String randomString(int len) { StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) sb.append(AB.charAt(RND.nextInt(AB.length()))); + return sb.toString(); } @@ -70,9 +72,11 @@ public static String getRandomizedName() { boolean generated = false; String name = ""; + while (!generated) { String randomizedName = MiscUtils.randomString(25); + if (!CREATED_RANDOMIZED_NAMES.contains(randomizedName)) { CREATED_RANDOMIZED_NAMES.add(randomizedName); @@ -80,6 +84,7 @@ public static String getRandomizedName() generated = true; } } + return name; } @@ -87,7 +92,8 @@ public static void printProcess(Process process) throws Exception { //Read out dir output try (InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr)) { String line; while ((line = br.readLine()) != null) @@ -117,8 +123,10 @@ public static void printProcess(Process process) throws Exception public static String randomStringNum(int len) { StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) sb.append(AN.charAt(RND.nextInt(AN.length()))); + return sb.toString(); } @@ -135,10 +143,12 @@ public static String getUniqueName(String start, String ext) boolean b = true; File f; String m; + while (b) { m = MiscUtils.randomString(32); f = new File(start + m + ext); + if (!f.exists()) { s = start + m; @@ -159,14 +169,17 @@ public static int getClassNumber(String start, String ext) { boolean b = true; int i = 0; + while (b) { File tempF = new File(start + i + ext); + if (!tempF.exists()) b = false; else i++; } + return i; } @@ -186,14 +199,17 @@ public static String extension(String name) public static String append(File file, String extension) { String path = file.getAbsolutePath(); + if (!path.endsWith(extension)) path += extension; + return path; } public static int fileContainersHash(List resourceContainers) { StringBuilder block = new StringBuilder(); + for (ResourceContainer container : resourceContainers) { block.append(container.name); @@ -246,6 +262,7 @@ public static BufferedImage loadImage(BufferedImage defaultImage, byte[] content public static void deduplicateAndTrim(List list, int maxLength) { List temporaryList = new ArrayList<>(); + for (String s : list) if (!s.isEmpty() && !temporaryList.contains(s)) temporaryList.add(s); @@ -265,6 +282,7 @@ public static boolean guessIfBinary(byte[] data) { double ascii = 0; double other = 0; + for (byte b : data) { if (b == 0x09 || b == 0x0A || b == 0x0C || b == 0x0D || (b >= 0x20 && b <= 0x7E)) @@ -272,6 +290,7 @@ public static boolean guessIfBinary(byte[] data) else other++; } + return other != 0 && other / (ascii + other) > 0.25; } @@ -345,9 +364,9 @@ public static byte[] getBytes(InputStream is) throws IOException { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - byte[] buffer = new byte[1024]; int a; + while ((a = is.read(buffer)) != -1) baos.write(buffer, 0, a); @@ -359,9 +378,11 @@ public static File[] listFiles(File file) { if (file == null) return new File[0]; + File[] list = file.listFiles(); if (list != null) return list; + return new File[0]; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/NewlineOutputStream.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/NewlineOutputStream.java index 54c865561..30e688b08 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/NewlineOutputStream.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/NewlineOutputStream.java @@ -41,11 +41,14 @@ public class NewlineOutputStream extends FilterOutputStream public NewlineOutputStream(OutputStream os) { super(os); + if (newline == null) { String s = Constants.NL; + if (s == null || s.length() <= 0) s = "\n"; + newline = s.getBytes(StandardCharsets.ISO_8859_1); // really us-ascii } } @@ -66,6 +69,7 @@ else if (b == '\n') { out.write(b); } + lastByte = b; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/SyntaxLanguage.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/SyntaxLanguage.java index f962c705b..71c9f46f3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/SyntaxLanguage.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/SyntaxLanguage.java @@ -33,7 +33,37 @@ public enum SyntaxLanguage XML(SyntaxConstants.SYNTAX_STYLE_XML, (n, c) -> n.endsWith(".xml") || c.startsWith(" n.endsWith(".py") || n.endsWith(".python")), RUBY(SyntaxConstants.SYNTAX_STYLE_RUBY, (n, c) -> n.endsWith(".rb") || n.endsWith(".ruby")), - JAVA(SyntaxConstants.SYNTAX_STYLE_JAVA, (n, c) -> n.endsWith(".java")), HTML(SyntaxConstants.SYNTAX_STYLE_HTML, (n, c) -> n.endsWith(".html")), CSS(SyntaxConstants.SYNTAX_STYLE_CSS, (n, c) -> n.endsWith(".css")), PROPERTIES(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE, (n, c) -> n.endsWith(".properties") || n.endsWith(".mf") || n.endsWith(".sf") || n.endsWith(".plugin") || n.endsWith(".attachprovider") || n.endsWith(".transportservice") || n.endsWith(".connector")), PHP(SyntaxConstants.SYNTAX_STYLE_PHP, (n, c) -> n.endsWith(".php") || c.startsWith(" n.endsWith(".js")), BATCH(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH, (n, c) -> n.endsWith(".bat")), SHELL(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL, (n, c) -> n.endsWith(".sh")), C(SyntaxConstants.SYNTAX_STYLE_C, (n, c) -> n.endsWith(".c") || n.endsWith(".h")), CPP(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS, (n, c) -> n.endsWith(".cpp") || n.endsWith(".hpp")), SCALA(SyntaxConstants.SYNTAX_STYLE_SCALA, (n, c) -> n.endsWith(".scala")), CLOJURE(SyntaxConstants.SYNTAX_STYLE_CLOJURE, (n, c) -> n.endsWith(".clojure")), GROOVY(SyntaxConstants.SYNTAX_STYLE_GROOVY, (n, c) -> n.endsWith(".groovy") || n.endsWith(".gradle")), LUA(SyntaxConstants.SYNTAX_STYLE_LUA, (n, c) -> n.endsWith(".lua")), SQL(SyntaxConstants.SYNTAX_STYLE_SQL, (n, c) -> n.endsWith(".sql")), JSON(SyntaxConstants.SYNTAX_STYLE_JSON, (n, c) -> n.endsWith(".json")), JSP(SyntaxConstants.SYNTAX_STYLE_JSP, (n, c) -> n.endsWith(".jsp")), YAML(SyntaxConstants.SYNTAX_STYLE_YAML, (n, c) -> n.endsWith(".yml") || n.endsWith(".yaml")), CS(SyntaxConstants.SYNTAX_STYLE_CSHARP, (n, c) -> n.endsWith(".cs")), CSV(SyntaxConstants.SYNTAX_STYLE_CSV, (n, c) -> n.endsWith(".csv")), DOCKER(SyntaxConstants.SYNTAX_STYLE_DOCKERFILE, (n, c) -> n.endsWith(".dockerfile")), DART(SyntaxConstants.SYNTAX_STYLE_DART, (n, c) -> n.endsWith(".dart")), GO(SyntaxConstants.SYNTAX_STYLE_GO, (n, c) -> n.endsWith(".go")), HTACCESS(SyntaxConstants.SYNTAX_STYLE_HTACCESS, (n, c) -> n.endsWith(".htaccess")), INI(SyntaxConstants.SYNTAX_STYLE_INI, (n, c) -> n.endsWith(".ini")), KOTLIN(SyntaxConstants.SYNTAX_STYLE_KOTLIN, (n, c) -> n.endsWith(".kt") || n.endsWith(".kts")), LATEX(SyntaxConstants.SYNTAX_STYLE_LATEX, (n, c) -> n.endsWith(".tex")), MARKDOWN(SyntaxConstants.SYNTAX_STYLE_MARKDOWN, (n, c) -> n.endsWith(".md")), PERL(SyntaxConstants.SYNTAX_STYLE_PERL, (n, c) -> n.endsWith(".pl")), TYPESCRIPT(SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT, (n, c) -> n.endsWith(".ts")), NONE(SyntaxConstants.SYNTAX_STYLE_NONE, (n, c) -> false); + JAVA(SyntaxConstants.SYNTAX_STYLE_JAVA, (n, c) -> n.endsWith(".java")), + HTML(SyntaxConstants.SYNTAX_STYLE_HTML, (n, c) -> n.endsWith(".html")), + CSS(SyntaxConstants.SYNTAX_STYLE_CSS, (n, c) -> n.endsWith(".css")), + PROPERTIES(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE, (n, c) -> n.endsWith(".properties") || n.endsWith(".mf") || n.endsWith(".sf") || n.endsWith(".plugin") || n.endsWith(".attachprovider") || n.endsWith(".transportservice") || n.endsWith(".connector")), + PHP(SyntaxConstants.SYNTAX_STYLE_PHP, (n, c) -> n.endsWith(".php") || c.startsWith(" n.endsWith(".js")), + BATCH(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH, (n, c) -> n.endsWith(".bat")), + SHELL(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL, (n, c) -> n.endsWith(".sh")), + C(SyntaxConstants.SYNTAX_STYLE_C, (n, c) -> n.endsWith(".c") || n.endsWith(".h")), + CPP(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS, (n, c) -> n.endsWith(".cpp") || n.endsWith(".hpp")), + SCALA(SyntaxConstants.SYNTAX_STYLE_SCALA, (n, c) -> n.endsWith(".scala")), + CLOJURE(SyntaxConstants.SYNTAX_STYLE_CLOJURE, (n, c) -> n.endsWith(".clojure")), + GROOVY(SyntaxConstants.SYNTAX_STYLE_GROOVY, (n, c) -> n.endsWith(".groovy") || n.endsWith(".gradle")), + LUA(SyntaxConstants.SYNTAX_STYLE_LUA, (n, c) -> n.endsWith(".lua")), + SQL(SyntaxConstants.SYNTAX_STYLE_SQL, (n, c) -> n.endsWith(".sql")), + JSON(SyntaxConstants.SYNTAX_STYLE_JSON, (n, c) -> n.endsWith(".json")), + JSP(SyntaxConstants.SYNTAX_STYLE_JSP, (n, c) -> n.endsWith(".jsp")), + YAML(SyntaxConstants.SYNTAX_STYLE_YAML, (n, c) -> n.endsWith(".yml") || n.endsWith(".yaml")), + CS(SyntaxConstants.SYNTAX_STYLE_CSHARP, (n, c) -> n.endsWith(".cs")), + CSV(SyntaxConstants.SYNTAX_STYLE_CSV, (n, c) -> n.endsWith(".csv")), + DOCKER(SyntaxConstants.SYNTAX_STYLE_DOCKERFILE, (n, c) -> n.endsWith(".dockerfile")), + DART(SyntaxConstants.SYNTAX_STYLE_DART, (n, c) -> n.endsWith(".dart")), + GO(SyntaxConstants.SYNTAX_STYLE_GO, (n, c) -> n.endsWith(".go")), + HTACCESS(SyntaxConstants.SYNTAX_STYLE_HTACCESS, (n, c) -> n.endsWith(".htaccess")), + INI(SyntaxConstants.SYNTAX_STYLE_INI, (n, c) -> n.endsWith(".ini")), + KOTLIN(SyntaxConstants.SYNTAX_STYLE_KOTLIN, (n, c) -> n.endsWith(".kt") || n.endsWith(".kts")), + LATEX(SyntaxConstants.SYNTAX_STYLE_LATEX, (n, c) -> n.endsWith(".tex")), + MARKDOWN(SyntaxConstants.SYNTAX_STYLE_MARKDOWN, (n, c) -> n.endsWith(".md")), + PERL(SyntaxConstants.SYNTAX_STYLE_PERL, (n, c) -> n.endsWith(".pl")), + TYPESCRIPT(SyntaxConstants.SYNTAX_STYLE_TYPESCRIPT, (n, c) -> n.endsWith(".ts")), + NONE(SyntaxConstants.SYNTAX_STYLE_NONE, (n, c) -> false); public static final SyntaxLanguage[] VALUES = values(); @@ -68,20 +98,19 @@ public static SyntaxLanguage detectLanguage(String fileName, String content) for (SyntaxLanguage lang : VALUES) { if (lang.isLanguage(fileName, content)) - { return lang; - } } + return NONE; } public static void setLanguage(RSyntaxTextArea area, String fileName) { String type = FILE_TYPE_UTIL.guessContentType(new File(fileName)); + if (type == null || type.equals(SyntaxConstants.SYNTAX_STYLE_NONE)) - { type = FILE_TYPE_UTIL.guessContentType(area); - } + area.setSyntaxEditingStyle(type); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/WindowStateChangeAdapter.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/WindowStateChangeAdapter.java index 1e380d221..34b80f202 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/WindowStateChangeAdapter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/WindowStateChangeAdapter.java @@ -50,12 +50,8 @@ public void windowStateChanged(WindowEvent evt) }*/ if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0) - { mainViewerGUI.isMaximized = true; - } else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0) - { mainViewerGUI.isMaximized = false; - } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java index 8f2f767e9..fbc74dc1f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/ZipUtils.java @@ -44,12 +44,14 @@ public final class ZipUtils public static void unzipFilesToPath(String jarPath, String destinationDir) throws IOException { String canonicalDestDir = new File(destinationDir).getCanonicalPath(); + if (!canonicalDestDir.endsWith(File.separator)) { canonicalDestDir += File.separator; } File file = new File(jarPath); + try (JarFile jar = new JarFile(file)) { @@ -82,6 +84,7 @@ public static void unzipFilesToPath(String jarPath, String destinationDir) throw } File parent = f.getParentFile(); + if (!parent.exists()) { parent.mkdirs(); @@ -110,6 +113,7 @@ public static void zipFile(File inputFile, File outputZip) { ZipEntry ze = new ZipEntry(inputFile.getName()); zos.putNextEntry(ze); + try (FileInputStream in = new FileInputStream(inputFile)) { int len; @@ -156,14 +160,18 @@ public static void addFileToZip(String path, String srcFile, ZipOutputStream zip { byte[] buf = new byte[1024]; int len; + try (FileInputStream in = new FileInputStream(srcFile)) { ZipEntry entry; + if (ignore == null) entry = new ZipEntry(path + "/" + folder.getName()); else entry = new ZipEntry(path.replace(ignore, "BCV_Krakatau") + "/" + folder.getName()); + zip.putNextEntry(entry); + while ((len = in.read(buf)) > 0) { zip.write(buf, 0, len); @@ -194,6 +202,7 @@ public static void addFileToZipAPKTool(String path, String srcFile, ZipOutputStr { byte[] buf = new byte[1024]; int len; + try (FileInputStream in = new FileInputStream(srcFile)) { ZipEntry entry; @@ -216,13 +225,9 @@ public static void addFolderToZip(String path, String srcFolder, ZipOutputStream for (String fileName : Objects.requireNonNull(folder.list())) { if (path.isEmpty()) - { addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, ignore); - } else - { addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, ignore); - } } } @@ -233,13 +238,9 @@ public static void addFolderToZipAPKTool(String path, String srcFolder, ZipOutpu for (String fileName : Objects.requireNonNull(folder.list())) { if (path.isEmpty()) - { addFileToZipAPKTool(folder.getName(), srcFolder + "/" + fileName, zip); - } else - { addFileToZipAPKTool(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip); - } } } }