Add ExceptionTracingTransformer

bzip2
Graham 5 years ago
parent 4e929bbfc0
commit 66283c6f7a
  1. 4
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.java
  2. 45
      deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java

@ -14,6 +14,7 @@ import dev.openrs2.asm.Transformer;
import dev.openrs2.deob.path.ClassPath;
import dev.openrs2.deob.path.TypedRemapper;
import dev.openrs2.deob.transform.ClassForNameTransformer;
import dev.openrs2.deob.transform.ExceptionTracingTransformer;
import dev.openrs2.deob.transform.OpaquePredicateTransformer;
import dev.openrs2.deob.transform.OriginalNameTransformer;
import org.slf4j.Logger;
@ -23,7 +24,8 @@ public final class Deobfuscator {
private static final Logger logger = LoggerFactory.getLogger(Deobfuscator.class);
private static final List<Transformer> TRANSFORMERS = List.of(
new OpaquePredicateTransformer()
new OpaquePredicateTransformer(),
new ExceptionTracingTransformer()
);
public static void main(String[] args) throws IOException {

@ -0,0 +1,45 @@
package dev.openrs2.deob.transform;
import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.InsnNodeUtils;
import dev.openrs2.asm.Library;
import dev.openrs2.asm.Transformer;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ExceptionTracingTransformer extends Transformer {
private static final Logger logger = LoggerFactory.getLogger(ExceptionTracingTransformer.class);
private static final InsnMatcher CATCH_MATCHER = InsnMatcher.compile("ASTORE ALOAD (| LDC INVOKESTATIC | NEW DUP (LDC INVOKESPECIAL | INVOKESPECIAL LDC INVOKEVIRTUAL) ((ILOAD | LLOAD | FLOAD | DLOAD | (ALOAD IFNULL LDC GOTO LDC) | BIPUSH) INVOKEVIRTUAL)* INVOKEVIRTUAL INVOKESTATIC) ATHROW");
private int tracingTryCatches;
@Override
public void preTransform(Library library) {
tracingTryCatches = 0;
}
@Override
public void transformCode(ClassNode clazz, MethodNode method) {
CATCH_MATCHER.match(method).forEach(match -> {
var foundTryCatch = method.tryCatchBlocks.removeIf(tryCatch -> {
if (!"java/lang/RuntimeException".equals(tryCatch.type)) {
return false;
}
return InsnNodeUtils.nextReal(tryCatch.handler) == match.get(0);
});
if (foundTryCatch) {
match.forEach(method.instructions::remove);
tracingTryCatches++;
}
});
}
@Override
public void postTransform(Library library) {
logger.info("Removed {} tracing try/catch blocks", tracingTryCatches);
}
}
Loading…
Cancel
Save