forked from openrs2/openrs2
This is a slightly nicer solution than running a combined transformer until it reaches a fixed point: we know we'd only need two passes, rather than an arbitrary number of passes. The 667 client uses various exception types beyond RuntimeException in ZKM exception obfuscation handlers, including Throwable, Exception, EOFException and IOException. This separation also allows us to remove the type constraint for ZKM handlers. Signed-off-by: Graham <gpe@openrs2.org>
parent
514799920e
commit
9e001e32e1
@ -0,0 +1,54 @@ |
||||
package org.openrs2.deob.bytecode.transform |
||||
|
||||
import com.github.michaelbull.logging.InlineLogger |
||||
import jakarta.inject.Singleton |
||||
import org.objectweb.asm.Opcodes |
||||
import org.objectweb.asm.tree.ClassNode |
||||
import org.objectweb.asm.tree.MethodNode |
||||
import org.openrs2.asm.classpath.ClassPath |
||||
import org.openrs2.asm.classpath.Library |
||||
import org.openrs2.asm.nextReal |
||||
import org.openrs2.asm.transform.Transformer |
||||
|
||||
/** |
||||
* A [Transformer] responsible for removing [ZKM](http://www.zelix.com/klassmaster/)'s |
||||
* [exception obfuscation](https://www.zelix.com/klassmaster/featuresExceptionObfuscation.html), |
||||
* which inserts exception handlers that catch any type of exception and |
||||
* immediately re-throw them. The exception handlers are inserted in locations |
||||
* where there is no Java source code equivalent, confusing decompilers. |
||||
*/ |
||||
@Singleton |
||||
public class ExceptionObfuscationTransformer : Transformer() { |
||||
private var handlers = 0 |
||||
|
||||
override fun preTransform(classPath: ClassPath) { |
||||
handlers = 0 |
||||
} |
||||
|
||||
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean { |
||||
for (insn in method.instructions) { |
||||
if (insn.opcode != Opcodes.ATHROW) { |
||||
continue |
||||
} |
||||
|
||||
val foundTryCatch = method.tryCatchBlocks.removeIf { tryCatch -> |
||||
tryCatch.handler.nextReal === insn |
||||
} |
||||
|
||||
if (foundTryCatch) { |
||||
method.instructions.remove(insn) |
||||
handlers++ |
||||
} |
||||
} |
||||
|
||||
return false |
||||
} |
||||
|
||||
override fun postTransform(classPath: ClassPath) { |
||||
logger.info { "Removed $handlers exception obfuscation handlers" } |
||||
} |
||||
|
||||
private companion object { |
||||
private val logger = InlineLogger() |
||||
} |
||||
} |
Loading…
Reference in new issue