Inject GlRegistry

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent 3c9edb0291
commit 6d6287c917
  1. 7
      deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscatorModule.kt
  2. 4
      deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt
  3. 15
      deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistryProvider.kt
  4. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/GlTransformer.kt

@ -1,7 +1,10 @@
package dev.openrs2.deob.ast
import com.google.inject.AbstractModule
import com.google.inject.Scopes
import com.google.inject.multibindings.Multibinder
import dev.openrs2.deob.ast.gl.GlRegistry
import dev.openrs2.deob.ast.gl.GlRegistryProvider
import dev.openrs2.deob.ast.transform.AddSubTransformer
import dev.openrs2.deob.ast.transform.BinaryExprOrderTransformer
import dev.openrs2.deob.ast.transform.BitMaskTransformer
@ -21,6 +24,10 @@ import dev.openrs2.deob.ast.transform.ValueOfTransformer
object AstDeobfuscatorModule : AbstractModule() {
override fun configure() {
bind(GlRegistry::class.java)
.toProvider(GlRegistryProvider::class.java)
.`in`(Scopes.SINGLETON)
val binder = Multibinder.newSetBinder(binder(), Transformer::class.java)
binder.addBinding().to(UnencloseTransformer::class.java)
binder.addBinding().to(NegativeLiteralTransformer::class.java)

@ -23,10 +23,6 @@ data class GlRegistry(val enums: ImmutableSetMultimap<Long, GlEnum>, val command
}
}
fun parse(): GlRegistry {
return GlRegistry::class.java.getResourceAsStream("/dev/openrs2/deob/ast/gl.xml").use(::parse)
}
fun parse(input: InputStream): GlRegistry {
val root = SAXBuilder().build(input).rootElement

@ -0,0 +1,15 @@
package dev.openrs2.deob.ast.gl
import javax.inject.Provider
class GlRegistryProvider : Provider<GlRegistry> {
override fun get(): GlRegistry {
GlRegistryProvider::class.java.getResourceAsStream(PATH).use { input ->
return GlRegistry.parse(input)
}
}
companion object {
private const val PATH = "/dev/openrs2/deob/ast/gl.xml"
}
}

@ -25,10 +25,11 @@ import dev.openrs2.deob.ast.gl.GlParameter
import dev.openrs2.deob.ast.gl.GlRegistry
import dev.openrs2.deob.ast.util.checkedAsInt
import dev.openrs2.deob.ast.util.walk
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class GlTransformer(private val registry: GlRegistry = GlRegistry.parse()) : Transformer() {
class GlTransformer @Inject constructor(private val registry: GlRegistry) : Transformer() {
private val enums = mutableSetOf<GlEnum>()
override fun preTransform(units: Map<String, CompilationUnit>) {

Loading…
Cancel
Save