Split FinalTransformer into Final{Class,Method}Transformer

Signed-off-by: Graham <gpe@openrs2.org>
Graham 2 years ago
parent 39d2f18cca
commit aff58e5e73
  1. 6
      deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscatorModule.kt
  2. 63
      deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/transform/FinalClassTransformer.kt
  3. 43
      deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/transform/FinalMethodTransformer.kt

@ -15,8 +15,9 @@ import org.openrs2.deob.bytecode.transform.EmptyClassTransformer
import org.openrs2.deob.bytecode.transform.ExceptionTracingTransformer
import org.openrs2.deob.bytecode.transform.FernflowerExceptionTransformer
import org.openrs2.deob.bytecode.transform.FieldOrderTransformer
import org.openrs2.deob.bytecode.transform.FinalClassTransformer
import org.openrs2.deob.bytecode.transform.FinalFieldTransformer
import org.openrs2.deob.bytecode.transform.FinalTransformer
import org.openrs2.deob.bytecode.transform.FinalMethodTransformer
import org.openrs2.deob.bytecode.transform.InvokeSpecialTransformer
import org.openrs2.deob.bytecode.transform.MethodOrderTransformer
import org.openrs2.deob.bytecode.transform.MonitorTransformer
@ -71,7 +72,8 @@ public object BytecodeDeobfuscatorModule : AbstractModule() {
binder.addBinding().to(EmptyClassTransformer::class.java)
binder.addBinding().to(MethodOrderTransformer::class.java)
binder.addBinding().to(VisibilityTransformer::class.java)
binder.addBinding().to(FinalTransformer::class.java)
binder.addBinding().to(FinalClassTransformer::class.java)
binder.addBinding().to(FinalMethodTransformer::class.java)
binder.addBinding().to(FinalFieldTransformer::class.java)
binder.addBinding().to(OverrideTransformer::class.java)
binder.addBinding().to(RedundantGotoTransformer::class.java)

@ -0,0 +1,63 @@
package org.openrs2.deob.bytecode.transform
import com.github.michaelbull.logging.InlineLogger
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import org.openrs2.asm.classpath.ClassPath
import org.openrs2.asm.classpath.Library
import org.openrs2.asm.transform.Transformer
import javax.inject.Singleton
@Singleton
public class FinalClassTransformer : Transformer() {
private val superClasses = mutableListOf<String>()
override fun preTransform(classPath: ClassPath) {
superClasses.clear()
}
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
val superClass = clazz.superName
if (superClass != null) {
superClasses += superClass
}
superClasses.addAll(clazz.interfaces)
return false
}
private fun isClassFinal(clazz: ClassNode): Boolean {
if ((clazz.access and (Opcodes.ACC_ABSTRACT or Opcodes.ACC_INTERFACE)) != 0) {
return false
}
return !superClasses.contains(clazz.name)
}
override fun postTransform(classPath: ClassPath) {
var classesChanged = 0
for (library in classPath.libraries) {
for (clazz in library) {
val access = clazz.access
if (isClassFinal(clazz)) {
clazz.access = access or Opcodes.ACC_FINAL
} else {
clazz.access = access and Opcodes.ACC_FINAL.inv()
}
if (clazz.access != access) {
classesChanged++
}
}
}
logger.info { "Updated final modifier on $classesChanged classes" }
}
private companion object {
private val logger = InlineLogger()
}
}

@ -12,28 +12,15 @@ import org.openrs2.util.collect.DisjointSet
import javax.inject.Singleton
@Singleton
public class FinalTransformer : Transformer() {
private val superClasses = mutableListOf<String>()
public class FinalMethodTransformer : Transformer() {
private lateinit var inheritedMethodSets: DisjointSet<MemberRef>
private var methodsChanged = 0
override fun preTransform(classPath: ClassPath) {
superClasses.clear()
inheritedMethodSets = classPath.createInheritedMethodSets()
methodsChanged = 0
}
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
val superClass = clazz.superName
if (superClass != null) {
superClasses += superClass
}
superClasses.addAll(clazz.interfaces)
return false
}
private fun isMethodFinal(classPath: ClassPath, clazz: ClassNode, method: MethodNode): Boolean {
if (method.name == "<init>") {
return false
@ -83,34 +70,8 @@ public class FinalTransformer : Transformer() {
return false
}
private fun isClassFinal(clazz: ClassNode): Boolean {
if ((clazz.access and (Opcodes.ACC_ABSTRACT or Opcodes.ACC_INTERFACE)) != 0) {
return false
}
return !superClasses.contains(clazz.name)
}
override fun postTransform(classPath: ClassPath) {
var classesChanged = 0
for (library in classPath.libraries) {
for (clazz in library) {
val access = clazz.access
if (isClassFinal(clazz)) {
clazz.access = access or Opcodes.ACC_FINAL
} else {
clazz.access = access and Opcodes.ACC_FINAL.inv()
}
if (clazz.access != access) {
classesChanged++
}
}
}
logger.info { "Updated final modifier on $classesChanged classes and $methodsChanged methods" }
logger.info { "Updated final modifier on $methodsChanged methods" }
}
private companion object {
Loading…
Cancel
Save