Remap argument names

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent 33955a57ad
commit 8dd5292cb2
  1. 14
      asm/src/main/java/dev/openrs2/asm/ClassNodeRemapper.kt
  2. 10
      asm/src/main/java/dev/openrs2/asm/classpath/ExtendedRemapper.kt
  3. 5
      deob/src/main/java/dev/openrs2/deob/ArgRef.kt
  4. 21
      deob/src/main/java/dev/openrs2/deob/remap/ArgumentMappingGenerator.kt
  5. 15
      deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt

@ -1,6 +1,7 @@
package dev.openrs2.asm
import dev.openrs2.asm.classpath.ExtendedRemapper
import org.objectweb.asm.Type
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
@ -13,6 +14,7 @@ import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.MultiANewArrayInsnNode
import org.objectweb.asm.tree.ParameterNode
import org.objectweb.asm.tree.TypeInsnNode
fun ClassNode.remap(remapper: ExtendedRemapper) {
@ -57,6 +59,14 @@ fun FieldNode.remap(remapper: ExtendedRemapper, owner: String) {
}
fun MethodNode.remap(remapper: ExtendedRemapper, owner: String) {
if (parameters == null) {
parameters = List(Type.getArgumentTypes(desc).size) { ParameterNode(null, 0) }
}
for ((index, parameter) in parameters.withIndex()) {
parameter.remap(remapper, owner, name, desc, index)
}
name = remapper.mapMethodName(owner, name, desc)
desc = remapper.mapMethodDesc(desc)
signature = remapper.mapSignature(signature, false)
@ -75,6 +85,10 @@ fun MethodNode.remap(remapper: ExtendedRemapper, owner: String) {
}
}
fun ParameterNode.remap(remapper: ExtendedRemapper, owner: String, methodName: String, desc: String, index: Int) {
name = remapper.mapArgumentName(owner, methodName, desc, index, name)
}
fun AbstractInsnNode.remap(remapper: ExtendedRemapper) {
when (this) {
is FrameNode -> throw UnsupportedOperationException("SKIP_FRAMES and COMPUTE_FRAMES must be used")

@ -15,4 +15,14 @@ abstract class ExtendedRemapper : Remapper() {
open fun mapMethodOwner(owner: String, name: String, descriptor: String): String {
return mapType(owner)
}
open fun mapArgumentName(
owner: String,
name: String,
descriptor: String,
index: Int,
argumentName: String?
): String? {
return argumentName
}
}

@ -0,0 +1,5 @@
package dev.openrs2.deob
import dev.openrs2.asm.MemberRef
data class ArgRef(val method: MemberRef, val index: Int)

@ -0,0 +1,21 @@
package dev.openrs2.deob.remap
import dev.openrs2.deob.ArgRef
import dev.openrs2.deob.util.map.NameMap
class ArgumentMappingGenerator(
private val nameMap: NameMap
) {
fun generate(): Map<ArgRef, String> {
val argumentNames = mutableMapOf<ArgRef, String>()
for ((methodRef, method) in nameMap.methods) {
for ((index, name) in method.arguments) {
val argument = ArgRef(methodRef, index)
argumentNames[argument] = name
}
}
return argumentNames
}
}

@ -5,6 +5,7 @@ import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.ExtendedRemapper
import dev.openrs2.asm.filter.UnionMemberFilter
import dev.openrs2.deob.ArgRef
import dev.openrs2.deob.Profile
import dev.openrs2.deob.filter.BrowserControlFilter
import dev.openrs2.deob.util.map.NameMap
@ -17,6 +18,7 @@ class TypedRemapper private constructor(
private val classes: Map<String, String>,
private val fields: Map<DisjointSet.Partition<MemberRef>, String>,
private val methods: Map<DisjointSet.Partition<MemberRef>, String>,
private val argumentNames: Map<ArgRef, String>,
private val staticFields: Map<DisjointSet.Partition<MemberRef>, StaticField>,
private val staticMethods: Map<DisjointSet.Partition<MemberRef>, String>
) : ExtendedRemapper() {
@ -54,6 +56,17 @@ class TypedRemapper private constructor(
return staticMethods.getOrDefault(partition, mapType(owner))
}
override fun mapArgumentName(
owner: String,
name: String,
descriptor: String,
index: Int,
argumentName: String?
): String? {
val argument = ArgRef(MemberRef(owner, name, descriptor), index)
return argumentNames[argument] ?: argumentName
}
companion object {
private val logger = InlineLogger()
@ -79,6 +92,7 @@ class TypedRemapper private constructor(
nameMap,
inheritedMethodSets
).generate()
val argumentNames = ArgumentMappingGenerator(nameMap).generate()
verifyMapping(classes, profile.maxObfuscatedNameLen)
verifyMemberMapping(fields, profile.maxObfuscatedNameLen)
@ -110,6 +124,7 @@ class TypedRemapper private constructor(
classes,
fields,
methods,
argumentNames,
staticFields,
staticMethods
)

Loading…
Cancel
Save