Add ExtendedRemapper type with support for moving fields/methods

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent 64dc49e15b
commit 113820a9a2
  1. 10
      asm/src/main/java/dev/openrs2/asm/ClassNodeRemapper.kt
  2. 3
      asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.kt
  3. 13
      asm/src/main/java/dev/openrs2/asm/classpath/ExtendedRemapper.kt
  4. 3
      asm/src/main/java/dev/openrs2/asm/classpath/Library.kt
  5. 31
      deob/src/main/java/dev/openrs2/deob/remap/PrefixRemapper.kt
  6. 4
      deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt

@ -1,6 +1,6 @@
package dev.openrs2.asm
import org.objectweb.asm.commons.Remapper
import dev.openrs2.asm.classpath.ExtendedRemapper
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode
@ -11,7 +11,7 @@ import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MultiANewArrayInsnNode
import org.objectweb.asm.tree.TypeInsnNode
fun ClassNode.remap(remapper: Remapper) {
fun ClassNode.remap(remapper: ExtendedRemapper) {
val originalName = name
name = remapper.mapType(originalName)
signature = remapper.mapSignature(signature, false)
@ -45,18 +45,18 @@ fun ClassNode.remap(remapper: Remapper) {
}
}
private fun AbstractInsnNode.remap(remapper: Remapper) {
private fun AbstractInsnNode.remap(remapper: ExtendedRemapper) {
when (this) {
is FrameNode -> throw UnsupportedOperationException("SKIP_FRAMES and COMPUTE_FRAMES must be used")
is FieldInsnNode -> {
val originalOwner = owner
owner = remapper.mapType(originalOwner)
owner = remapper.mapFieldOwner(originalOwner, name, desc)
name = remapper.mapFieldName(originalOwner, name, desc)
desc = remapper.mapDesc(desc)
}
is MethodInsnNode -> {
val originalOwner = owner
owner = remapper.mapType(originalOwner)
owner = remapper.mapMethodOwner(originalOwner, name, desc)
name = remapper.mapMethodName(originalOwner, name, desc)
desc = remapper.mapDesc(desc)
}

@ -6,7 +6,6 @@ import dev.openrs2.asm.toBinaryClassName
import dev.openrs2.util.collect.DisjointSet
import dev.openrs2.util.collect.ForestDisjointSet
import org.objectweb.asm.Opcodes
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
@ -76,7 +75,7 @@ class ClassPath(
return null
}
fun remap(remapper: Remapper) {
fun remap(remapper: ExtendedRemapper) {
for (library in libraries) {
library.remap(remapper)
}

@ -0,0 +1,13 @@
package dev.openrs2.asm.classpath
import org.objectweb.asm.commons.Remapper
abstract class ExtendedRemapper : Remapper() {
open fun mapFieldOwner(owner: String, name: String, desc: String): String {
return mapType(owner)
}
open fun mapMethodOwner(owner: String, name: String, desc: String): String {
return mapType(owner)
}
}

@ -4,7 +4,6 @@ import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.io.LibraryReader
import dev.openrs2.asm.io.LibraryWriter
import dev.openrs2.asm.remap
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.ClassNode
import java.nio.file.Files
import java.nio.file.Path
@ -41,7 +40,7 @@ class Library() : Iterable<ClassNode> {
return classes.values.iterator()
}
fun remap(remapper: Remapper) {
fun remap(remapper: ExtendedRemapper) {
for (clazz in classes.values) {
clazz.remap(remapper)
}

@ -1,22 +1,29 @@
package dev.openrs2.deob.remap
import dev.openrs2.asm.classpath.ExtendedRemapper
import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.filter.ClassFilter
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.commons.SimpleRemapper
object PrefixRemapper {
fun create(library: Library, prefix: String, excluded: ClassFilter): Remapper {
val mapping = mutableMapOf<String, String>()
class PrefixRemapper(private val prefix: String, private val classes: Set<String>) : ExtendedRemapper() {
override fun map(internalName: String): String {
return if (classes.contains(internalName)) {
prefix + internalName
} else {
internalName
}
}
companion object {
fun create(library: Library, prefix: String, excluded: ClassFilter): ExtendedRemapper {
val classes = mutableSetOf<String>()
for (clazz in library) {
if (excluded.matches(clazz.name)) {
mapping[clazz.name] = clazz.name
} else {
mapping[clazz.name] = prefix + clazz.name
for (clazz in library) {
if (!excluded.matches(clazz.name)) {
classes += clazz.name
}
}
}
return SimpleRemapper(mapping)
return PrefixRemapper(prefix, classes)
}
}
}

@ -5,6 +5,7 @@ import dev.openrs2.asm.MemberDesc
import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.classpath.ClassMetadata
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.ExtendedRemapper
import dev.openrs2.asm.filter.ClassFilter
import dev.openrs2.asm.filter.MemberFilter
import dev.openrs2.deob.Profile
@ -12,13 +13,12 @@ import dev.openrs2.util.collect.DisjointSet
import dev.openrs2.util.indefiniteArticle
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.commons.Remapper
class TypedRemapper private constructor(
private val classes: Map<String, String>,
private val fields: Map<MemberRef, String>,
private val methods: Map<MemberRef, String>
) : Remapper() {
) : ExtendedRemapper() {
override fun map(internalName: String): String {
return classes.getOrDefault(internalName, internalName)
}

Loading…
Cancel
Save