Inject transformers in the bundler and deobfuscator

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent d07714a37d
commit 05a03d5bdc
  1. 2
      asm/src/main/java/dev/openrs2/asm/transform/Transformer.kt
  2. 1
      bundler/build.gradle.kts
  3. 26
      bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
  4. 22
      bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt
  5. 8
      bundler/src/main/java/dev/openrs2/bundler/BundlerQualifier.kt
  6. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/BufferSizeTransformer.kt
  7. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.kt
  8. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/HostCheckTransformer.kt
  9. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/LoadLibraryTransformer.kt
  10. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/MacResizeTransformer.kt
  11. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/PlatformDetectionTransformer.kt
  12. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.kt
  13. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/TypoTransformer.kt
  14. 6
      deob/src/main/java/dev/openrs2/deob/DeobfuscateCommand.kt
  15. 78
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt
  16. 72
      deob/src/main/java/dev/openrs2/deob/DeobfuscatorModule.kt
  17. 8
      deob/src/main/java/dev/openrs2/deob/DeobfuscatorQualifier.kt
  18. 2
      deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.kt
  19. 2
      deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.kt
  20. 24
      deob/src/main/java/dev/openrs2/deob/transform/BundlerTransformer.kt
  21. 2
      deob/src/main/java/dev/openrs2/deob/transform/CanvasTransformer.kt
  22. 2
      deob/src/main/java/dev/openrs2/deob/transform/ClassLiteralTransformer.kt
  23. 2
      deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt
  24. 2
      deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.kt
  25. 2
      deob/src/main/java/dev/openrs2/deob/transform/EmptyClassTransformer.kt
  26. 2
      deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.kt
  27. 2
      deob/src/main/java/dev/openrs2/deob/transform/FernflowerExceptionTransformer.kt
  28. 2
      deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.kt
  29. 2
      deob/src/main/java/dev/openrs2/deob/transform/FinalTransformer.kt
  30. 2
      deob/src/main/java/dev/openrs2/deob/transform/InvokeSpecialTransformer.kt
  31. 2
      deob/src/main/java/dev/openrs2/deob/transform/MethodOrderTransformer.kt
  32. 2
      deob/src/main/java/dev/openrs2/deob/transform/MonitorTransformer.kt
  33. 2
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt
  34. 2
      deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.kt
  35. 2
      deob/src/main/java/dev/openrs2/deob/transform/OriginalPcRestoreTransformer.kt
  36. 2
      deob/src/main/java/dev/openrs2/deob/transform/OriginalPcSaveTransformer.kt
  37. 2
      deob/src/main/java/dev/openrs2/deob/transform/OverrideTransformer.kt
  38. 2
      deob/src/main/java/dev/openrs2/deob/transform/RedundantGotoTransformer.kt
  39. 2
      deob/src/main/java/dev/openrs2/deob/transform/RemapTransformer.kt
  40. 2
      deob/src/main/java/dev/openrs2/deob/transform/ResetTransformer.kt
  41. 2
      deob/src/main/java/dev/openrs2/deob/transform/StaticScramblingTransformer.kt
  42. 2
      deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt
  43. 2
      deob/src/main/java/dev/openrs2/deob/transform/UnusedLocalTransformer.kt
  44. 2
      deob/src/main/java/dev/openrs2/deob/transform/UnusedMethodTransformer.kt
  45. 2
      deob/src/main/java/dev/openrs2/deob/transform/VisibilityTransformer.kt

@ -8,7 +8,7 @@ import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
abstract class Transformer { abstract class Transformer {
fun transform(classPath: ClassPath) { open fun transform(classPath: ClassPath) {
preTransform(classPath) preTransform(classPath)
var changed: Boolean var changed: Boolean

@ -11,6 +11,7 @@ application {
dependencies { dependencies {
api(project(":asm")) api(project(":asm"))
api("com.github.ajalt:clikt:${Versions.clikt}") api("com.github.ajalt:clikt:${Versions.clikt}")
api("com.google.inject:guice:${Versions.guice}")
implementation(project(":crypto")) implementation(project(":crypto"))
implementation("dev.openrs2:openrs2-natives-all:${Versions.openrs2Natives}") implementation("dev.openrs2:openrs2-natives-all:${Versions.openrs2Natives}")

@ -3,16 +3,8 @@ package dev.openrs2.bundler
import com.github.michaelbull.logging.InlineLogger import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library import dev.openrs2.asm.classpath.Library
import dev.openrs2.bundler.transform.BufferSizeTransformer import dev.openrs2.asm.transform.Transformer
import dev.openrs2.bundler.transform.CachePathTransformer
import dev.openrs2.bundler.transform.HostCheckTransformer
import dev.openrs2.bundler.transform.LoadLibraryTransformer
import dev.openrs2.bundler.transform.MacResizeTransformer
import dev.openrs2.bundler.transform.PlatformDetectionTransformer
import dev.openrs2.bundler.transform.PublicKeyTransformer
import dev.openrs2.bundler.transform.ResourceTransformer import dev.openrs2.bundler.transform.ResourceTransformer
import dev.openrs2.bundler.transform.RightClickTransformer
import dev.openrs2.bundler.transform.TypoTransformer
import dev.openrs2.crypto.Pkcs12KeyStore import dev.openrs2.crypto.Pkcs12KeyStore
import java.nio.file.Path import java.nio.file.Path
import java.util.jar.Attributes import java.util.jar.Attributes
@ -22,9 +14,9 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
class Bundler @Inject constructor(publicKeyTransformer: PublicKeyTransformer) { class Bundler @Inject constructor(
private val transformers = TRANSFORMERS + publicKeyTransformer @BundlerQualifier private val transformers: Set<@JvmSuppressWildcards Transformer>
) {
fun run(input: Path, output: Path, keyStorePath: Path) { fun run(input: Path, output: Path, keyStorePath: Path) {
// read input jars/packs // read input jars/packs
logger.info { "Reading input jars" } logger.info { "Reading input jars" }
@ -118,16 +110,6 @@ class Bundler @Inject constructor(publicKeyTransformer: PublicKeyTransformer) {
companion object { companion object {
private val logger = InlineLogger() private val logger = InlineLogger()
val TRANSFORMERS = listOf(
BufferSizeTransformer(),
CachePathTransformer(),
HostCheckTransformer(),
MacResizeTransformer(),
RightClickTransformer(),
LoadLibraryTransformer(),
PlatformDetectionTransformer(),
TypoTransformer()
)
private val unsignedManifest = Manifest() private val unsignedManifest = Manifest()
private val signedManifest: Manifest private val signedManifest: Manifest

@ -1,10 +1,32 @@
package dev.openrs2.bundler package dev.openrs2.bundler
import com.google.inject.AbstractModule import com.google.inject.AbstractModule
import com.google.inject.multibindings.Multibinder
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.bundler.transform.BufferSizeTransformer
import dev.openrs2.bundler.transform.CachePathTransformer
import dev.openrs2.bundler.transform.HostCheckTransformer
import dev.openrs2.bundler.transform.LoadLibraryTransformer
import dev.openrs2.bundler.transform.MacResizeTransformer
import dev.openrs2.bundler.transform.PlatformDetectionTransformer
import dev.openrs2.bundler.transform.PublicKeyTransformer
import dev.openrs2.bundler.transform.RightClickTransformer
import dev.openrs2.bundler.transform.TypoTransformer
import dev.openrs2.crypto.CryptoModule import dev.openrs2.crypto.CryptoModule
object BundlerModule : AbstractModule() { object BundlerModule : AbstractModule() {
override fun configure() { override fun configure() {
install(CryptoModule) install(CryptoModule)
val binder = Multibinder.newSetBinder(binder(), Transformer::class.java, BundlerQualifier::class.java)
binder.addBinding().to(BufferSizeTransformer::class.java)
binder.addBinding().to(CachePathTransformer::class.java)
binder.addBinding().to(HostCheckTransformer::class.java)
binder.addBinding().to(LoadLibraryTransformer::class.java)
binder.addBinding().to(MacResizeTransformer::class.java)
binder.addBinding().to(PlatformDetectionTransformer::class.java)
binder.addBinding().to(PublicKeyTransformer::class.java)
binder.addBinding().to(RightClickTransformer::class.java)
binder.addBinding().to(TypoTransformer::class.java)
} }
} }

@ -0,0 +1,8 @@
package dev.openrs2.bundler
import javax.inject.Qualifier
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION)
annotation class BundlerQualifier

@ -12,7 +12,9 @@ import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class BufferSizeTransformer : Transformer() { class BufferSizeTransformer : Transformer() {
private var buffer: MemberRef? = null private var buffer: MemberRef? = null
private var buffersResized = 0 private var buffersResized = 0

@ -7,7 +7,9 @@ import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class CachePathTransformer : Transformer() { class CachePathTransformer : Transformer() {
private var paths = 0 private var paths = 0

@ -11,7 +11,9 @@ import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.InsnNode import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class HostCheckTransformer : Transformer() { class HostCheckTransformer : Transformer() {
private var hostChecks = 0 private var hostChecks = 0

@ -8,7 +8,9 @@ import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class LoadLibraryTransformer : Transformer() { class LoadLibraryTransformer : Transformer() {
private var jnilibs = 0 private var jnilibs = 0
private var amd64Checks = 0 private var amd64Checks = 0

@ -12,7 +12,9 @@ import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class MacResizeTransformer : Transformer() { class MacResizeTransformer : Transformer() {
private var branchesRemoved = 0 private var branchesRemoved = 0

@ -19,7 +19,9 @@ import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class PlatformDetectionTransformer : Transformer() { class PlatformDetectionTransformer : Transformer() {
private var glBlocks = 0 private var glBlocks = 0
private var miscBlocks = 0 private var miscBlocks = 0

@ -11,7 +11,9 @@ import org.objectweb.asm.tree.InsnList
import org.objectweb.asm.tree.InsnNode import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class RightClickTransformer : Transformer() { class RightClickTransformer : Transformer() {
private var metaDownCalls = 0 private var metaDownCalls = 0

@ -7,7 +7,9 @@ import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class TypoTransformer : Transformer() { class TypoTransformer : Transformer() {
private var errorsFixed = 0 private var errorsFixed = 0

@ -1,13 +1,15 @@
package dev.openrs2.deob package dev.openrs2.deob
import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.CliktCommand
import com.google.inject.Guice
import java.nio.file.Paths import java.nio.file.Paths
fun main(args: Array<String>) = DeobfuscateCommand().main(args) fun main(args: Array<String>) = DeobfuscateCommand().main(args)
class DeobfuscateCommand : CliktCommand(name = "deob") { class DeobfuscateCommand : CliktCommand(name = "deob") {
override fun run() { override fun run() {
val deobfuscator = Deobfuscator(Paths.get("nonfree/lib"), Paths.get("nonfree/var/cache/deob")) val injector = Guice.createInjector(DeobfuscatorModule)
deobfuscator.run() val deobfuscator = injector.getInstance(Deobfuscator::class.java)
deobfuscator.run(Paths.get("nonfree/lib"), Paths.get("nonfree/var/cache/deob"))
} }
} }

@ -5,42 +5,19 @@ import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.classpath.Library.Companion.readJar import dev.openrs2.asm.classpath.Library.Companion.readJar
import dev.openrs2.asm.classpath.Library.Companion.readPack import dev.openrs2.asm.classpath.Library.Companion.readPack
import dev.openrs2.bundler.Bundler import dev.openrs2.asm.transform.Transformer
import dev.openrs2.bundler.transform.ResourceTransformer
import dev.openrs2.deob.SignedClassUtils.move import dev.openrs2.deob.SignedClassUtils.move
import dev.openrs2.deob.remap.PrefixRemapper.create import dev.openrs2.deob.remap.PrefixRemapper.create
import dev.openrs2.deob.transform.BitShiftTransformer
import dev.openrs2.deob.transform.BitwiseOpTransformer
import dev.openrs2.deob.transform.CanvasTransformer
import dev.openrs2.deob.transform.ClassLiteralTransformer
import dev.openrs2.deob.transform.ConstantArgTransformer
import dev.openrs2.deob.transform.CounterTransformer
import dev.openrs2.deob.transform.EmptyClassTransformer
import dev.openrs2.deob.transform.ExceptionTracingTransformer
import dev.openrs2.deob.transform.FernflowerExceptionTransformer
import dev.openrs2.deob.transform.FieldOrderTransformer
import dev.openrs2.deob.transform.FinalTransformer
import dev.openrs2.deob.transform.InvokeSpecialTransformer
import dev.openrs2.deob.transform.MethodOrderTransformer
import dev.openrs2.deob.transform.MonitorTransformer
import dev.openrs2.deob.transform.OpaquePredicateTransformer
import dev.openrs2.deob.transform.OriginalNameTransformer
import dev.openrs2.deob.transform.OriginalPcRestoreTransformer
import dev.openrs2.deob.transform.OriginalPcSaveTransformer
import dev.openrs2.deob.transform.OverrideTransformer
import dev.openrs2.deob.transform.RedundantGotoTransformer
import dev.openrs2.deob.transform.RemapTransformer
import dev.openrs2.deob.transform.ResetTransformer
import dev.openrs2.deob.transform.StaticScramblingTransformer
import dev.openrs2.deob.transform.UnusedArgTransformer
import dev.openrs2.deob.transform.UnusedLocalTransformer
import dev.openrs2.deob.transform.UnusedMethodTransformer
import dev.openrs2.deob.transform.VisibilityTransformer
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import javax.inject.Inject
class Deobfuscator(private val input: Path, private val output: Path) { import javax.inject.Singleton
fun run() {
@Singleton
class Deobfuscator @Inject constructor(
@DeobfuscatorQualifier private val transformers: Set<@JvmSuppressWildcards Transformer>
) {
fun run(input: Path, output: Path) {
// read input jars/packs // read input jars/packs
logger.info { "Reading input jars" } logger.info { "Reading input jars" }
val unpackClass = readJar(input.resolve("unpackclass.pack")) val unpackClass = readJar(input.resolve("unpackclass.pack"))
@ -102,19 +79,19 @@ class Deobfuscator(private val input: Path, private val output: Path) {
// deobfuscate // deobfuscate
logger.info { "Transforming client" } logger.info { "Transforming client" }
for (transformer in TRANSFORMERS) { for (transformer in transformers) {
logger.info { "Running transformer ${transformer.javaClass.simpleName} " } logger.info { "Running transformer ${transformer.javaClass.simpleName} " }
transformer.transform(classPath) transformer.transform(classPath)
} }
logger.info { "Transforming client_gl" } logger.info { "Transforming client_gl" }
for (transformer in TRANSFORMERS) { for (transformer in transformers) {
logger.info { "Running transformer ${transformer.javaClass.simpleName} " } logger.info { "Running transformer ${transformer.javaClass.simpleName} " }
transformer.transform(glClassPath) transformer.transform(glClassPath)
} }
logger.info { "Transforming client_unsigned" } logger.info { "Transforming client_unsigned" }
for (transformer in TRANSFORMERS) { for (transformer in transformers) {
logger.info { "Running transformer ${transformer.javaClass.simpleName} " } logger.info { "Running transformer ${transformer.javaClass.simpleName} " }
transformer.transform(unsignedClassPath) transformer.transform(unsignedClassPath)
} }
@ -142,36 +119,5 @@ class Deobfuscator(private val input: Path, private val output: Path) {
companion object { companion object {
private val logger = InlineLogger() private val logger = InlineLogger()
private val TRANSFORMERS = listOf(
OriginalPcSaveTransformer(),
OriginalNameTransformer(),
*Bundler.TRANSFORMERS.toTypedArray(),
ResourceTransformer(),
OpaquePredicateTransformer(),
ExceptionTracingTransformer(),
MonitorTransformer(),
BitShiftTransformer(),
CanvasTransformer(),
FieldOrderTransformer(),
BitwiseOpTransformer(),
RemapTransformer(),
ConstantArgTransformer(),
UnusedLocalTransformer(),
UnusedMethodTransformer(),
UnusedArgTransformer(),
CounterTransformer(),
ResetTransformer(),
ClassLiteralTransformer(),
InvokeSpecialTransformer(),
StaticScramblingTransformer(),
EmptyClassTransformer(),
MethodOrderTransformer(),
VisibilityTransformer(),
FinalTransformer(),
OverrideTransformer(),
RedundantGotoTransformer(),
OriginalPcRestoreTransformer(),
FernflowerExceptionTransformer()
)
} }
} }

@ -0,0 +1,72 @@
package dev.openrs2.deob
import com.google.inject.AbstractModule
import com.google.inject.multibindings.Multibinder
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.bundler.BundlerModule
import dev.openrs2.bundler.transform.ResourceTransformer
import dev.openrs2.deob.transform.BitShiftTransformer
import dev.openrs2.deob.transform.BitwiseOpTransformer
import dev.openrs2.deob.transform.BundlerTransformer
import dev.openrs2.deob.transform.CanvasTransformer
import dev.openrs2.deob.transform.ClassLiteralTransformer
import dev.openrs2.deob.transform.ConstantArgTransformer
import dev.openrs2.deob.transform.CounterTransformer
import dev.openrs2.deob.transform.EmptyClassTransformer
import dev.openrs2.deob.transform.ExceptionTracingTransformer
import dev.openrs2.deob.transform.FernflowerExceptionTransformer
import dev.openrs2.deob.transform.FieldOrderTransformer
import dev.openrs2.deob.transform.FinalTransformer
import dev.openrs2.deob.transform.InvokeSpecialTransformer
import dev.openrs2.deob.transform.MethodOrderTransformer
import dev.openrs2.deob.transform.MonitorTransformer
import dev.openrs2.deob.transform.OpaquePredicateTransformer
import dev.openrs2.deob.transform.OriginalNameTransformer
import dev.openrs2.deob.transform.OriginalPcRestoreTransformer
import dev.openrs2.deob.transform.OriginalPcSaveTransformer
import dev.openrs2.deob.transform.OverrideTransformer
import dev.openrs2.deob.transform.RedundantGotoTransformer
import dev.openrs2.deob.transform.RemapTransformer
import dev.openrs2.deob.transform.ResetTransformer
import dev.openrs2.deob.transform.StaticScramblingTransformer
import dev.openrs2.deob.transform.UnusedArgTransformer
import dev.openrs2.deob.transform.UnusedLocalTransformer
import dev.openrs2.deob.transform.UnusedMethodTransformer
import dev.openrs2.deob.transform.VisibilityTransformer
object DeobfuscatorModule : AbstractModule() {
override fun configure() {
install(BundlerModule)
val binder = Multibinder.newSetBinder(binder(), Transformer::class.java, DeobfuscatorQualifier::class.java)
binder.addBinding().to(OriginalPcSaveTransformer::class.java)
binder.addBinding().to(OriginalNameTransformer::class.java)
binder.addBinding().to(BundlerTransformer::class.java)
binder.addBinding().to(ResourceTransformer::class.java)
binder.addBinding().to(OpaquePredicateTransformer::class.java)
binder.addBinding().to(ExceptionTracingTransformer::class.java)
binder.addBinding().to(MonitorTransformer::class.java)
binder.addBinding().to(BitShiftTransformer::class.java)
binder.addBinding().to(CanvasTransformer::class.java)
binder.addBinding().to(FieldOrderTransformer::class.java)
binder.addBinding().to(BitwiseOpTransformer::class.java)
binder.addBinding().to(RemapTransformer::class.java)
binder.addBinding().to(ConstantArgTransformer::class.java)
binder.addBinding().to(UnusedLocalTransformer::class.java)
binder.addBinding().to(UnusedMethodTransformer::class.java)
binder.addBinding().to(UnusedArgTransformer::class.java)
binder.addBinding().to(CounterTransformer::class.java)
binder.addBinding().to(ResetTransformer::class.java)
binder.addBinding().to(ClassLiteralTransformer::class.java)
binder.addBinding().to(InvokeSpecialTransformer::class.java)
binder.addBinding().to(StaticScramblingTransformer::class.java)
binder.addBinding().to(EmptyClassTransformer::class.java)
binder.addBinding().to(MethodOrderTransformer::class.java)
binder.addBinding().to(VisibilityTransformer::class.java)
binder.addBinding().to(FinalTransformer::class.java)
binder.addBinding().to(OverrideTransformer::class.java)
binder.addBinding().to(RedundantGotoTransformer::class.java)
binder.addBinding().to(OriginalPcRestoreTransformer::class.java)
binder.addBinding().to(FernflowerExceptionTransformer::class.java)
}
}

@ -0,0 +1,8 @@
package dev.openrs2.deob
import javax.inject.Qualifier
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION)
annotation class DeobfuscatorQualifier

@ -10,7 +10,9 @@ import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class BitShiftTransformer : Transformer() { class BitShiftTransformer : Transformer() {
private var simplified = 0 private var simplified = 0

@ -13,7 +13,9 @@ import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class BitwiseOpTransformer : Transformer() { class BitwiseOpTransformer : Transformer() {
private val methodOps = mutableMapOf<MemberRef, Int>() private val methodOps = mutableMapOf<MemberRef, Int>()
private var inlinedOps = 0 private var inlinedOps = 0

@ -0,0 +1,24 @@
package dev.openrs2.deob.transform
import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.bundler.BundlerQualifier
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BundlerTransformer @Inject constructor(
@BundlerQualifier private val transformers: Set<@JvmSuppressWildcards Transformer>
) : Transformer() {
override fun transform(classPath: ClassPath) {
for (transformer in transformers) {
logger.info { "Running transformer ${transformer.javaClass.simpleName}" }
transformer.transform(classPath)
}
}
companion object {
private val logger = InlineLogger()
}
}

@ -5,7 +5,9 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import javax.inject.Singleton
@Singleton
class CanvasTransformer : Transformer() { class CanvasTransformer : Transformer() {
override fun transformClass( override fun transformClass(
classPath: ClassPath, classPath: ClassPath,

@ -15,7 +15,9 @@ import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class ClassLiteralTransformer : Transformer() { class ClassLiteralTransformer : Transformer() {
private val classForNameMethods = mutableListOf<MemberRef>() private val classForNameMethods = mutableListOf<MemberRef>()
private var classLiterals = 0 private var classLiterals = 0

@ -43,7 +43,9 @@ import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.analysis.Analyzer import org.objectweb.asm.tree.analysis.Analyzer
import javax.inject.Singleton
@Singleton
class ConstantArgTransformer : Transformer() { class ConstantArgTransformer : Transformer() {
private val pendingMethods = LinkedHashSet<MemberRef>() private val pendingMethods = LinkedHashSet<MemberRef>()
private val arglessMethods = mutableSetOf<DisjointSet.Partition<MemberRef>>() private val arglessMethods = mutableSetOf<DisjointSet.Partition<MemberRef>>()

@ -10,7 +10,9 @@ import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class CounterTransformer : Transformer() { class CounterTransformer : Transformer() {
private val counters = mutableSetOf<MemberRef>() private val counters = mutableSetOf<MemberRef>()

@ -11,7 +11,9 @@ import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.TypeInsnNode import org.objectweb.asm.tree.TypeInsnNode
import javax.inject.Singleton
@Singleton
class EmptyClassTransformer : Transformer() { class EmptyClassTransformer : Transformer() {
private var removedClasses = 0 private var removedClasses = 0
private val emptyClasses = mutableSetOf<String>() private val emptyClasses = mutableSetOf<String>()

@ -8,6 +8,7 @@ import dev.openrs2.asm.nextReal
import dev.openrs2.asm.transform.Transformer import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
/** /**
* A [Transformer] responsible for removing two kinds of redundant exception * A [Transformer] responsible for removing two kinds of redundant exception
@ -27,6 +28,7 @@ import org.objectweb.asm.tree.MethodNode
* and not obfuscation, it is clearly automatically-generated and thus we * and not obfuscation, it is clearly automatically-generated and thus we
* remove these exception handlers too. * remove these exception handlers too.
*/ */
@Singleton
class ExceptionTracingTransformer : Transformer() { class ExceptionTracingTransformer : Transformer() {
private var tracingTryCatches = 0 private var tracingTryCatches = 0

@ -9,7 +9,9 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.InsnNode import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class FernflowerExceptionTransformer : Transformer() { class FernflowerExceptionTransformer : Transformer() {
private var nopsInserted = 0 private var nopsInserted = 0

@ -8,7 +8,9 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.FieldNode import org.objectweb.asm.tree.FieldNode
import javax.inject.Singleton
@Singleton
class FieldOrderTransformer : Transformer() { class FieldOrderTransformer : Transformer() {
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean { override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
sortFields(clazz, CONSTRUCTOR, Opcodes.PUTFIELD) sortFields(clazz, CONSTRUCTOR, Opcodes.PUTFIELD)

@ -9,7 +9,9 @@ import dev.openrs2.util.collect.DisjointSet
import org.objectweb.asm.Opcodes import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class FinalTransformer : Transformer() { class FinalTransformer : Transformer() {
private val superClasses = mutableListOf<String>() private val superClasses = mutableListOf<String>()
private lateinit var inheritedMethodSets: DisjointSet<MemberRef> private lateinit var inheritedMethodSets: DisjointSet<MemberRef>

@ -8,6 +8,7 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
/** /**
* A [Transformer] that replaces `INVOKESPECIAL` instructions in static methods * A [Transformer] that replaces `INVOKESPECIAL` instructions in static methods
@ -47,6 +48,7 @@ import org.objectweb.asm.tree.MethodNode
* instructions where possible, allowing the [StaticScramblingTransformer] to * instructions where possible, allowing the [StaticScramblingTransformer] to
* produce verifiable output. * produce verifiable output.
*/ */
@Singleton
class InvokeSpecialTransformer : Transformer() { class InvokeSpecialTransformer : Transformer() {
private var invokeSpecialsReplaced = 0 private var invokeSpecialsReplaced = 0

@ -6,7 +6,9 @@ import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class MethodOrderTransformer : Transformer() { class MethodOrderTransformer : Transformer() {
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean { override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
clazz.methods.sortWith(STATIC_COMPARATOR.then(INIT_COMPARATOR)) clazz.methods.sortWith(STATIC_COMPARATOR.then(INIT_COMPARATOR))

@ -15,6 +15,7 @@ import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.JumpInsnNode import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.LabelNode import org.objectweb.asm.tree.LabelNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
/** /**
* A [Transformer] that rewrites `synchronized` blocks produced by older * A [Transformer] that rewrites `synchronized` blocks produced by older
@ -41,6 +42,7 @@ import org.objectweb.asm.tree.MethodNode
* handler pointing to the same `MONITOREXIT` sequence. Adding this isn't * handler pointing to the same `MONITOREXIT` sequence. Adding this isn't
* necessary for Fernflower compatibility. * necessary for Fernflower compatibility.
*/ */
@Singleton
class MonitorTransformer : Transformer() { class MonitorTransformer : Transformer() {
private var subroutinesInlined = 0 private var subroutinesInlined = 0
private var tryRangesExtended = 0 private var tryRangesExtended = 0

@ -14,7 +14,9 @@ import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.JumpInsnNode import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class OpaquePredicateTransformer : Transformer() { class OpaquePredicateTransformer : Transformer() {
private val flowObstructors = mutableSetOf<MemberRef>() private val flowObstructors = mutableSetOf<MemberRef>()
private var opaquePredicates = 0 private var opaquePredicates = 0

@ -11,7 +11,9 @@ import org.objectweb.asm.tree.AnnotationNode
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldNode import org.objectweb.asm.tree.FieldNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class OriginalNameTransformer : Transformer() { class OriginalNameTransformer : Transformer() {
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean { override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
if (clazz.invisibleAnnotations == null) { if (clazz.invisibleAnnotations == null) {

@ -9,7 +9,9 @@ import dev.openrs2.deob.OriginalPcTable
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.LabelNode import org.objectweb.asm.tree.LabelNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class OriginalPcRestoreTransformer : Transformer() { class OriginalPcRestoreTransformer : Transformer() {
private var originalPcsRestored = 0 private var originalPcsRestored = 0

@ -6,7 +6,9 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class OriginalPcSaveTransformer : Transformer() { class OriginalPcSaveTransformer : Transformer() {
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean { override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean {
for ((pc, insn) in method.instructions.filter { it.opcode != -1 }.withIndex()) { for ((pc, insn) in method.instructions.filter { it.opcode != -1 }.withIndex()) {

@ -10,7 +10,9 @@ import org.objectweb.asm.Type
import org.objectweb.asm.tree.AnnotationNode import org.objectweb.asm.tree.AnnotationNode
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class OverrideTransformer : Transformer() { class OverrideTransformer : Transformer() {
private var overrides = 0 private var overrides = 0

@ -10,7 +10,9 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.JumpInsnNode import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class RedundantGotoTransformer : Transformer() { class RedundantGotoTransformer : Transformer() {
private var removed = 0 private var removed = 0

@ -3,7 +3,9 @@ package dev.openrs2.deob.transform
import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.transform.Transformer import dev.openrs2.asm.transform.Transformer
import dev.openrs2.deob.remap.TypedRemapper import dev.openrs2.deob.remap.TypedRemapper
import javax.inject.Singleton
@Singleton
class RemapTransformer : Transformer() { class RemapTransformer : Transformer() {
override fun preTransform(classPath: ClassPath) { override fun preTransform(classPath: ClassPath) {
classPath.remap(TypedRemapper.create(classPath)) classPath.remap(TypedRemapper.create(classPath))

@ -16,7 +16,9 @@ import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class ResetTransformer : Transformer() { class ResetTransformer : Transformer() {
private val resetMethods = mutableSetOf<MemberRef>() private val resetMethods = mutableSetOf<MemberRef>()

@ -18,8 +18,10 @@ import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.LabelNode import org.objectweb.asm.tree.LabelNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
import kotlin.math.max import kotlin.math.max
@Singleton
class StaticScramblingTransformer : Transformer() { class StaticScramblingTransformer : Transformer() {
private class FieldSet(val owner: ClassNode, val fields: List<FieldNode>, val clinit: MethodNode?) { private class FieldSet(val owner: ClassNode, val fields: List<FieldNode>, val clinit: MethodNode?) {
val dependencies = clinit?.instructions val dependencies = clinit?.instructions

@ -20,7 +20,9 @@ import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode import org.objectweb.asm.tree.VarInsnNode
import org.objectweb.asm.tree.analysis.Analyzer import org.objectweb.asm.tree.analysis.Analyzer
import javax.inject.Singleton
@Singleton
class UnusedArgTransformer : Transformer() { class UnusedArgTransformer : Transformer() {
private val retainedArgs = mutableSetOf<ArgRef>() private val retainedArgs = mutableSetOf<ArgRef>()
private lateinit var inheritedMethodSets: DisjointSet<MemberRef> private lateinit var inheritedMethodSets: DisjointSet<MemberRef>

@ -12,7 +12,9 @@ import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.tree.VarInsnNode import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class UnusedLocalTransformer : Transformer() { class UnusedLocalTransformer : Transformer() {
private var localsRemoved = 0 private var localsRemoved = 0

@ -14,7 +14,9 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class UnusedMethodTransformer : Transformer() { class UnusedMethodTransformer : Transformer() {
private lateinit var inheritedMethodSets: DisjointSet<MemberRef> private lateinit var inheritedMethodSets: DisjointSet<MemberRef>
private val methodReferences = HashMultimap.create<DisjointSet.Partition<MemberRef>, MemberRef>() private val methodReferences = HashMultimap.create<DisjointSet.Partition<MemberRef>, MemberRef>()

@ -16,7 +16,9 @@ import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.FieldInsnNode import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.MethodInsnNode import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class VisibilityTransformer : Transformer() { class VisibilityTransformer : Transformer() {
private lateinit var inheritedFieldSets: DisjointSet<MemberRef> private lateinit var inheritedFieldSets: DisjointSet<MemberRef>
private lateinit var inheritedMethodSets: DisjointSet<MemberRef> private lateinit var inheritedMethodSets: DisjointSet<MemberRef>

Loading…
Cancel
Save