From e6f7a40f6eaae56de9715dd27f8f5585ab2525b7 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 14 Jan 2024 11:27:49 +0000 Subject: [PATCH] Make enabled transformers and their order configurable in profile Signed-off-by: Graham --- .../org/openrs2/asm/transform/Transformer.kt | 2 + .../deob/bytecode/BytecodeDeobfuscator.kt | 10 +++- .../bytecode/BytecodeDeobfuscatorModule.kt | 46 +++++++++---------- .../org/openrs2/deob/bytecode/Profile.kt | 3 +- share/deob/profile.yaml | 34 ++++++++++++++ 5 files changed, 70 insertions(+), 25 deletions(-) diff --git a/asm/src/main/kotlin/org/openrs2/asm/transform/Transformer.kt b/asm/src/main/kotlin/org/openrs2/asm/transform/Transformer.kt index ca6a3168e7..cd5c93dbe3 100644 --- a/asm/src/main/kotlin/org/openrs2/asm/transform/Transformer.kt +++ b/asm/src/main/kotlin/org/openrs2/asm/transform/Transformer.kt @@ -8,6 +8,8 @@ import org.openrs2.asm.classpath.Library import org.openrs2.asm.hasCode public abstract class Transformer { + public val name: String = javaClass.simpleName.removeSuffix("Transformer") + public open fun transform(classPath: ClassPath) { preTransform(classPath) diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscator.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscator.kt index 20ec41d8a8..bd50df428f 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscator.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscator.kt @@ -16,9 +16,17 @@ import java.nio.file.Path @Singleton public class BytecodeDeobfuscator @Inject constructor( - @DeobfuscatorQualifier private val transformers: Set + @DeobfuscatorQualifier private val allTransformers: Set, + private val profile: Profile, ) { + private val allTransformersByName = allTransformers.associateBy(Transformer::name) + public fun run(input: Path, output: Path) { + // read list of enabled transformers and their order from the profile + val transformers = profile.transformers.map { name -> + allTransformersByName[name] ?: throw IllegalArgumentException("Unknown transformer $name") + } + // read input jars/packs logger.info { "Reading input jars" } val client = Library.read("client", input.resolve("runescape_gl.pack200"), Pack200LibraryReader) diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscatorModule.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscatorModule.kt index da0e4be89a..05dc809904 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscatorModule.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/BytecodeDeobfuscatorModule.kt @@ -50,38 +50,38 @@ public object BytecodeDeobfuscatorModule : AbstractModule() { .`in`(Scopes.SINGLETON) 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(ClassLiteralTransformer::class.java) - binder.addBinding().to(InvokeSpecialTransformer::class.java) - binder.addBinding().to(MultipleAssignmentTransformer::class.java) - binder.addBinding().to(RemapTransformer::class.java) - binder.addBinding().to(PatcherTransformer::class.java) - binder.addBinding().to(ResourceTransformer::class.java) - binder.addBinding().to(OpaquePredicateTransformer::class.java) - binder.addBinding().to(ExceptionObfuscationTransformer::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(CanvasTransformer::class.java) + binder.addBinding().to(ClassLiteralTransformer::class.java) binder.addBinding().to(ConstantArgTransformer::class.java) binder.addBinding().to(CopyPropagationTransformer::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(EmptyClassTransformer::class.java) - binder.addBinding().to(MethodOrderTransformer::class.java) - binder.addBinding().to(VisibilityTransformer::class.java) + binder.addBinding().to(ExceptionObfuscationTransformer::class.java) + binder.addBinding().to(ExceptionTracingTransformer::class.java) + binder.addBinding().to(FernflowerExceptionTransformer::class.java) + binder.addBinding().to(FieldOrderTransformer::class.java) binder.addBinding().to(FinalClassTransformer::class.java) - binder.addBinding().to(FinalMethodTransformer::class.java) binder.addBinding().to(FinalFieldTransformer::class.java) + binder.addBinding().to(FinalMethodTransformer::class.java) + binder.addBinding().to(InvokeSpecialTransformer::class.java) + binder.addBinding().to(MethodOrderTransformer::class.java) + binder.addBinding().to(MonitorTransformer::class.java) + binder.addBinding().to(MultipleAssignmentTransformer::class.java) + binder.addBinding().to(OpaquePredicateTransformer::class.java) + binder.addBinding().to(OriginalNameTransformer::class.java) + binder.addBinding().to(OriginalPcRestoreTransformer::class.java) + binder.addBinding().to(OriginalPcSaveTransformer::class.java) binder.addBinding().to(OverrideTransformer::class.java) + binder.addBinding().to(PatcherTransformer::class.java) binder.addBinding().to(RedundantGotoTransformer::class.java) - binder.addBinding().to(OriginalPcRestoreTransformer::class.java) - binder.addBinding().to(FernflowerExceptionTransformer::class.java) + binder.addBinding().to(RemapTransformer::class.java) + binder.addBinding().to(ResetTransformer::class.java) + binder.addBinding().to(ResourceTransformer::class.java) + binder.addBinding().to(UnusedArgTransformer::class.java) + binder.addBinding().to(UnusedLocalTransformer::class.java) + binder.addBinding().to(UnusedMethodTransformer::class.java) + binder.addBinding().to(VisibilityTransformer::class.java) } } diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/Profile.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/Profile.kt index 7097f06c49..cfee84797a 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/Profile.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/Profile.kt @@ -9,5 +9,6 @@ public class Profile( public val excludedFields: GlobMemberFilter, public val entryPoints: GlobMemberFilter, public val scrambledLibraries: Set, - public val maxObfuscatedNameLen: Int + public val maxObfuscatedNameLen: Int, + public val transformers: List ) diff --git a/share/deob/profile.yaml b/share/deob/profile.yaml index 93a20c19df..393397a775 100644 --- a/share/deob/profile.yaml +++ b/share/deob/profile.yaml @@ -35,3 +35,37 @@ entry_points: scrambled_libraries: - client max_obfuscated_name_len: 2 +transformers: + - OriginalPcSave + - OriginalName + - ClassLiteral + - InvokeSpecial + - MultipleAssignment + - Remap + - Patcher + - Resource + - OpaquePredicate + - ExceptionObfuscation + - ExceptionTracing + - Monitor + - BitShift + - Canvas + - FieldOrder + - BitwiseOp + - ConstantArg + - CopyPropagation + - UnusedLocal + - UnusedMethod + - UnusedArg + - Counter + - Reset + - EmptyClass + - MethodOrder + - Visibility + - FinalClass + - FinalMethod + - FinalField + - Override + - RedundantGoto + - OriginalPcRestore + - FernflowerException