diff --git a/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java deleted file mode 100644 index 49b736ba95..0000000000 --- a/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java +++ /dev/null @@ -1,48 +0,0 @@ -package dev.openrs2.deob.transform; - -import dev.openrs2.asm.InsnMatcher; -import dev.openrs2.asm.InsnNodeUtils; -import dev.openrs2.asm.classpath.ClassPath; -import dev.openrs2.asm.classpath.Library; -import dev.openrs2.asm.transform.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(ClassPath classPath) { - tracingTryCatches = 0; - } - - @Override - public boolean transformCode(ClassPath classPath, Library library, 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++; - } - }); - - return false; - } - - @Override - public void postTransform(ClassPath classPath) { - logger.info("Removed {} tracing try/catch blocks", tracingTryCatches); - } -} diff --git a/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.kt new file mode 100644 index 0000000000..55cad9472c --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.kt @@ -0,0 +1,47 @@ +package dev.openrs2.deob.transform + +import com.github.michaelbull.logging.InlineLogger +import dev.openrs2.asm.InsnMatcher +import dev.openrs2.asm.InsnNodeUtils +import dev.openrs2.asm.classpath.ClassPath +import dev.openrs2.asm.classpath.Library +import dev.openrs2.asm.transform.Transformer +import org.objectweb.asm.tree.ClassNode +import org.objectweb.asm.tree.MethodNode + +class ExceptionTracingTransformer : Transformer() { + private var tracingTryCatches = 0 + + public override fun preTransform(classPath: ClassPath) { + tracingTryCatches = 0 + } + + public override fun transformCode( + classPath: ClassPath, + library: Library, + clazz: ClassNode, + method: MethodNode + ): Boolean { + CATCH_MATCHER.match(method).forEach { match -> + val foundTryCatch = method.tryCatchBlocks.removeIf { tryCatch -> + tryCatch.type == "java/lang/RuntimeException" && InsnNodeUtils.nextReal(tryCatch.handler) === match[0] + } + + if (foundTryCatch) { + match.forEach(method.instructions::remove) + tracingTryCatches++ + } + } + return false + } + + public override fun postTransform(classPath: ClassPath) { + logger.info { "Removed $tracingTryCatches tracing try/catch blocks" } + } + + companion object { + private val logger = InlineLogger() + private val 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") + } +}