From 435dee8b6d63568f04d83bdd95b5d6729d1bdb5d Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 3 May 2020 11:13:02 +0100 Subject: [PATCH] Add MemberRefKeyDeserializer Signed-off-by: Graham --- asm/src/main/java/dev/openrs2/asm/MemberRef.kt | 10 ++++++++++ deob-map/build.gradle.kts | 1 + .../deob/map/DeobfuscatorMapJacksonModule.kt | 12 ++++++++++++ .../dev/openrs2/deob/map/DeobfuscatorMapModule.kt | 15 +++++++++++++++ .../openrs2/deob/map/MemberRefKeyDeserializer.kt | 11 +++++++++++ .../deob/processor/DeobfuscatorProcessorModule.kt | 2 ++ 6 files changed, 51 insertions(+) create mode 100644 deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapJacksonModule.kt create mode 100644 deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapModule.kt create mode 100644 deob-map/src/main/java/dev/openrs2/deob/map/MemberRefKeyDeserializer.kt diff --git a/asm/src/main/java/dev/openrs2/asm/MemberRef.kt b/asm/src/main/java/dev/openrs2/asm/MemberRef.kt index 53dca95ca3..0a40e5ba8b 100644 --- a/asm/src/main/java/dev/openrs2/asm/MemberRef.kt +++ b/asm/src/main/java/dev/openrs2/asm/MemberRef.kt @@ -30,4 +30,14 @@ data class MemberRef(val owner: String, val name: String, val desc: String) : Co override fun toString(): String { return "$owner.$name $desc" } + + companion object { + private val STRING_REGEX = Regex("([^.]+)[.]([^ ]+) (.+)") + + fun fromString(str: String): MemberRef { + val result = STRING_REGEX.matchEntire(str) + require(result != null) + return MemberRef(result.groupValues[1], result.groupValues[2], result.groupValues[3]) + } + } } diff --git a/deob-map/build.gradle.kts b/deob-map/build.gradle.kts index d531cb4a64..3192edb5eb 100644 --- a/deob-map/build.gradle.kts +++ b/deob-map/build.gradle.kts @@ -5,6 +5,7 @@ plugins { dependencies { api(project(":asm")) + api(project(":yaml")) } publishing { diff --git a/deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapJacksonModule.kt b/deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapJacksonModule.kt new file mode 100644 index 0000000000..955f319fec --- /dev/null +++ b/deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapJacksonModule.kt @@ -0,0 +1,12 @@ +package dev.openrs2.deob.map + +import com.fasterxml.jackson.databind.module.SimpleModule +import dev.openrs2.asm.MemberRef +import javax.inject.Singleton + +@Singleton +class DeobfuscatorMapJacksonModule : SimpleModule() { + init { + addKeyDeserializer(MemberRef::class.java, MemberRefKeyDeserializer) + } +} diff --git a/deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapModule.kt b/deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapModule.kt new file mode 100644 index 0000000000..98fb9d8b09 --- /dev/null +++ b/deob-map/src/main/java/dev/openrs2/deob/map/DeobfuscatorMapModule.kt @@ -0,0 +1,15 @@ +package dev.openrs2.deob.map + +import com.fasterxml.jackson.databind.Module +import com.google.inject.AbstractModule +import com.google.inject.multibindings.Multibinder +import dev.openrs2.yaml.YamlModule + +object DeobfuscatorMapModule : AbstractModule() { + override fun configure() { + install(YamlModule) + + Multibinder.newSetBinder(binder(), Module::class.java) + .addBinding().to(DeobfuscatorMapJacksonModule::class.java) + } +} diff --git a/deob-map/src/main/java/dev/openrs2/deob/map/MemberRefKeyDeserializer.kt b/deob-map/src/main/java/dev/openrs2/deob/map/MemberRefKeyDeserializer.kt new file mode 100644 index 0000000000..5457d35b51 --- /dev/null +++ b/deob-map/src/main/java/dev/openrs2/deob/map/MemberRefKeyDeserializer.kt @@ -0,0 +1,11 @@ +package dev.openrs2.deob.map + +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.KeyDeserializer +import dev.openrs2.asm.MemberRef + +object MemberRefKeyDeserializer : KeyDeserializer() { + override fun deserializeKey(key: String, ctx: DeserializationContext): Any { + return MemberRef.fromString(key) + } +} diff --git a/deob-processor/src/main/java/dev/openrs2/deob/processor/DeobfuscatorProcessorModule.kt b/deob-processor/src/main/java/dev/openrs2/deob/processor/DeobfuscatorProcessorModule.kt index ae12336295..08318c6c97 100644 --- a/deob-processor/src/main/java/dev/openrs2/deob/processor/DeobfuscatorProcessorModule.kt +++ b/deob-processor/src/main/java/dev/openrs2/deob/processor/DeobfuscatorProcessorModule.kt @@ -1,10 +1,12 @@ package dev.openrs2.deob.processor import com.google.inject.AbstractModule +import dev.openrs2.deob.map.DeobfuscatorMapModule import dev.openrs2.yaml.YamlModule object DeobfuscatorProcessorModule : AbstractModule() { override fun configure() { + install(DeobfuscatorMapModule) install(YamlModule) } }