diff --git a/.idea/runConfigurations/Deobfuscator.xml b/.idea/runConfigurations/Deobfuscator.xml new file mode 100644 index 00000000..ad9ba984 --- /dev/null +++ b/.idea/runConfigurations/Deobfuscator.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/all/build.gradle.kts b/all/build.gradle.kts index b5969bf1..1d1b9eb7 100644 --- a/all/build.gradle.kts +++ b/all/build.gradle.kts @@ -18,9 +18,7 @@ dependencies { implementation(project(":archive")) implementation(project(":compress-cli")) implementation(project(":crc32")) - implementation(project(":decompiler")) - implementation(project(":deob-ast")) - implementation(project(":deob-bytecode")) + implementation(project(":deob")) implementation(project(":game")) implementation(project(":patcher")) } diff --git a/all/src/main/kotlin/org/openrs2/Command.kt b/all/src/main/kotlin/org/openrs2/Command.kt index faa90fd5..37211692 100644 --- a/all/src/main/kotlin/org/openrs2/Command.kt +++ b/all/src/main/kotlin/org/openrs2/Command.kt @@ -5,9 +5,7 @@ import com.github.ajalt.clikt.core.subcommands import org.openrs2.archive.ArchiveCommand import org.openrs2.compress.cli.CompressCommand import org.openrs2.crc32.Crc32Command -import org.openrs2.decompiler.DecompileCommand -import org.openrs2.deob.ast.DeobfuscateAstCommand -import org.openrs2.deob.bytecode.DeobfuscateBytecodeCommand +import org.openrs2.deob.DeobfuscateCommand import org.openrs2.game.GameCommand import org.openrs2.patcher.PatchCommand @@ -19,9 +17,7 @@ public class Command : NoOpCliktCommand(name = "openrs2") { ArchiveCommand(), CompressCommand(), Crc32Command(), - DecompileCommand(), - DeobfuscateAstCommand(), - DeobfuscateBytecodeCommand(), + DeobfuscateCommand(), GameCommand(), PatchCommand() ) diff --git a/decompiler/build.gradle.kts b/decompiler/build.gradle.kts index 4d9b4c2f..f2ce3408 100644 --- a/decompiler/build.gradle.kts +++ b/decompiler/build.gradle.kts @@ -10,9 +10,10 @@ application { } dependencies { + api(project(":deob-util")) api("com.github.ajalt.clikt:clikt:${Versions.clikt}") + api("com.google.inject:guice:${Versions.guice}") - implementation(project(":deob-util")) implementation(project(":util")) implementation("org.openrs2:fernflower:${Versions.fernflower}") } diff --git a/decompiler/src/main/kotlin/org/openrs2/decompiler/DecompileCommand.kt b/decompiler/src/main/kotlin/org/openrs2/decompiler/DecompileCommand.kt index e4ecb2c4..36e43ac8 100644 --- a/decompiler/src/main/kotlin/org/openrs2/decompiler/DecompileCommand.kt +++ b/decompiler/src/main/kotlin/org/openrs2/decompiler/DecompileCommand.kt @@ -7,7 +7,7 @@ public fun main(args: Array): Unit = DecompileCommand().main(args) public class DecompileCommand : CliktCommand(name = "decompile") { override fun run() { - val decompiler = Decompiler(Module.ALL) - decompiler.run() + val decompiler = Decompiler() + decompiler.run(Module.ALL) } } diff --git a/decompiler/src/main/kotlin/org/openrs2/decompiler/Decompiler.kt b/decompiler/src/main/kotlin/org/openrs2/decompiler/Decompiler.kt index ff768b76..2090fb94 100644 --- a/decompiler/src/main/kotlin/org/openrs2/decompiler/Decompiler.kt +++ b/decompiler/src/main/kotlin/org/openrs2/decompiler/Decompiler.kt @@ -3,9 +3,11 @@ package org.openrs2.decompiler import org.jetbrains.java.decompiler.main.Fernflower import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences import org.openrs2.deob.util.Module +import javax.inject.Singleton -public class Decompiler(private val modules: Set) { - public fun run() { +@Singleton +public class Decompiler { + public fun run(modules: Set) { for (module in modules) { DecompilerIo(module.sources).use { io -> val fernflower = Fernflower(io, io, OPTIONS, Slf4jFernflowerLogger) diff --git a/deob-ast/build.gradle.kts b/deob-ast/build.gradle.kts index 539be16b..bf1c5e56 100644 --- a/deob-ast/build.gradle.kts +++ b/deob-ast/build.gradle.kts @@ -9,9 +9,10 @@ application { } dependencies { + api(project(":deob-util")) api("com.github.ajalt.clikt:clikt:${Versions.clikt}") + api("com.google.inject:guice:${Versions.guice}") - implementation(project(":deob-util")) implementation(project(":util")) implementation("com.github.javaparser:javaparser-symbol-solver-core:${Versions.javaParser}") implementation("com.google.guava:guava:${Versions.guava}") diff --git a/deob-ast/src/main/kotlin/org/openrs2/deob/ast/DeobfuscateAstCommand.kt b/deob-ast/src/main/kotlin/org/openrs2/deob/ast/DeobfuscateAstCommand.kt index 6105161e..468df7a1 100644 --- a/deob-ast/src/main/kotlin/org/openrs2/deob/ast/DeobfuscateAstCommand.kt +++ b/deob-ast/src/main/kotlin/org/openrs2/deob/ast/DeobfuscateAstCommand.kt @@ -6,7 +6,7 @@ import org.openrs2.deob.util.Module public fun main(args: Array): Unit = DeobfuscateAstCommand().main(args) -public class DeobfuscateAstCommand : CliktCommand(name = "deob-ast") { +public class DeobfuscateAstCommand : CliktCommand(name = "ast") { override fun run() { val injector = Guice.createInjector(AstDeobfuscatorModule) val deobfuscator = injector.getInstance(AstDeobfuscator::class.java) diff --git a/deob-bytecode/build.gradle.kts b/deob-bytecode/build.gradle.kts index a5de3ad2..6a3ac624 100644 --- a/deob-bytecode/build.gradle.kts +++ b/deob-bytecode/build.gradle.kts @@ -10,6 +10,7 @@ application { dependencies { api("com.github.ajalt.clikt:clikt:${Versions.clikt}") + api("com.google.inject:guice:${Versions.guice}") implementation(project(":deob-annotations")) implementation(project(":deob-util")) diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/DeobfuscateBytecodeCommand.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/DeobfuscateBytecodeCommand.kt index 6af23451..95395cc8 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/DeobfuscateBytecodeCommand.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/DeobfuscateBytecodeCommand.kt @@ -6,7 +6,7 @@ import java.nio.file.Paths public fun main(args: Array): Unit = DeobfuscateBytecodeCommand().main(args) -public class DeobfuscateBytecodeCommand : CliktCommand(name = "deob-bytecode") { +public class DeobfuscateBytecodeCommand : CliktCommand(name = "bytecode") { override fun run() { val injector = Guice.createInjector(BytecodeDeobfuscatorModule) val deobfuscator = injector.getInstance(BytecodeDeobfuscator::class.java) diff --git a/deob/build.gradle.kts b/deob/build.gradle.kts new file mode 100644 index 00000000..c16240ac --- /dev/null +++ b/deob/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + `maven-publish` + application + kotlin("jvm") +} + +application { + mainClass.set("org.openrs2.deob.DeobfuscateCommandKt") + applicationDefaultJvmArgs = listOf("-Xmx3G") +} + +dependencies { + api("com.github.ajalt.clikt:clikt:${Versions.clikt}") + + implementation(project(":decompiler")) + implementation(project(":deob-ast")) + implementation(project(":deob-bytecode")) +} + +publishing { + publications.create("maven") { + from(components["java"]) + + pom { + packaging = "jar" + name.set("OpenRS2 Deobfuscator") + description.set( + """ + A tool for deobfuscating and decompiling the RuneScape client. + """.trimIndent() + ) + } + } +} diff --git a/deob/src/main/kotlin/org/openrs2/deob/DeobfuscateCommand.kt b/deob/src/main/kotlin/org/openrs2/deob/DeobfuscateCommand.kt new file mode 100644 index 00000000..336d8a22 --- /dev/null +++ b/deob/src/main/kotlin/org/openrs2/deob/DeobfuscateCommand.kt @@ -0,0 +1,14 @@ +package org.openrs2.deob + +import com.github.ajalt.clikt.core.CliktCommand +import com.google.inject.Guice + +public fun main(args: Array): Unit = DeobfuscateCommand().main(args) + +public class DeobfuscateCommand : CliktCommand(name = "deob") { + override fun run() { + val injector = Guice.createInjector(DeobfuscatorModule) + val deobfuscator = injector.getInstance(Deobfuscator::class.java) + deobfuscator.run() + } +} diff --git a/deob/src/main/kotlin/org/openrs2/deob/Deobfuscator.kt b/deob/src/main/kotlin/org/openrs2/deob/Deobfuscator.kt new file mode 100644 index 00000000..848f247e --- /dev/null +++ b/deob/src/main/kotlin/org/openrs2/deob/Deobfuscator.kt @@ -0,0 +1,35 @@ +package org.openrs2.deob + +import com.github.michaelbull.logging.InlineLogger +import org.openrs2.decompiler.Decompiler +import org.openrs2.deob.ast.AstDeobfuscator +import org.openrs2.deob.bytecode.BytecodeDeobfuscator +import org.openrs2.deob.util.Module +import java.nio.file.Paths +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +public class Deobfuscator @Inject constructor( + private val bytecodeDeobfuscator: BytecodeDeobfuscator, + private val decompiler: Decompiler, + private val astDeobfuscator: AstDeobfuscator +) { + public fun run() { + logger.info { "Deobfuscating bytecode" } + bytecodeDeobfuscator.run( + input = Paths.get("nonfree/lib"), + output = Paths.get("nonfree/var/cache/deob") + ) + + logger.info { "Decompiling" } + decompiler.run(Module.ALL) + + logger.info { "Deobfuscating AST" } + astDeobfuscator.run(Module.ALL) + } + + private companion object { + private val logger = InlineLogger() + } +} diff --git a/deob/src/main/kotlin/org/openrs2/deob/DeobfuscatorModule.kt b/deob/src/main/kotlin/org/openrs2/deob/DeobfuscatorModule.kt new file mode 100644 index 00000000..bac93ed7 --- /dev/null +++ b/deob/src/main/kotlin/org/openrs2/deob/DeobfuscatorModule.kt @@ -0,0 +1,12 @@ +package org.openrs2.deob + +import com.google.inject.AbstractModule +import org.openrs2.deob.ast.AstDeobfuscatorModule +import org.openrs2.deob.bytecode.BytecodeDeobfuscatorModule + +public object DeobfuscatorModule : AbstractModule() { + override fun configure() { + install(AstDeobfuscatorModule) + install(BytecodeDeobfuscatorModule) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 4fdd037a..02a96951 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,6 +13,7 @@ include( "crypto", "db", "decompiler", + "deob", "deob-annotations", "deob-ast", "deob-bytecode",