Convert AccessTransformer to Kotlin

bzip2
Graham 5 years ago
parent ec58c75ab4
commit 368df81bc8
  1. 65
      deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java
  2. 67
      deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.kt

@ -1,65 +0,0 @@
package dev.openrs2.deob.transform;
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.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class AccessTransformer extends Transformer {
private static final Logger logger = LoggerFactory.getLogger(AccessTransformer.class);
private int redundantFinals, packagePrivate;
@Override
protected void preTransform(ClassPath classPath) {
redundantFinals = 0;
packagePrivate = 0;
}
@Override
protected boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
if ((clazz.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) == 0) {
clazz.access |= Opcodes.ACC_PUBLIC;
packagePrivate++;
}
return false;
}
@Override
protected boolean transformField(ClassPath classPath, Library library, ClassNode clazz, FieldNode field) {
if ((field.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) == 0) {
field.access |= Opcodes.ACC_PUBLIC;
packagePrivate++;
}
return false;
}
@Override
protected boolean preTransformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
if ((method.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) == 0) {
method.access |= Opcodes.ACC_PUBLIC;
packagePrivate++;
}
if ((method.access & Opcodes.ACC_FINAL) == 0) {
return false;
}
if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC)) != 0) {
method.access &= ~Opcodes.ACC_FINAL;
redundantFinals++;
}
return false;
}
@Override
protected void postTransform(ClassPath classPath) {
logger.info("Removed {} redundant final modifiers", redundantFinals);
logger.info("Made {} package-private classes, fields and methods public", packagePrivate);
}
}

@ -0,0 +1,67 @@
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.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodNode
class AccessTransformer : Transformer() {
private var redundantFinals = 0
private var packagePrivate = 0
override fun preTransform(classPath: ClassPath) {
redundantFinals = 0
packagePrivate = 0
}
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
if (clazz.access and (Opcodes.ACC_PUBLIC or Opcodes.ACC_PROTECTED or Opcodes.ACC_PRIVATE) == 0) {
clazz.access = clazz.access or Opcodes.ACC_PUBLIC
packagePrivate++
}
return false
}
override fun transformField(classPath: ClassPath, library: Library, clazz: ClassNode, field: FieldNode): Boolean {
if (field.access and (Opcodes.ACC_PUBLIC or Opcodes.ACC_PROTECTED or Opcodes.ACC_PRIVATE) == 0) {
field.access = field.access or Opcodes.ACC_PUBLIC
packagePrivate++
}
return false
}
override fun preTransformMethod(
classPath: ClassPath,
library: Library,
clazz: ClassNode,
method: MethodNode
): Boolean {
if (method.access and (Opcodes.ACC_PUBLIC or Opcodes.ACC_PROTECTED or Opcodes.ACC_PRIVATE) == 0) {
method.access = method.access or Opcodes.ACC_PUBLIC
packagePrivate++
}
if (method.access and Opcodes.ACC_FINAL == 0) {
return false
}
if (method.access and (Opcodes.ACC_PRIVATE or Opcodes.ACC_STATIC) != 0) {
method.access = method.access and Opcodes.ACC_FINAL.inv()
redundantFinals++
}
return false
}
override fun postTransform(classPath: ClassPath) {
logger.info { "Removed $redundantFinals redundant final modifiers" }
logger.info { "Made $packagePrivate package-private classes, fields and methods public" }
}
companion object {
private val logger = InlineLogger()
}
}
Loading…
Cancel
Save