Add method for finding classes loaded with Class.forName()

master
Graham 5 years ago
parent 34ef4f9a5e
commit 59ac765ef8
  1. 20
      asm/src/main/java/dev/openrs2/asm/ClassForNameUtils.kt

@ -21,11 +21,23 @@ object ClassForNameUtils {
invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;" invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;"
} }
private fun findLdcInsns(method: MethodNode): Sequence<LdcInsnNode> {
return INVOKE_MATCHER.match(method)
.filter(::isClassForName)
.map { it[0] as LdcInsnNode }
}
private fun internalName(ldc: LdcInsnNode): String {
return (ldc.cst as String).toInternalClassName()
}
fun findClassNames(method: MethodNode): Sequence<String> {
return findLdcInsns(method).map(::internalName)
}
fun remap(remapper: Remapper, method: MethodNode) { fun remap(remapper: Remapper, method: MethodNode) {
for (match in INVOKE_MATCHER.match(method).filter( for (ldc in findLdcInsns(method)) {
ClassForNameUtils::isClassForName)) { val name = remapper.map(internalName(ldc))
val ldc = match[0] as LdcInsnNode
val name = remapper.map((ldc.cst as String).toInternalClassName())
if (name != null) { if (name != null) {
ldc.cst = name.toBinaryClassName() ldc.cst = name.toBinaryClassName()
} }

Loading…
Cancel
Save