Add OverrideTransformer

master
Graham 5 years ago
parent 2ebcb3507b
commit c2809a16f8
  1. 25
      asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt
  2. 4
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt
  3. 56
      deob/src/main/java/dev/openrs2/deob/transform/OverrideTransformer.kt

@ -13,6 +13,31 @@ abstract class ClassMetadata {
abstract fun isNative(method: MemberDesc): Boolean
fun isOverride(method: MemberDesc): Boolean {
val superClass = this.superClass
if (superClass != null) {
if (superClass.methods.contains(method)) {
return true
}
if (superClass.isOverride(method)) {
return true
}
}
for (superInterface in superInterfaces) {
if (superInterface.methods.contains(method)) {
return true
}
if (superInterface.isOverride(method)) {
return true
}
}
return false
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ClassMetadata) return false

@ -19,6 +19,7 @@ import dev.openrs2.deob.transform.ExceptionTracingTransformer
import dev.openrs2.deob.transform.FieldOrderTransformer
import dev.openrs2.deob.transform.OpaquePredicateTransformer
import dev.openrs2.deob.transform.OriginalNameTransformer
import dev.openrs2.deob.transform.OverrideTransformer
import dev.openrs2.deob.transform.RemapTransformer
import dev.openrs2.deob.transform.ResetTransformer
import dev.openrs2.deob.transform.UnusedArgTransformer
@ -157,7 +158,8 @@ class Deobfuscator(private val input: Path, private val output: Path) {
DummyLocalTransformer(),
UnusedArgTransformer(),
ResetTransformer(),
AccessTransformer()
AccessTransformer(),
OverrideTransformer()
)
}
}

@ -0,0 +1,56 @@
package dev.openrs2.deob.transform
import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.MemberDesc
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.AnnotationNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
class OverrideTransformer : Transformer() {
private var overrides = 0
override fun preTransform(classPath: ClassPath) {
overrides = 0
}
override fun transformCode(
classPath: ClassPath,
library: Library,
clazz: ClassNode,
method: MethodNode
): Boolean {
if (method.name == "<init>" || method.name == "<clinit>" || method.access and Opcodes.ACC_STATIC != 0) {
return false
}
if (!classPath[clazz.name].isOverride(MemberDesc(method))) {
return false
}
if (method.visibleAnnotations != null && method.visibleAnnotations.any { it.desc == OVERRIDE_DESC }) {
return false
}
if (method.visibleAnnotations == null) {
method.visibleAnnotations = mutableListOf()
}
method.visibleAnnotations.add(AnnotationNode(OVERRIDE_DESC))
overrides++
return false
}
override fun postTransform(classPath: ClassPath) {
logger.info { "Added $overrides override annotations" }
}
companion object {
val logger = InlineLogger()
val OVERRIDE_DESC: String = Type.getDescriptor(Override::class.java)
}
}
Loading…
Cancel
Save