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.
 
 
 
 
openrs2/asm/src/main/java/dev/openrs2/asm/ClassForNameUtils.kt

34 lines
1.1 KiB

package dev.openrs2.asm
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
object ClassForNameUtils {
private val INVOKE_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC")
private fun isClassForName(match: List<AbstractInsnNode>): Boolean {
val ldc = match[0] as LdcInsnNode
if (ldc.cst !is String) {
return false
}
val invokestatic = match[1] as MethodInsnNode
return invokestatic.owner == "java/lang/Class" &&
invokestatic.name == "forName" &&
invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;"
}
fun remap(remapper: Remapper, method: MethodNode) {
for (match in INVOKE_MATCHER.match(method).filter(
ClassForNameUtils::isClassForName)) {
val ldc = match[0] as LdcInsnNode
val name = remapper.map((ldc.cst as String).toInternalClassName())
if (name != null) {
ldc.cst = name.toBinaryClassName()
}
}
}
}