From f94c03d1782b56bebfcf34fbc8b7e74c69f2c52e Mon Sep 17 00:00:00 2001 From: Konloch Date: Wed, 2 Oct 2024 16:50:49 -0600 Subject: [PATCH] ASM Disassembler Better Failing. Decompile to zip fallback added. --- .../decompilers/Decompiler.java | 2 +- ...Disassembler.java => ASMDisassembler.java} | 40 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) rename src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/{ASMTextifierDisassembler.java => ASMDisassembler.java} (56%) 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 bdb5f998..1a192771 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/Decompiler.java @@ -44,7 +44,7 @@ public enum Decompiler JD_DECOMPILER(new JDGUIDecompiler()), //java decompiler JADX_DECOMPILER(new JADXDecompiler()), //java decompiler - ASM_TEXTIFY_DISASSEMBLER(new ASMTextifierDisassembler()), //bytecode disassembler + ASM_TEXTIFY_DISASSEMBLER(new ASMDisassembler()), //bytecode disassembler ASMIFIER_DECOMPILER(new ASMifierGenerator()), //bytecode disassembler / code gen JAVAP_DISASSEMBLER(new JavapDisassembler()); //bytecode disassembler diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMDisassembler.java similarity index 56% rename from src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java rename to src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMDisassembler.java index b77d45c3..e3992065 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMTextifierDisassembler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMDisassembler.java @@ -21,19 +21,27 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.util.Textifier; import org.objectweb.asm.util.TraceClassVisitor; +import the.bytecode.club.bytecodeviewer.Constants; +import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler; +import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; +import the.bytecode.club.bytecodeviewer.util.ExceptionUtils; import java.io.PrintWriter; import java.io.StringWriter; +import static the.bytecode.club.bytecodeviewer.Constants.NL; +import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.DEV_MODE_SIMULATED_ERROR; +import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.ERROR; + /** * Objectweb ASM Textifier output * * @author Thiakil */ -public class ASMTextifierDisassembler extends AbstractDecompiler +public class ASMDisassembler extends AbstractDecompiler { - public ASMTextifierDisassembler() + public ASMDisassembler() { super("ASM Disassembler", "asm"); } @@ -41,13 +49,35 @@ public class ASMTextifierDisassembler extends AbstractDecompiler @Override public String decompileClassNode(ClassNode cn, byte[] bytes) { - StringWriter writer = new StringWriter(); - cn.accept(new TraceClassVisitor(null, new Textifier(), new PrintWriter(writer))); - return writer.toString(); + String exception; + + try + { + //create writer + StringWriter writer = new StringWriter(); + + //initialize ASM-Textifier & parse class-file + cn.accept(new TraceClassVisitor(null, new Textifier(), new PrintWriter(writer))); + + //handle simulated errors + if(Constants.DEV_FLAG_DECOMPILERS_SIMULATED_ERRORS) + throw new RuntimeException(DEV_MODE_SIMULATED_ERROR.toString()); + + //return writer contents + return writer.toString(); + } + catch (Throwable e) + { + exception = ExceptionUtils.exceptionToString(e); + } + + return "ASM Disassembler " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception; } @Override public void decompileToZip(String sourceJar, String zipName) { + decompileToZipFallBack(sourceJar, zipName); } }