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
class AsmJacksonModule : SimpleModule() {
init {
addDeserializer(MemberRef::class.java, MemberRefDeserializer)
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
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<String>) : 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) }
}
}

@ -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<MemberRef>) : 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)
)
}
}

@ -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)

@ -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(
"**.<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