forked from openrs2/openrs2
Fernflower fails to decompile any exception handler with an end_pc (`to` in Fernflower nomenclature) equal to the length of the code array, even though this is permitted in the class file spec. This transformer inserts a NOP at the end of any code array that has such an exception handler. Signed-off-by: Major <major@emulate.rs>bzip2
parent
e7c3afab19
commit
a869d47d11
@ -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() |
||||
} |
||||
} |
Loading…
Reference in new issue