Skip to content

Commit

Permalink
add printStackTrace() inserter
Browse files Browse the repository at this point in the history
  • Loading branch information
GraxCode committed Apr 23, 2020
1 parent 69cb5b3 commit 8f3e35d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/me/nov/threadtear/execution/tools/LogAllExceptions.java
Original file line number Diff line number Diff line change
@@ -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<String, Clazz> 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;
}
}
2 changes: 2 additions & 0 deletions src/me/nov/threadtear/swing/dialog/ExecutionSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8f3e35d

Please sign in to comment.