diff --git a/src/me/nov/threadtear/execution/tools/LogAllExceptions.java b/src/me/nov/threadtear/execution/tools/LogAllExceptions.java new file mode 100644 index 0000000..f69fbfd --- /dev/null +++ b/src/me/nov/threadtear/execution/tools/LogAllExceptions.java @@ -0,0 +1,37 @@ +package me.nov.threadtear.execution.tools; + +import java.util.List; +import java.util.Map; + +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.MethodInsnNode; + +import me.nov.threadtear.execution.Clazz; +import me.nov.threadtear.execution.Execution; +import me.nov.threadtear.execution.ExecutionCategory; +import me.nov.threadtear.execution.ExecutionTag; +import me.nov.threadtear.util.asm.Instructions; + +public class LogAllExceptions extends Execution { + + public LogAllExceptions() { + super(ExecutionCategory.TOOLS, "Log all exceptions", "Adds .printStackTrace() in every try catch block handler.", ExecutionTag.RUNNABLE); + } + + @Override + public boolean execute(Map classes, boolean verbose) { + classes.values().stream().map(c -> c.node.methods).flatMap(List::stream).forEach(m -> { + if (m.tryCatchBlocks == null) + return; + m.tryCatchBlocks.forEach(tcb -> { + AbstractInsnNode handler = Instructions.getRealNext(tcb.handler); + m.instructions.insertBefore(handler, new InsnNode(DUP)); + m.instructions.insertBefore(handler, new MethodInsnNode(INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V")); + }); + m.maxStack = Math.max(m.maxStack, 2); + }); + logger.info("Inserted .printStackTrace() in every catch block!"); + return true; + } +} \ No newline at end of file diff --git a/src/me/nov/threadtear/swing/dialog/ExecutionSelection.java b/src/me/nov/threadtear/swing/dialog/ExecutionSelection.java index 413e8fa..b00fce8 100644 --- a/src/me/nov/threadtear/swing/dialog/ExecutionSelection.java +++ b/src/me/nov/threadtear/swing/dialog/ExecutionSelection.java @@ -41,6 +41,7 @@ import me.nov.threadtear.execution.tools.IsolatePossiblyMalicious; import me.nov.threadtear.execution.tools.Java7Compatibility; import me.nov.threadtear.execution.tools.Java8Compatibility; +import me.nov.threadtear.execution.tools.LogAllExceptions; import me.nov.threadtear.execution.zkm.AccessObfusationZKM; import me.nov.threadtear.execution.zkm.StringObfuscationZKM; import me.nov.threadtear.execution.zkm.TryCatchObfuscationRemover; @@ -129,6 +130,7 @@ public ExecutionSelectionTree() { addExecution(root, new Java8Compatibility()); addExecution(root, new IsolatePossiblyMalicious()); addExecution(root, new AddLineNumbers()); + addExecution(root, new LogAllExceptions()); this.setModel(model); ToolTipManager.sharedInstance().registerComponent(this);