Load Profile from a YAML file

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent 3dcf91cfef
commit 3db4c82569
  1. 1
      asm/src/main/java/dev/openrs2/asm/AsmJacksonModule.kt
  2. 11
      asm/src/main/java/dev/openrs2/asm/MemberRefDeserializer.kt
  3. 9
      asm/src/main/java/dev/openrs2/asm/filter/GlobClassFilter.kt
  4. 17
      asm/src/main/java/dev/openrs2/asm/filter/GlobMemberFilter.kt
  5. 4
      deob/src/main/java/dev/openrs2/deob/DeobfuscatorModule.kt
  6. 52
      deob/src/main/java/dev/openrs2/deob/Profile.kt
  7. 15
      deob/src/main/java/dev/openrs2/deob/ProfileProvider.kt
  8. 34
      share/deob/profile.yaml

@ -6,6 +6,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class AsmJacksonModule : SimpleModule() { class AsmJacksonModule : SimpleModule() {
init { init {
addDeserializer(MemberRef::class.java, MemberRefDeserializer)
addKeyDeserializer(MemberRef::class.java, MemberRefKeyDeserializer) addKeyDeserializer(MemberRef::class.java, MemberRefKeyDeserializer)
} }
} }

@ -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>(MemberRef::class.java) {
override fun deserialize(parser: JsonParser, ctx: DeserializationContext): MemberRef {
return MemberRef.fromString(ctx.readValue(parser, String::class.java))
}
}

@ -1,9 +1,12 @@
package dev.openrs2.asm.filter package dev.openrs2.asm.filter
class GlobClassFilter(vararg patterns: String) : ClassFilter { import com.fasterxml.jackson.annotation.JsonIgnore
private val patterns = patterns.map(Glob::compileClass).toList()
class GlobClassFilter(@Suppress("CanBeParameter") private val patterns: List<String>) : ClassFilter {
@JsonIgnore
private val compiledPatterns = patterns.map(Glob::compileClass).toList()
override fun matches(name: String): Boolean { override fun matches(name: String): Boolean {
return patterns.any { it.matches(name) } return compiledPatterns.any { it.matches(name) }
} }
} }

@ -1,23 +1,24 @@
package dev.openrs2.asm.filter package dev.openrs2.asm.filter
import com.fasterxml.jackson.annotation.JsonIgnore
import dev.openrs2.asm.MemberRef import dev.openrs2.asm.MemberRef
class GlobMemberFilter(vararg patterns: String) : MemberFilter { class GlobMemberFilter(@Suppress("CanBeParameter") private val patterns: List<MemberRef>) : MemberFilter {
private data class CompiledPattern(val owner: Regex, val name: Regex, val desc: Regex) 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 { 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 { companion object {
private fun compile(pattern: String): CompiledPattern { private fun compile(member: MemberRef): CompiledPattern {
val ref = MemberRef.fromString(pattern)
return CompiledPattern( return CompiledPattern(
Glob.compileClass(ref.owner), Glob.compileClass(member.owner),
Glob.compile(ref.name), Glob.compile(member.name),
Glob.compile(ref.desc) Glob.compile(member.desc)
) )
} }
} }

@ -1,6 +1,7 @@
package dev.openrs2.deob package dev.openrs2.deob
import com.google.inject.AbstractModule import com.google.inject.AbstractModule
import com.google.inject.Scopes
import com.google.inject.multibindings.Multibinder import com.google.inject.multibindings.Multibinder
import dev.openrs2.asm.transform.Transformer import dev.openrs2.asm.transform.Transformer
import dev.openrs2.bundler.BundlerModule import dev.openrs2.bundler.BundlerModule
@ -41,7 +42,8 @@ object DeobfuscatorModule : AbstractModule() {
install(DeobfuscatorMapModule) install(DeobfuscatorMapModule)
bind(Profile::class.java) 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) val binder = Multibinder.newSetBinder(binder(), Transformer::class.java, DeobfuscatorQualifier::class.java)
binder.addBinding().to(OriginalPcSaveTransformer::class.java) binder.addBinding().to(OriginalPcSaveTransformer::class.java)

@ -1,56 +1,12 @@
package dev.openrs2.deob package dev.openrs2.deob
import dev.openrs2.asm.filter.ClassFilter
import dev.openrs2.asm.filter.GlobClassFilter import dev.openrs2.asm.filter.GlobClassFilter
import dev.openrs2.asm.filter.GlobMemberFilter import dev.openrs2.asm.filter.GlobMemberFilter
import dev.openrs2.asm.filter.MemberFilter
class Profile( class Profile(
val excludedClasses: ClassFilter, val excludedClasses: GlobClassFilter,
val excludedMethods: MemberFilter, val excludedMethods: GlobMemberFilter,
val excludedFields: MemberFilter, val excludedFields: GlobMemberFilter,
val entryPoints: MemberFilter, val entryPoints: GlobMemberFilter,
val maxObfuscatedNameLen: Int 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(
"**.<clinit> *",
"**.<init> *",
"**.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(
"**.<clinit> *",
"**.main *",
"**.providesignlink *",
"client.<init> *",
"com/sun/opengl/impl/x11/DRIHack.begin *",
"com/sun/opengl/impl/x11/DRIHack.end *",
"loader.<init> *",
"unpackclass.<init> *"
),
maxObfuscatedNameLen = 2
) )
}
}

@ -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<Profile> {
override fun get(): Profile {
return Files.newBufferedReader(Paths.get("share/deob/profile.yaml")).use { reader ->
mapper.readValue(reader, Profile::class.java)
}
}
}

@ -0,0 +1,34 @@
---
excluded_classes:
- "client"
- "com/sun/opengl/impl/x11/**"
- "jagex3/jagmisc/jagmisc"
- "jaggl/**"
- "javax/media/opengl/**"
- "loader"
- "unpack"
- "unpackclass"
excluded_methods:
- "**.<clinit> *"
- "**.<init> *"
- "**.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:
- "**.<clinit> *"
- "**.main *"
- "**.providesignlink *"
- "client.<init> *"
- "com/sun/opengl/impl/x11/DRIHack.begin *"
- "com/sun/opengl/impl/x11/DRIHack.end *"
- "loader.<init> *"
- "unpackclass.<init> *"
max_obfuscated_name_len: 2
Loading…
Cancel
Save