From 3db4c8256959197c75b10e1b6feedac3e4946151 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 9 May 2020 22:35:17 +0100 Subject: [PATCH] Load Profile from a YAML file Signed-off-by: Graham --- .../java/dev/openrs2/asm/AsmJacksonModule.kt | 1 + .../dev/openrs2/asm/MemberRefDeserializer.kt | 11 ++++ .../dev/openrs2/asm/filter/GlobClassFilter.kt | 9 ++-- .../openrs2/asm/filter/GlobMemberFilter.kt | 17 +++--- .../dev/openrs2/deob/DeobfuscatorModule.kt | 4 +- .../src/main/java/dev/openrs2/deob/Profile.kt | 54 ++----------------- .../java/dev/openrs2/deob/ProfileProvider.kt | 15 ++++++ share/deob/profile.yaml | 34 ++++++++++++ 8 files changed, 84 insertions(+), 61 deletions(-) create mode 100644 asm/src/main/java/dev/openrs2/asm/MemberRefDeserializer.kt create mode 100644 deob/src/main/java/dev/openrs2/deob/ProfileProvider.kt create mode 100644 share/deob/profile.yaml diff --git a/asm/src/main/java/dev/openrs2/asm/AsmJacksonModule.kt b/asm/src/main/java/dev/openrs2/asm/AsmJacksonModule.kt index 8910dd1707..1dafbfdeee 100644 --- a/asm/src/main/java/dev/openrs2/asm/AsmJacksonModule.kt +++ b/asm/src/main/java/dev/openrs2/asm/AsmJacksonModule.kt @@ -6,6 +6,7 @@ import javax.inject.Singleton @Singleton class AsmJacksonModule : SimpleModule() { init { + addDeserializer(MemberRef::class.java, MemberRefDeserializer) addKeyDeserializer(MemberRef::class.java, MemberRefKeyDeserializer) } } diff --git a/asm/src/main/java/dev/openrs2/asm/MemberRefDeserializer.kt b/asm/src/main/java/dev/openrs2/asm/MemberRefDeserializer.kt new file mode 100644 index 0000000000..cef2eb64e0 --- /dev/null +++ b/asm/src/main/java/dev/openrs2/asm/MemberRefDeserializer.kt @@ -0,0 +1,11 @@ +package dev.openrs2.asm + +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.deser.std.StdDeserializer + +object MemberRefDeserializer : StdDeserializer(MemberRef::class.java) { + override fun deserialize(parser: JsonParser, ctx: DeserializationContext): MemberRef { + return MemberRef.fromString(ctx.readValue(parser, String::class.java)) + } +} diff --git a/asm/src/main/java/dev/openrs2/asm/filter/GlobClassFilter.kt b/asm/src/main/java/dev/openrs2/asm/filter/GlobClassFilter.kt index 3845f9b1df..8a4514e246 100644 --- a/asm/src/main/java/dev/openrs2/asm/filter/GlobClassFilter.kt +++ b/asm/src/main/java/dev/openrs2/asm/filter/GlobClassFilter.kt @@ -1,9 +1,12 @@ package dev.openrs2.asm.filter -class GlobClassFilter(vararg patterns: String) : ClassFilter { - private val patterns = patterns.map(Glob::compileClass).toList() +import com.fasterxml.jackson.annotation.JsonIgnore + +class GlobClassFilter(@Suppress("CanBeParameter") private val patterns: List) : ClassFilter { + @JsonIgnore + private val compiledPatterns = patterns.map(Glob::compileClass).toList() override fun matches(name: String): Boolean { - return patterns.any { it.matches(name) } + return compiledPatterns.any { it.matches(name) } } } diff --git a/asm/src/main/java/dev/openrs2/asm/filter/GlobMemberFilter.kt b/asm/src/main/java/dev/openrs2/asm/filter/GlobMemberFilter.kt index 47f3eeeb7f..b8e60728e8 100644 --- a/asm/src/main/java/dev/openrs2/asm/filter/GlobMemberFilter.kt +++ b/asm/src/main/java/dev/openrs2/asm/filter/GlobMemberFilter.kt @@ -1,23 +1,24 @@ package dev.openrs2.asm.filter +import com.fasterxml.jackson.annotation.JsonIgnore import dev.openrs2.asm.MemberRef -class GlobMemberFilter(vararg patterns: String) : MemberFilter { +class GlobMemberFilter(@Suppress("CanBeParameter") private val patterns: List) : MemberFilter { private data class CompiledPattern(val owner: Regex, val name: Regex, val desc: Regex) - private val patterns = patterns.map(::compile).toList() + @JsonIgnore + private val compiledPatterns = patterns.map(::compile).toList() override fun matches(owner: String, name: String, desc: String): Boolean { - return patterns.any { it.owner.matches(owner) && it.name.matches(name) && it.desc.matches(desc) } + return compiledPatterns.any { it.owner.matches(owner) && it.name.matches(name) && it.desc.matches(desc) } } companion object { - private fun compile(pattern: String): CompiledPattern { - val ref = MemberRef.fromString(pattern) + private fun compile(member: MemberRef): CompiledPattern { return CompiledPattern( - Glob.compileClass(ref.owner), - Glob.compile(ref.name), - Glob.compile(ref.desc) + Glob.compileClass(member.owner), + Glob.compile(member.name), + Glob.compile(member.desc) ) } } diff --git a/deob/src/main/java/dev/openrs2/deob/DeobfuscatorModule.kt b/deob/src/main/java/dev/openrs2/deob/DeobfuscatorModule.kt index e3bfc0028a..9636c727f8 100644 --- a/deob/src/main/java/dev/openrs2/deob/DeobfuscatorModule.kt +++ b/deob/src/main/java/dev/openrs2/deob/DeobfuscatorModule.kt @@ -1,6 +1,7 @@ package dev.openrs2.deob import com.google.inject.AbstractModule +import com.google.inject.Scopes import com.google.inject.multibindings.Multibinder import dev.openrs2.asm.transform.Transformer import dev.openrs2.bundler.BundlerModule @@ -41,7 +42,8 @@ object DeobfuscatorModule : AbstractModule() { install(DeobfuscatorMapModule) bind(Profile::class.java) - .toInstance(Profile.BUILD_550) + .toProvider(ProfileProvider::class.java) + .`in`(Scopes.SINGLETON) val binder = Multibinder.newSetBinder(binder(), Transformer::class.java, DeobfuscatorQualifier::class.java) binder.addBinding().to(OriginalPcSaveTransformer::class.java) diff --git a/deob/src/main/java/dev/openrs2/deob/Profile.kt b/deob/src/main/java/dev/openrs2/deob/Profile.kt index 4f0835e1d2..4409ee0f3b 100644 --- a/deob/src/main/java/dev/openrs2/deob/Profile.kt +++ b/deob/src/main/java/dev/openrs2/deob/Profile.kt @@ -1,56 +1,12 @@ package dev.openrs2.deob -import dev.openrs2.asm.filter.ClassFilter import dev.openrs2.asm.filter.GlobClassFilter import dev.openrs2.asm.filter.GlobMemberFilter -import dev.openrs2.asm.filter.MemberFilter class Profile( - val excludedClasses: ClassFilter, - val excludedMethods: MemberFilter, - val excludedFields: MemberFilter, - val entryPoints: MemberFilter, + val excludedClasses: GlobClassFilter, + val excludedMethods: GlobMemberFilter, + val excludedFields: GlobMemberFilter, + val entryPoints: GlobMemberFilter, val maxObfuscatedNameLen: Int -) { - companion object { - val BUILD_550 = Profile( - excludedClasses = GlobClassFilter( - "client", - "com/sun/opengl/impl/x11/**", - "jagex3/jagmisc/jagmisc", - "jaggl/**", - "javax/media/opengl/**", - "loader", - "unpack", - "unpackclass" - ), - excludedMethods = GlobMemberFilter( - "**. *", - "**. *", - "**.main *", - "**.providesignlink *", - "**.quit *", - "com/sun/opengl/impl/x11/**.* *", - "jaggl/**.* *", - "javax/media/opengl/**.* *" - ), - excludedFields = GlobMemberFilter( - "**.cache *", - "com/sun/opengl/impl/x11/**.* *", - "jaggl/**.* *", - "javax/media/opengl/**.* *" - ), - entryPoints = GlobMemberFilter( - "**. *", - "**.main *", - "**.providesignlink *", - "client. *", - "com/sun/opengl/impl/x11/DRIHack.begin *", - "com/sun/opengl/impl/x11/DRIHack.end *", - "loader. *", - "unpackclass. *" - ), - maxObfuscatedNameLen = 2 - ) - } -} +) diff --git a/deob/src/main/java/dev/openrs2/deob/ProfileProvider.kt b/deob/src/main/java/dev/openrs2/deob/ProfileProvider.kt new file mode 100644 index 0000000000..094c99a7b8 --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/ProfileProvider.kt @@ -0,0 +1,15 @@ +package dev.openrs2.deob + +import com.fasterxml.jackson.databind.ObjectMapper +import java.nio.file.Files +import java.nio.file.Paths +import javax.inject.Inject +import javax.inject.Provider + +class ProfileProvider @Inject constructor(private val mapper: ObjectMapper) : Provider { + override fun get(): Profile { + return Files.newBufferedReader(Paths.get("share/deob/profile.yaml")).use { reader -> + mapper.readValue(reader, Profile::class.java) + } + } +} diff --git a/share/deob/profile.yaml b/share/deob/profile.yaml new file mode 100644 index 0000000000..619df28855 --- /dev/null +++ b/share/deob/profile.yaml @@ -0,0 +1,34 @@ +--- +excluded_classes: + - "client" + - "com/sun/opengl/impl/x11/**" + - "jagex3/jagmisc/jagmisc" + - "jaggl/**" + - "javax/media/opengl/**" + - "loader" + - "unpack" + - "unpackclass" +excluded_methods: + - "**. *" + - "**. *" + - "**.main *" + - "**.providesignlink *" + - "**.quit *" + - "com/sun/opengl/impl/x11/**.* *" + - "jaggl/**.* *" + - "javax/media/opengl/**.* *" +excluded_fields: + - "**.cache *" + - "com/sun/opengl/impl/x11/**.* *" + - "jaggl/**.* *" + - "javax/media/opengl/**.* *" +entry_points: + - "**. *" + - "**.main *" + - "**.providesignlink *" + - "client. *" + - "com/sun/opengl/impl/x11/DRIHack.begin *" + - "com/sun/opengl/impl/x11/DRIHack.end *" + - "loader. *" + - "unpackclass. *" +max_obfuscated_name_len: 2