Inject transformers in the bundler and deobfuscator

Signed-off-by: Graham <gpe@openrs2.dev>
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
abstract class Transformer {
fun transform(classPath: ClassPath) {
open fun transform(classPath: ClassPath) {
preTransform(classPath)
var changed: Boolean

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

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

@ -1,10 +1,32 @@
package dev.openrs2.bundler
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
object BundlerModule : AbstractModule() {
override fun configure() {
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.LdcInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class BufferSizeTransformer : Transformer() {
private var buffer: MemberRef? = null
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.LdcInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class CachePathTransformer : Transformer() {
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.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class HostCheckTransformer : Transformer() {
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.LdcInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class LoadLibraryTransformer : Transformer() {
private var jnilibs = 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.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class MacResizeTransformer : Transformer() {
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.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class PlatformDetectionTransformer : Transformer() {
private var glBlocks = 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.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class RightClickTransformer : Transformer() {
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.LdcInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class TypoTransformer : Transformer() {
private var errorsFixed = 0

@ -1,13 +1,15 @@
package dev.openrs2.deob
import com.github.ajalt.clikt.core.CliktCommand
import com.google.inject.Guice
import java.nio.file.Paths
fun main(args: Array<String>) = DeobfuscateCommand().main(args)
class DeobfuscateCommand : CliktCommand(name = "deob") {
override fun run() {
val deobfuscator = Deobfuscator(Paths.get("nonfree/lib"), Paths.get("nonfree/var/cache/deob"))
deobfuscator.run()
val injector = Guice.createInjector(DeobfuscatorModule)
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.Companion.readJar
import dev.openrs2.asm.classpath.Library.Companion.readPack
import dev.openrs2.bundler.Bundler
import dev.openrs2.bundler.transform.ResourceTransformer
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.deob.SignedClassUtils.move
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.Path
class Deobfuscator(private val input: Path, private val output: Path) {
fun run() {
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class Deobfuscator @Inject constructor(
@DeobfuscatorQualifier private val transformers: Set<@JvmSuppressWildcards Transformer>
) {
fun run(input: Path, output: Path) {
// read input jars/packs
logger.info { "Reading input jars" }
val unpackClass = readJar(input.resolve("unpackclass.pack"))
@ -102,19 +79,19 @@ class Deobfuscator(private val input: Path, private val output: Path) {
// deobfuscate
logger.info { "Transforming client" }
for (transformer in TRANSFORMERS) {
for (transformer in transformers) {
logger.info { "Running transformer ${transformer.javaClass.simpleName} " }
transformer.transform(classPath)
}
logger.info { "Transforming client_gl" }
for (transformer in TRANSFORMERS) {
for (transformer in transformers) {
logger.info { "Running transformer ${transformer.javaClass.simpleName} " }
transformer.transform(glClassPath)
}
logger.info { "Transforming client_unsigned" }
for (transformer in TRANSFORMERS) {
for (transformer in transformers) {
logger.info { "Running transformer ${transformer.javaClass.simpleName} " }
transformer.transform(unsignedClassPath)
}
@ -142,36 +119,5 @@ class Deobfuscator(private val input: Path, private val output: Path) {
companion object {
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.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class BitShiftTransformer : Transformer() {
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.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class BitwiseOpTransformer : Transformer() {
private val methodOps = mutableMapOf<MemberRef, Int>()
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 org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import javax.inject.Singleton
@Singleton
class CanvasTransformer : Transformer() {
override fun transformClass(
classPath: ClassPath,

@ -15,7 +15,9 @@ import org.objectweb.asm.tree.FieldInsnNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class ClassLiteralTransformer : Transformer() {
private val classForNameMethods = mutableListOf<MemberRef>()
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.MethodNode
import org.objectweb.asm.tree.analysis.Analyzer
import javax.inject.Singleton
@Singleton
class ConstantArgTransformer : Transformer() {
private val pendingMethods = LinkedHashSet<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.FieldInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class CounterTransformer : Transformer() {
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.MethodNode
import org.objectweb.asm.tree.TypeInsnNode
import javax.inject.Singleton
@Singleton
class EmptyClassTransformer : Transformer() {
private var removedClasses = 0
private val emptyClasses = mutableSetOf<String>()

@ -8,6 +8,7 @@ import dev.openrs2.asm.nextReal
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
/**
* 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
* remove these exception handlers too.
*/
@Singleton
class ExceptionTracingTransformer : Transformer() {
private var tracingTryCatches = 0

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

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

@ -9,7 +9,9 @@ import dev.openrs2.util.collect.DisjointSet
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class FinalTransformer : Transformer() {
private val superClasses = mutableListOf<String>()
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.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
/**
* 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
* produce verifiable output.
*/
@Singleton
class InvokeSpecialTransformer : Transformer() {
private var invokeSpecialsReplaced = 0

@ -6,7 +6,9 @@ import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class MethodOrderTransformer : Transformer() {
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
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.LabelNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
/**
* 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
* necessary for Fernflower compatibility.
*/
@Singleton
class MonitorTransformer : Transformer() {
private var subroutinesInlined = 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.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class OpaquePredicateTransformer : Transformer() {
private val flowObstructors = mutableSetOf<MemberRef>()
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.FieldNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class OriginalNameTransformer : Transformer() {
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
if (clazz.invisibleAnnotations == null) {

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

@ -6,7 +6,9 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.transform.Transformer
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class OriginalPcSaveTransformer : Transformer() {
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean {
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.ClassNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class OverrideTransformer : Transformer() {
private var overrides = 0

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

@ -3,7 +3,9 @@ package dev.openrs2.deob.transform
import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.transform.Transformer
import dev.openrs2.deob.remap.TypedRemapper
import javax.inject.Singleton
@Singleton
class RemapTransformer : Transformer() {
override fun preTransform(classPath: 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.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class ResetTransformer : Transformer() {
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.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
import kotlin.math.max
@Singleton
class StaticScramblingTransformer : Transformer() {
private class FieldSet(val owner: ClassNode, val fields: List<FieldNode>, val clinit: MethodNode?) {
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.VarInsnNode
import org.objectweb.asm.tree.analysis.Analyzer
import javax.inject.Singleton
@Singleton
class UnusedArgTransformer : Transformer() {
private val retainedArgs = mutableSetOf<ArgRef>()
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.MethodNode
import org.objectweb.asm.tree.VarInsnNode
import javax.inject.Singleton
@Singleton
class UnusedLocalTransformer : Transformer() {
private var localsRemoved = 0

@ -14,7 +14,9 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class UnusedMethodTransformer : Transformer() {
private lateinit var inheritedMethodSets: DisjointSet<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.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
import javax.inject.Singleton
@Singleton
class VisibilityTransformer : Transformer() {
private lateinit var inheritedFieldSets: DisjointSet<MemberRef>
private lateinit var inheritedMethodSets: DisjointSet<MemberRef>

Loading…
Cancel
Save