From 59ac765ef8ad3d8594143954568a48cb624ccabc Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 29 Feb 2020 14:16:15 +0000 Subject: [PATCH] Add method for finding classes loaded with Class.forName() --- .../java/dev/openrs2/asm/ClassForNameUtils.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/ClassForNameUtils.kt b/asm/src/main/java/dev/openrs2/asm/ClassForNameUtils.kt index c1d44322..21f27e60 100644 --- a/asm/src/main/java/dev/openrs2/asm/ClassForNameUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/ClassForNameUtils.kt @@ -21,11 +21,23 @@ object ClassForNameUtils { invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;" } + private fun findLdcInsns(method: MethodNode): Sequence { + 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 { + return findLdcInsns(method).map(::internalName) + } + 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()) + for (ldc in findLdcInsns(method)) { + val name = remapper.map(internalName(ldc)) if (name != null) { ldc.cst = name.toBinaryClassName() }