From 9e33d2c28243702c431e5ca3a5d4669669ff47f0 Mon Sep 17 00:00:00 2001 From: nick-botticelli Date: Fri, 27 May 2022 04:29:07 -0700 Subject: [PATCH 1/5] Update Maven shade plugin to 3.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 65465760..5fe5ba4f 100644 --- a/pom.xml +++ b/pom.xml @@ -398,7 +398,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.3.0 package From 56b3a72c25d4892090cb8544a2d5d03f54d8901a Mon Sep 17 00:00:00 2001 From: nick-botticelli Date: Fri, 27 May 2022 15:51:38 -0700 Subject: [PATCH 2/5] Change reference to -decompiler-list to -list --- .../java/the/bytecode/club/bytecodeviewer/CommandLineInput.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java index e7b661e8..165bc7ec 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java @@ -165,7 +165,7 @@ public class CommandLineInput { !decompiler.equalsIgnoreCase("jd-gui") && !decompiler.equalsIgnoreCase("smali") ) { - System.out.println("Error, no decompiler called '" + decompiler + "' found. Type -decompiler-list" + System.out.println("Error, no decompiler called '" + decompiler + "' found. Type -list" + " for the list"); } From 0d221dbca59908036b05d1a4b0064821a161e61c Mon Sep 17 00:00:00 2001 From: nick-botticelli Date: Fri, 27 May 2022 16:53:59 -0700 Subject: [PATCH 3/5] Add ASMifier support This adds support (both GUI and CLI) for generating Java code from ASMifier to generate the bytecode of a class with ASM --- .../club/bytecodeviewer/CommandLineInput.java | 24 +++++++++- .../decompilers/Decompiler.java | 13 +---- .../decompilers/impl/ASMifierGenerator.java | 47 +++++++++++++++++++ .../components/DecompilerViewComponent.java | 12 ++--- .../DecompilerSelectionPane.java | 13 ++--- .../translation/TranslatedComponents.java | 3 +- .../translation/TranslatedStrings.java | 1 + src/main/resources/translations/english.json | 1 + 8 files changed, 88 insertions(+), 26 deletions(-) create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java index 165bc7ec..87e52207 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/CommandLineInput.java @@ -100,6 +100,7 @@ public class CommandLineInput { System.out.println("Krakatau-Bytecode"); System.out.println("JD-GUI"); System.out.println("Smali"); + System.out.println("ASMifier"); return STOP; } else if (cmd.hasOption("clean")) { new File(Constants.getBCVDirectory()).delete(); @@ -163,7 +164,8 @@ public class CommandLineInput { !decompiler.equalsIgnoreCase("krakatau") && !decompiler.equalsIgnoreCase("krakatau-bytecode") && !decompiler.equalsIgnoreCase("jd-gui") && - !decompiler.equalsIgnoreCase("smali") + !decompiler.equalsIgnoreCase("smali") && + !decompiler.equalsIgnoreCase("asmifier") ) { System.out.println("Error, no decompiler called '" + decompiler + "' found. Type -list" + " for the list"); @@ -356,6 +358,26 @@ public class CommandLineInput { } } } + else if (decompiler.equalsIgnoreCase("asmifier")) { + System.out.println("Generating ASM code for " + input.getAbsolutePath() + " with ASMifier"); + BytecodeViewer.openFiles(new File[]{input}, false); + + Thread.sleep(5 * 1000); + + if (target.equalsIgnoreCase("all")) { + System.out.println("Coming soon."); + //Decompiler.smali.decompileToZip(output.getAbsolutePath()); + } else { + try { + ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target); + final ClassWriter cw = accept(cn); + String contents = Decompiler.ASMIFIER_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray()); + DiskWriter.replaceFile(output.getAbsolutePath(), contents, false); + } catch (Exception e) { + BytecodeViewer.handleException(e); + } + } + } System.out.println("Finished."); System.out.println("Bytecode Viewer " + VERSION + " [CLI] - Created by @Konloch - https://bytecodeviewer.com"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java index e168c4a3..033b11d8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java @@ -1,16 +1,6 @@ package the.bytecode.club.bytecodeviewer.decompilers; -import the.bytecode.club.bytecodeviewer.decompilers.impl.ASMTextifierDisassembler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.BytecodeDisassembler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.CFRDecompiler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.FernFlowerDecompiler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.JADXDecompiler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.JDGUIDecompiler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.JavapDisassembler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.KrakatauDecompiler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.KrakatauDisassembler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.ProcyonDecompiler; -import the.bytecode.club.bytecodeviewer.decompilers.impl.SmaliDisassembler; +import the.bytecode.club.bytecodeviewer.decompilers.impl.*; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -51,6 +41,7 @@ public enum Decompiler JD_DECOMPILER("JD-GUI Decompiler", "jdgui", new JDGUIDecompiler()), JADX_DECOMPILER("JADX Decompiler", "jadx", new JADXDecompiler()), ASM_TEXTIFY_DISASSEMBLER("ASM Disassembler", "asm", new ASMTextifierDisassembler()), + ASMIFIER_DECOMPILER("ASMifier Generator", "asmifier", new ASMifierGenerator()), JAVAP_DISASSEMBLER("Javap Disassembler", "javap", new JavapDisassembler()), ; 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 new file mode 100644 index 00000000..a2031f41 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java @@ -0,0 +1,47 @@ +package the.bytecode.club.bytecodeviewer.decompilers.impl; + +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.util.ASMifier; +import org.objectweb.asm.util.Textifier; +import org.objectweb.asm.util.TraceClassVisitor; +import the.bytecode.club.bytecodeviewer.decompilers.InternalDecompiler; + +import java.io.PrintWriter; +import java.io.StringWriter; + +/*************************************************************************** + * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * + * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +/** + * Objectweb ASMifier output + * + * @author Nick Botticelli + */ +public class ASMifierGenerator extends InternalDecompiler +{ + @Override + public String decompileClassNode(ClassNode cn, byte[] b) { + StringWriter writer = new StringWriter(); + cn.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer))); + return writer.toString(); + } + + @Override + public void decompileToZip(String sourceJar, String zipName) { + } +} 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 b535d5f1..94586528 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 @@ -11,10 +11,7 @@ import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJCheckBoxMenuItem; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJRadioButtonMenuItem; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.BYTECODE; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.BYTECODE_NON_EDITABLE; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.JAVA; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.JAVA_AND_BYTECODE; +import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.*; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -63,12 +60,12 @@ public class DecompilerViewComponent private void createMenu() { - if(type == JAVA || type == JAVA_AND_BYTECODE) + 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); - if(type != BYTECODE_NON_EDITABLE) + if(type != JAVA_NON_EDITABLE && type != BYTECODE_NON_EDITABLE) { menu.add(new JSeparator()); menu.add(editable); @@ -79,7 +76,7 @@ public class DecompilerViewComponent public void addToGroup(ButtonGroup group) { - if(type == JAVA || type == JAVA_AND_BYTECODE) + 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); @@ -118,6 +115,7 @@ public class DecompilerViewComponent public enum DecompilerComponentType { JAVA, + JAVA_NON_EDITABLE, BYTECODE, BYTECODE_NON_EDITABLE, JAVA_AND_BYTECODE 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 30c2dc7c..afa1bb6f 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 @@ -18,10 +18,7 @@ import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJMenu; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJRadioButtonMenuItem; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.BYTECODE; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.BYTECODE_NON_EDITABLE; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.JAVA; -import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.JAVA_AND_BYTECODE; +import static the.bytecode.club.bytecodeviewer.gui.components.DecompilerViewComponent.DecompilerComponentType.*; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -61,12 +58,13 @@ public class DecompilerSelectionPane private final DecompilerViewComponent smali = new DecompilerViewComponent("Smali", BYTECODE, Decompiler.SMALI_DISASSEMBLER); private final DecompilerViewComponent bytecode = new DecompilerViewComponent("Bytecode", BYTECODE_NON_EDITABLE, Decompiler.BYTECODE_DISASSEMBLER); private final DecompilerViewComponent asmTextify = new DecompilerViewComponent("ASM Textify", BYTECODE_NON_EDITABLE, Decompiler.ASM_TEXTIFY_DISASSEMBLER); + private final DecompilerViewComponent asmifier = new DecompilerViewComponent("ASMifier", JAVA_NON_EDITABLE, Decompiler.ASMIFIER_DECOMPILER); private final DecompilerViewComponent javap = new DecompilerViewComponent("Javap", BYTECODE_NON_EDITABLE, Decompiler.JAVAP_DISASSEMBLER); //TODO when adding new decompilers insert the DecompilerViewComponent object into here // also in the group, then finally the build menu public List components = new ArrayList<>(Arrays.asList( - procyon, CFR, JADX, JD, fern, krakatau, smali, bytecode, asmTextify, javap)); + procyon, CFR, JADX, JD, fern, krakatau, smali, bytecode, asmTextify, asmifier, javap)); public DecompilerSelectionPane(int paneID) { @@ -159,13 +157,16 @@ public class DecompilerSelectionPane menu.add(bytecode.getMenu()); menu.add(javap.getMenu()); menu.add(asmTextify.getMenu()); + menu.add(asmifier.getMenu()); menu.add(new JSeparator()); menu.add(hexcode); } public Decompiler getSelectedDecompiler() { - return Decompiler.valueOf(group.getSelection().getActionCommand()); + javax.swing.ButtonModel selection = group.getSelection(); + String actionCommand = selection.getActionCommand(); + return Decompiler.valueOf(actionCommand); } public void setSelectedDecompiler(Decompiler decompiler) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java b/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java index e0b6b2cf..ed082427 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedComponents.java @@ -94,7 +94,8 @@ public enum TranslatedComponents BYTECODE, HEXCODE, ASM_TEXTIFY, - + ASMIFIER, + SETTINGS, COMPILE_ON_SAVE, COMPILE_ON_REFRESH, diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedStrings.java b/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedStrings.java index f056dea0..504cce63 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedStrings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedStrings.java @@ -54,6 +54,7 @@ public enum TranslatedStrings HEXCODE, BYTECODE, ASM_TEXTIFY, + ASMIFIER, ERROR, DISASSEMBLER, RESULTS, diff --git a/src/main/resources/translations/english.json b/src/main/resources/translations/english.json index eff6d09b..9c781150 100644 --- a/src/main/resources/translations/english.json +++ b/src/main/resources/translations/english.json @@ -96,6 +96,7 @@ "HEXCODE": "Hexcode", "BYTECODE": "Bytecode", "ASM_TEXTIFY": "ASM Textify", + "ASMIFIER": "ASMifier", "BYTECODE_DECOMPILER": "Bytecode Decompiler", "DEBUG_HELPERS": "Debug Helpers", From 59a40b18c76d91725be4c9c365f16866849ac149 Mon Sep 17 00:00:00 2001 From: nick-botticelli Date: Sat, 28 May 2022 04:17:35 -0700 Subject: [PATCH 4/5] Undo accidental change for debugging --- .../gui/resourceviewer/DecompilerSelectionPane.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 afa1bb6f..ffeeaec6 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 @@ -164,9 +164,7 @@ public class DecompilerSelectionPane public Decompiler getSelectedDecompiler() { - javax.swing.ButtonModel selection = group.getSelection(); - String actionCommand = selection.getActionCommand(); - return Decompiler.valueOf(actionCommand); + return Decompiler.valueOf(group.getSelection().getActionCommand()); } public void setSelectedDecompiler(Decompiler decompiler) From 55eaafd2d18fc469cad0d8c4c58ac8e54979c882 Mon Sep 17 00:00:00 2001 From: Konloch Date: Tue, 5 Jul 2022 01:39:49 -0500 Subject: [PATCH 5/5] Malicious Code Scanner Fix On the latest release the code scanner isn't functioning, this should allow it to work as normal again --- .../decompilers/bytecode/InstructionPrinter.java | 3 +++ 1 file changed, 3 insertions(+) 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 ba6e8ac5..797d5727 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 @@ -76,6 +76,9 @@ public class InstructionPrinter implements Opcodes { } private void precalculateLabelIndexes(MethodNode m) { + if(m == null) + return; + int lIdx = 0; for (AbstractInsnNode ain : m.instructions) { if (ain.getType() == AbstractInsnNode.LABEL) {