diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt index c220fab447..6fef1941f4 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt @@ -18,6 +18,7 @@ import dev.openrs2.deob.transform.DummyArgTransformer import dev.openrs2.deob.transform.DummyLocalTransformer import dev.openrs2.deob.transform.EmptyClassTransformer import dev.openrs2.deob.transform.ExceptionTracingTransformer +import dev.openrs2.deob.transform.FernflowerExceptionTransformer import dev.openrs2.deob.transform.FieldOrderTransformer import dev.openrs2.deob.transform.FinalTransformer import dev.openrs2.deob.transform.InvokeSpecialTransformer @@ -177,7 +178,8 @@ class Deobfuscator(private val input: Path, private val output: Path) { MethodOrderTransformer(), VisibilityTransformer(), OverrideTransformer(), - OriginalPcRestoreTransformer() + OriginalPcRestoreTransformer(), + FernflowerExceptionTransformer() ) } } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/FernflowerExceptionTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/FernflowerExceptionTransformer.kt new file mode 100644 index 0000000000..ba09cc261c --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/transform/FernflowerExceptionTransformer.kt @@ -0,0 +1,36 @@ +package dev.openrs2.deob.transform + +import com.github.michaelbull.logging.InlineLogger +import dev.openrs2.asm.classpath.ClassPath +import dev.openrs2.asm.classpath.Library +import dev.openrs2.asm.nextReal +import dev.openrs2.asm.transform.Transformer +import org.objectweb.asm.Opcodes +import org.objectweb.asm.tree.ClassNode +import org.objectweb.asm.tree.InsnNode +import org.objectweb.asm.tree.MethodNode + +class FernflowerExceptionTransformer : Transformer() { + private var nopsInserted = 0 + + override fun preTransform(classPath: ClassPath) { + nopsInserted = 0 + } + + override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean { + if (method.tryCatchBlocks.any { it.end.nextReal == null }) { + method.instructions.add(InsnNode(Opcodes.NOP)) + nopsInserted++ + } + + return false + } + + override fun postTransform(classPath: ClassPath) { + logger.info { "Inserted $nopsInserted NOPs to correct Fernflower's exception generation" } + } + + private companion object { + private val logger = InlineLogger() + } +}