diff --git a/deob/src/main/java/dev/openrs2/deob/remap/FieldMappingGenerator.kt b/deob/src/main/java/dev/openrs2/deob/remap/FieldMappingGenerator.kt index 094b60c745..74572f9b0e 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/FieldMappingGenerator.kt +++ b/deob/src/main/java/dev/openrs2/deob/remap/FieldMappingGenerator.kt @@ -10,13 +10,14 @@ import org.objectweb.asm.Type class FieldMappingGenerator( private val classPath: ClassPath, private val excludedFields: MemberFilter, + private val inheritedFieldSets: DisjointSet, private val classMapping: Map ) { - private val inheritedFieldSets = classPath.createInheritedFieldSets() private val nameGenerator = NameGenerator() - private val mapping = mutableMapOf() - fun generate(): Map { + fun generate(): Map, String> { + val mapping = mutableMapOf, String>() + for (partition in inheritedFieldSets) { if (!isRenamable(partition)) { continue @@ -24,9 +25,7 @@ class FieldMappingGenerator( val type = Type.getType(partition.first().desc) val mappedName = generateName(type) - for (field in partition) { - mapping[field] = mappedName - } + mapping[partition] = mappedName } return mapping diff --git a/deob/src/main/java/dev/openrs2/deob/remap/MethodMappingGenerator.kt b/deob/src/main/java/dev/openrs2/deob/remap/MethodMappingGenerator.kt index 88637f7e06..9266addece 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/MethodMappingGenerator.kt +++ b/deob/src/main/java/dev/openrs2/deob/remap/MethodMappingGenerator.kt @@ -9,13 +9,13 @@ import org.objectweb.asm.Opcodes class MethodMappingGenerator( private val classPath: ClassPath, - private val excludedMethods: MemberFilter + private val excludedMethods: MemberFilter, + private val inheritedMethodSets: DisjointSet ) { - private val inheritedMethodSets = classPath.createInheritedMethodSets() private var index = 0 - fun generate(): Map { - val mapping = mutableMapOf() + fun generate(): Map, String> { + val mapping = mutableMapOf, String>() for (partition in inheritedMethodSets) { @Suppress("DEPRECATION") @@ -24,9 +24,7 @@ class MethodMappingGenerator( } val mappedName = "method" + ++index - for (method in partition) { - mapping[method] = mappedName - } + mapping[partition] = mappedName } return mapping diff --git a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt index 9070232715..6a4fe62db8 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt +++ b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt @@ -5,22 +5,29 @@ import dev.openrs2.asm.MemberRef import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.ExtendedRemapper import dev.openrs2.deob.Profile +import dev.openrs2.util.collect.DisjointSet class TypedRemapper private constructor( + private val inheritedFieldSets: DisjointSet, + private val inheritedMethodSets: DisjointSet, private val classes: Map, - private val fields: Map, - private val methods: Map + private val fields: Map, String>, + private val methods: Map, String> ) : ExtendedRemapper() { override fun map(internalName: String): String { return classes.getOrDefault(internalName, internalName) } override fun mapFieldName(owner: String, name: String, descriptor: String): String { - return fields.getOrDefault(MemberRef(owner, name, descriptor), name) + val member = MemberRef(owner, name, descriptor) + val partition = inheritedFieldSets[member] ?: return name + return fields.getOrDefault(partition, name) } override fun mapMethodName(owner: String, name: String, descriptor: String): String { - return methods.getOrDefault(MemberRef(owner, name, descriptor), name) + val member = MemberRef(owner, name, descriptor) + val partition = inheritedMethodSets[member] ?: return name + return methods.getOrDefault(partition, name) } companion object { @@ -29,15 +36,27 @@ class TypedRemapper private constructor( private val LIBRARY_PREFIX_REGEX = Regex("^(?:loader|unpackclass)_") fun create(classPath: ClassPath, profile: Profile): TypedRemapper { + val inheritedFieldSets = classPath.createInheritedFieldSets() + val inheritedMethodSets = classPath.createInheritedMethodSets() + val classes = ClassMappingGenerator(classPath, profile.excludedClasses).generate() - val fields = FieldMappingGenerator(classPath, profile.excludedFields, classes).generate() - val methods = MethodMappingGenerator(classPath, profile.excludedMethods).generate() + val fields = FieldMappingGenerator( + classPath, + profile.excludedFields, + inheritedFieldSets, + classes + ).generate() + val methods = MethodMappingGenerator( + classPath, + profile.excludedMethods, + inheritedMethodSets + ).generate() verifyMapping(classes, profile.maxObfuscatedNameLen) verifyMemberMapping(fields, profile.maxObfuscatedNameLen) verifyMemberMapping(methods, profile.maxObfuscatedNameLen) - return TypedRemapper(classes, fields, methods) + return TypedRemapper(inheritedFieldSets, inheritedMethodSets, classes, fields, methods) } private fun verifyMapping(mapping: Map, maxObfuscatedNameLen: Int) { @@ -46,9 +65,12 @@ class TypedRemapper private constructor( } } - private fun verifyMemberMapping(mapping: Map, maxObfuscatedNameLen: Int) { + private fun verifyMemberMapping( + mapping: Map, String>, + maxObfuscatedNameLen: Int + ) { for ((key, value) in mapping) { - verifyMapping(key.name, value, maxObfuscatedNameLen) + verifyMapping(key.first().name, value, maxObfuscatedNameLen) } }