Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.3 KiB
81 lines
2.3 KiB
4 years ago
|
package org.openrs2.deob.bytecode.transform
|
||
5 years ago
|
|
||
|
import com.github.michaelbull.logging.InlineLogger
|
||
|
import org.objectweb.asm.Opcodes
|
||
|
import org.objectweb.asm.tree.ClassNode
|
||
|
import org.objectweb.asm.tree.MethodNode
|
||
4 years ago
|
import org.openrs2.asm.MemberRef
|
||
|
import org.openrs2.asm.classpath.ClassPath
|
||
|
import org.openrs2.asm.classpath.Library
|
||
|
import org.openrs2.asm.transform.Transformer
|
||
|
import org.openrs2.util.collect.DisjointSet
|
||
4 years ago
|
import javax.inject.Singleton
|
||
5 years ago
|
|
||
4 years ago
|
@Singleton
|
||
2 years ago
|
public class FinalMethodTransformer : Transformer() {
|
||
4 years ago
|
private lateinit var inheritedMethodSets: DisjointSet<MemberRef>
|
||
|
private var methodsChanged = 0
|
||
5 years ago
|
|
||
|
override fun preTransform(classPath: ClassPath) {
|
||
4 years ago
|
inheritedMethodSets = classPath.createInheritedMethodSets()
|
||
|
methodsChanged = 0
|
||
|
}
|
||
|
|
||
|
private fun isMethodFinal(classPath: ClassPath, clazz: ClassNode, method: MethodNode): Boolean {
|
||
|
if (method.name == "<init>") {
|
||
|
return false
|
||
|
} else if ((method.access and (Opcodes.ACC_ABSTRACT or Opcodes.ACC_PRIVATE or Opcodes.ACC_STATIC)) != 0) {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
val thisClass = classPath[clazz.name]!!
|
||
|
|
||
|
val partition = inheritedMethodSets[MemberRef(clazz, method)]!!
|
||
|
for (methodRef in partition) {
|
||
|
if (methodRef.owner == clazz.name) {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
val otherClass = classPath[methodRef.owner]!!
|
||
|
if (otherClass.methods.none { it.name == methodRef.name && it.desc == methodRef.desc }) {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
if (thisClass.isAssignableFrom(otherClass)) {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true
|
||
5 years ago
|
}
|
||
|
|
||
|
override fun preTransformMethod(
|
||
|
classPath: ClassPath,
|
||
|
library: Library,
|
||
|
clazz: ClassNode,
|
||
|
method: MethodNode
|
||
|
): Boolean {
|
||
4 years ago
|
val access = method.access
|
||
|
|
||
|
if (isMethodFinal(classPath, clazz, method)) {
|
||
|
method.access = access or Opcodes.ACC_FINAL
|
||
|
} else {
|
||
|
method.access = access and Opcodes.ACC_FINAL.inv()
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
if (method.access != access) {
|
||
|
methodsChanged++
|
||
5 years ago
|
}
|
||
4 years ago
|
|
||
5 years ago
|
return false
|
||
|
}
|
||
|
|
||
|
override fun postTransform(classPath: ClassPath) {
|
||
2 years ago
|
logger.info { "Updated final modifier on $methodsChanged methods" }
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
private companion object {
|
||
5 years ago
|
private val logger = InlineLogger()
|
||
|
}
|
||
|
}
|