Add initial NameMap support to TypedRemapper

This commit adds support for mapping:

* class names
* field names
* field owners
* method names
* method owners

It does not yet support argument names, local variable names or
re-ordering method arguments. Local variable names are blocked on
Fernflower patches and method argument re-ordering is blocked on the IR.

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent d28c712299
commit 611ac6de84
  1. 49
      deob-map/src/main/java/dev/openrs2/deob/map/NameMap.kt
  2. 7
      deob/src/main/java/dev/openrs2/deob/remap/ClassMappingGenerator.kt
  3. 5
      deob/src/main/java/dev/openrs2/deob/remap/FieldMappingGenerator.kt
  4. 6
      deob/src/main/java/dev/openrs2/deob/remap/MethodMappingGenerator.kt
  5. 5
      deob/src/main/java/dev/openrs2/deob/remap/StaticFieldUnscrambler.kt
  6. 4
      deob/src/main/java/dev/openrs2/deob/remap/StaticMethodUnscrambler.kt
  7. 13
      deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt
  8. 8
      deob/src/main/java/dev/openrs2/deob/transform/RemapTransformer.kt

@ -1,6 +1,7 @@
package dev.openrs2.deob.map
import dev.openrs2.asm.MemberRef
import dev.openrs2.util.collect.DisjointSet
import java.util.SortedMap
import java.util.TreeMap
@ -16,4 +17,52 @@ data class NameMap(
fields.putAll(other.fields)
methods.putAll(other.methods)
}
fun mapClassName(name: String, default: String): String {
return classes.getOrDefault(name, default)
}
fun mapFieldName(partition: DisjointSet.Partition<MemberRef>, default: String): String {
for (member in partition) {
val field = fields[member]
if (field != null) {
return field.name
}
}
return default
}
fun mapFieldOwner(partition: DisjointSet.Partition<MemberRef>, default: String): String {
for (member in partition) {
val field = fields[member]
if (field != null) {
return field.owner
}
}
return default
}
fun mapMethodName(partition: DisjointSet.Partition<MemberRef>, default: String): String {
for (member in partition) {
val method = methods[member]
if (method != null) {
return method.name
}
}
return default
}
fun mapMethodOwner(partition: DisjointSet.Partition<MemberRef>, default: String): String {
for (member in partition) {
val method = methods[member]
if (method != null) {
return method.owner
}
}
return default
}
}

@ -3,11 +3,13 @@ package dev.openrs2.deob.remap
import dev.openrs2.asm.classpath.ClassMetadata
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.filter.ClassFilter
import dev.openrs2.deob.map.NameMap
import org.objectweb.asm.Opcodes
class ClassMappingGenerator(
private val classPath: ClassPath,
private val excludedClasses: ClassFilter
private val excludedClasses: ClassFilter,
private val nameMap: NameMap
) {
private val nameGenerator = NameGenerator()
private val mapping = mutableMapOf<String, String>()
@ -16,6 +18,9 @@ class ClassMappingGenerator(
for (clazz in classPath.libraryClasses) {
populateMapping(clazz)
}
mapping.replaceAll(nameMap::mapClassName)
return mapping
}

@ -3,6 +3,7 @@ package dev.openrs2.deob.remap
import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.filter.MemberFilter
import dev.openrs2.deob.map.NameMap
import dev.openrs2.util.collect.DisjointSet
import dev.openrs2.util.indefiniteArticle
import org.objectweb.asm.Type
@ -10,6 +11,7 @@ import org.objectweb.asm.Type
class FieldMappingGenerator(
private val classPath: ClassPath,
private val excludedFields: MemberFilter,
private val nameMap: NameMap,
private val inheritedFieldSets: DisjointSet<MemberRef>,
private val classMapping: Map<String, String>
) {
@ -24,8 +26,7 @@ class FieldMappingGenerator(
}
val type = Type.getType(partition.first().desc)
val mappedName = generateName(type)
mapping[partition] = mappedName
mapping[partition] = nameMap.mapFieldName(partition, generateName(type))
}
return mapping

@ -4,12 +4,14 @@ import dev.openrs2.asm.MemberDesc
import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.filter.MemberFilter
import dev.openrs2.deob.map.NameMap
import dev.openrs2.util.collect.DisjointSet
import org.objectweb.asm.Opcodes
class MethodMappingGenerator(
private val classPath: ClassPath,
private val excludedMethods: MemberFilter,
private val nameMap: NameMap,
private val inheritedMethodSets: DisjointSet<MemberRef>
) {
private var index = 0
@ -23,8 +25,8 @@ class MethodMappingGenerator(
continue
}
val mappedName = "method" + ++index
mapping[partition] = mappedName
val generatedName = "method" + ++index
mapping[partition] = nameMap.mapMethodName(partition, generatedName)
}
return mapping

@ -6,6 +6,7 @@ import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.filter.MemberFilter
import dev.openrs2.asm.getExpression
import dev.openrs2.asm.isSequential
import dev.openrs2.deob.map.NameMap
import dev.openrs2.util.collect.DisjointSet
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.AbstractInsnNode
@ -15,6 +16,7 @@ import org.objectweb.asm.tree.MethodNode
class StaticFieldUnscrambler(
private val classPath: ClassPath,
private val excludedFields: MemberFilter,
private val nameMap: NameMap,
private val inheritedFieldSets: DisjointSet<MemberRef>,
staticClassNameGenerator: NameGenerator
) {
@ -50,7 +52,8 @@ class StaticFieldUnscrambler(
val member = MemberRef(clazz, field)
val partition = inheritedFieldSets[member]!!
fields[partition] = StaticField(generator.generate(), simpleInitializers[desc])
val owner = nameMap.mapFieldOwner(partition, generator.generate())
fields[partition] = StaticField(owner, simpleInitializers[desc])
}
}
}

@ -3,12 +3,14 @@ package dev.openrs2.deob.remap
import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.filter.MemberFilter
import dev.openrs2.deob.map.NameMap
import dev.openrs2.util.collect.DisjointSet
import org.objectweb.asm.Opcodes
class StaticMethodUnscrambler(
private val classPath: ClassPath,
private val excludedMethods: MemberFilter,
private val nameMap: NameMap,
private val inheritedMethodSets: DisjointSet<MemberRef>,
staticClassNameGenerator: NameGenerator
) {
@ -37,7 +39,7 @@ class StaticMethodUnscrambler(
val member = MemberRef(clazz, method)
val partition = inheritedMethodSets[member]!!
owners[partition] = generator.generate()
owners[partition] = nameMap.mapMethodOwner(partition, generator.generate())
}
}
}

@ -5,6 +5,7 @@ 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.deob.map.NameMap
import dev.openrs2.util.collect.DisjointSet
import org.objectweb.asm.tree.AbstractInsnNode
@ -56,20 +57,26 @@ class TypedRemapper private constructor(
private val LIBRARY_PREFIX_REGEX = Regex("^(?:loader|unpackclass)_")
fun create(classPath: ClassPath, profile: Profile): TypedRemapper {
fun create(classPath: ClassPath, profile: Profile, nameMap: NameMap): TypedRemapper {
val inheritedFieldSets = classPath.createInheritedFieldSets()
val inheritedMethodSets = classPath.createInheritedMethodSets()
val classes = ClassMappingGenerator(classPath, profile.excludedClasses).generate()
val classes = ClassMappingGenerator(
classPath,
profile.excludedClasses,
nameMap
).generate()
val fields = FieldMappingGenerator(
classPath,
profile.excludedFields,
nameMap,
inheritedFieldSets,
classes
).generate()
val methods = MethodMappingGenerator(
classPath,
profile.excludedMethods,
nameMap,
inheritedMethodSets
).generate()
@ -81,12 +88,14 @@ class TypedRemapper private constructor(
val staticFields = StaticFieldUnscrambler(
classPath,
profile.excludedFields,
nameMap,
inheritedFieldSets,
staticClassNameGenerator
).unscramble()
val staticMethods = StaticMethodUnscrambler(
classPath,
profile.excludedMethods,
nameMap,
inheritedMethodSets,
staticClassNameGenerator
).unscramble()

@ -3,13 +3,17 @@ package dev.openrs2.deob.transform
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.deob.Profile
import dev.openrs2.deob.map.NameMap
import dev.openrs2.deob.remap.TypedRemapper
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class RemapTransformer @Inject constructor(private val profile: Profile) : Transformer() {
class RemapTransformer @Inject constructor(
private val profile: Profile,
private val nameMap: NameMap
) : Transformer() {
override fun preTransform(classPath: ClassPath) {
classPath.remap(TypedRemapper.create(classPath, profile))
classPath.remap(TypedRemapper.create(classPath, profile, nameMap))
}
}

Loading…
Cancel
Save