forked from openrs2/openrs2
This allows two different classes in different modules to be refactored to the same name - for example, Node in client and unpackclass. Under the hood, it is implemented by prefixing each class name with the library name and an exclamation mark (which is highly unlikely to appear in a class name, as it is invalid Java syntax). At first, prefixing class names with the library name feels like a bit of a hack. However, it is much simpler than trying to track libraries throughout the existing code. Furthermore, it allows us to avoid forking ASM classes like Remapper. The Fernflower driver was also changed to deobfuscate each library in its own context, rather than trying to decompile them all in one go - by the time classes reach Fernflower, the prefixes have already been removed and Fernflower can't deal with duplicate class names either. Signed-off-by: Graham <gpe@openrs2.dev>
parent
7811bc70f4
commit
882cbed44f
@ -0,0 +1,9 @@ |
|||||||
|
package dev.openrs2.decompiler |
||||||
|
|
||||||
|
import java.nio.file.Path |
||||||
|
|
||||||
|
class Library( |
||||||
|
val source: Path, |
||||||
|
val destination: Path, |
||||||
|
val dependencies: List<Path> = emptyList() |
||||||
|
) |
@ -0,0 +1,44 @@ |
|||||||
|
package dev.openrs2.deob.remap |
||||||
|
|
||||||
|
import dev.openrs2.asm.classpath.ExtendedRemapper |
||||||
|
import dev.openrs2.asm.classpath.Library |
||||||
|
|
||||||
|
private val BOUNDARY_CHARS = charArrayOf('/', '!') |
||||||
|
|
||||||
|
fun String.splitAtLibraryBoundary(): Pair<String, String> { |
||||||
|
val index = indexOf('!') |
||||||
|
return Pair(substring(0, index), substring(index + 1)) |
||||||
|
} |
||||||
|
|
||||||
|
fun String.getLibraryAndPackageName(): String { |
||||||
|
return substring(0, lastIndexOfAny(BOUNDARY_CHARS) + 1) |
||||||
|
} |
||||||
|
|
||||||
|
fun String.getClassName(): String { |
||||||
|
return substring(lastIndexOfAny(BOUNDARY_CHARS) + 1) |
||||||
|
} |
||||||
|
|
||||||
|
class ClassNamePrefixRemapper(vararg libraries: Library) : ExtendedRemapper() { |
||||||
|
private val mapping = mutableMapOf<String, String>() |
||||||
|
|
||||||
|
init { |
||||||
|
for (library in libraries) { |
||||||
|
for (clazz in library) { |
||||||
|
require(!clazz.name.contains('!')) { |
||||||
|
"Input class name contains !, which conflicts with library separator" |
||||||
|
} |
||||||
|
mapping.putIfAbsent(clazz.name, "${library.name}!${clazz.name}") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun map(internalName: String): String { |
||||||
|
return mapping.getOrDefault(internalName, internalName) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
object StripClassNamePrefixRemapper : ExtendedRemapper() { |
||||||
|
override fun map(internalName: String): String { |
||||||
|
return internalName.substring(internalName.indexOf('!') + 1) |
||||||
|
} |
||||||
|
} |
@ -1,29 +0,0 @@ |
|||||||
package dev.openrs2.deob.remap |
|
||||||
|
|
||||||
import dev.openrs2.asm.classpath.ExtendedRemapper |
|
||||||
import dev.openrs2.asm.classpath.Library |
|
||||||
import dev.openrs2.asm.filter.ClassFilter |
|
||||||
|
|
||||||
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)) { |
|
||||||
classes += clazz.name |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return PrefixRemapper(prefix, classes) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,36 +1,36 @@ |
|||||||
--- |
--- |
||||||
excluded_classes: |
excluded_classes: |
||||||
- "client" |
- "*!client" |
||||||
- "com/sun/opengl/impl/x11/**" |
- "*!com/sun/opengl/impl/x11/**" |
||||||
- "jagex3/jagmisc/jagmisc" |
- "*!jagex3/jagmisc/jagmisc" |
||||||
- "jaggl/**" |
- "*!jaggl/**" |
||||||
- "javax/media/opengl/**" |
- "*!javax/media/opengl/**" |
||||||
- "loader" |
- "*!loader" |
||||||
- "unpack" |
- "*!unpack" |
||||||
- "unpackclass" |
- "*!unpackclass" |
||||||
excluded_methods: |
excluded_methods: |
||||||
- "**.<clinit> *" |
- "*!**.<clinit> *" |
||||||
- "**.<init> *" |
- "*!**.<init> *" |
||||||
- "**.main *" |
- "*!**.main *" |
||||||
- "**.providesignlink *" |
- "*!**.providesignlink *" |
||||||
- "**.quit *" |
- "*!**.quit *" |
||||||
- "com/sun/opengl/impl/x11/**.* *" |
- "*!com/sun/opengl/impl/x11/**.* *" |
||||||
- "jaggl/**.* *" |
- "*!jaggl/**.* *" |
||||||
- "javax/media/opengl/**.* *" |
- "*!javax/media/opengl/**.* *" |
||||||
excluded_fields: |
excluded_fields: |
||||||
- "**.cache *" |
- "*!**.cache *" |
||||||
- "com/sun/opengl/impl/x11/**.* *" |
- "*!com/sun/opengl/impl/x11/**.* *" |
||||||
- "jaggl/**.* *" |
- "*!jaggl/**.* *" |
||||||
- "javax/media/opengl/**.* *" |
- "*!javax/media/opengl/**.* *" |
||||||
entry_points: |
entry_points: |
||||||
- "**.<clinit> *" |
- "*!**.<clinit> *" |
||||||
- "**.main *" |
- "*!**.main *" |
||||||
- "**.providesignlink *" |
- "*!**.providesignlink *" |
||||||
- "client.<init> *" |
- "*!client.<init> *" |
||||||
- "com/sun/opengl/impl/x11/DRIHack.begin *" |
- "*!com/sun/opengl/impl/x11/DRIHack.begin *" |
||||||
- "com/sun/opengl/impl/x11/DRIHack.end *" |
- "*!com/sun/opengl/impl/x11/DRIHack.end *" |
||||||
- "loader.<init> *" |
- "*!loader.<init> *" |
||||||
- "unpackclass.<init> *" |
- "*!unpackclass.<init> *" |
||||||
scrambled_libraries: |
scrambled_libraries: |
||||||
- client |
- client |
||||||
max_obfuscated_name_len: 2 |
max_obfuscated_name_len: 2 |
||||||
|
Loading…
Reference in new issue