From f9021f7fe66381e60b19f90117fe52ada0494018 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 27 Jun 2020 16:47:53 +0100 Subject: [PATCH] Use Module class in the decompiler This commit also changes the names of the deobfuscator output jars to match up with the module names. Signed-off-by: Graham --- decompiler/build.gradle.kts | 1 + .../openrs2/decompiler/DecompileCommand.kt | 46 +------------------ .../java/dev/openrs2/decompiler/Decompiler.kt | 13 +++--- .../java/dev/openrs2/deob/Deobfuscator.kt | 12 ++--- 4 files changed, 16 insertions(+), 56 deletions(-) diff --git a/decompiler/build.gradle.kts b/decompiler/build.gradle.kts index 87907372fa..cfbabc9726 100644 --- a/decompiler/build.gradle.kts +++ b/decompiler/build.gradle.kts @@ -12,6 +12,7 @@ application { dependencies { api("com.github.ajalt:clikt:${Versions.clikt}") + implementation(project(":deob-util")) implementation(project(":util")) implementation("dev.openrs2:fernflower:${Versions.fernflower}") } diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt b/decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt index f293dfdab2..7bc183f6bf 100644 --- a/decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt +++ b/decompiler/src/main/java/dev/openrs2/decompiler/DecompileCommand.kt @@ -1,55 +1,13 @@ package dev.openrs2.decompiler import com.github.ajalt.clikt.core.CliktCommand -import java.nio.file.Path -import java.nio.file.Paths +import dev.openrs2.deob.util.Module fun main(args: Array) = DecompileCommand().main(args) class DecompileCommand : CliktCommand(name = "decompile") { override fun run() { - val deobOutput = Paths.get("nonfree/var/cache/deob") - - val client = deobOutput.resolve("runescape_gl.jar") - val gl = deobOutput.resolve("jaggl.jar") - val loader = deobOutput.resolve("loader_gl.jar") - val signlink = deobOutput.resolve("signlink_gl.jar") - val unpack = deobOutput.resolve("unpack_gl.jar") - val unpackClass = deobOutput.resolve("unpackclass_gl.jar") - - val decompiler = Decompiler( - Library( - source = client, - destination = getDestination("client"), - dependencies = listOf(gl, signlink) - ), - Library( - source = gl, - destination = getDestination("gl") - ), - Library( - source = loader, - destination = getDestination("loader"), - dependencies = listOf(signlink, unpack) - ), - Library( - source = signlink, - destination = getDestination("signlink") - ), - Library( - source = unpack, - destination = getDestination("unpack") - ), - Library( - source = unpackClass, - destination = getDestination("unpackclass"), - dependencies = listOf(unpack) - ) - ) + val decompiler = Decompiler(Module.all) decompiler.run() } - - private fun getDestination(dir: String): Path { - return Paths.get("nonfree").resolve(dir).resolve("src/main/java") - } } diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt index 8d1932f944..0e21cf8e1e 100644 --- a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt +++ b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.kt @@ -1,18 +1,19 @@ package dev.openrs2.decompiler +import dev.openrs2.deob.util.Module import org.jetbrains.java.decompiler.main.Fernflower import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences -class Decompiler(private vararg val libraries: Library) { +class Decompiler(private val modules: Set) { fun run() { - for (library in libraries) { - DecompilerIo(library.destination).use { io -> + for (module in modules) { + DecompilerIo(module.sources).use { io -> val fernflower = Fernflower(io, io, OPTIONS, Slf4jFernflowerLogger) - for (dependency in library.dependencies) { - fernflower.addLibrary(dependency.toFile()) + for (dependency in module.transitiveDependencies) { + fernflower.addLibrary(dependency.jar.toFile()) } - fernflower.addSource(library.source.toFile()) + fernflower.addSource(module.jar.toFile()) fernflower.decompileContext() } diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt index 4be4fa6c23..da3a9fc167 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt @@ -106,12 +106,12 @@ class Deobfuscator @Inject constructor( Files.createDirectories(output) - client.write(output.resolve("runescape_gl.jar"), JarLibraryWriter, classPath) - gl.write(output.resolve("jaggl.jar"), JarLibraryWriter, classPath) - loader.write(output.resolve("loader_gl.jar"), JarLibraryWriter, classPath) - signlink.write(output.resolve("signlink_gl.jar"), JarLibraryWriter, classPath) - unpack.write(output.resolve("unpack_gl.jar"), JarLibraryWriter, classPath) - unpackClass.write(output.resolve("unpackclass_gl.jar"), JarLibraryWriter, classPath) + client.write(output.resolve("client.jar"), JarLibraryWriter, classPath) + gl.write(output.resolve("gl.jar"), JarLibraryWriter, classPath) + loader.write(output.resolve("loader.jar"), JarLibraryWriter, classPath) + signlink.write(output.resolve("signlink.jar"), JarLibraryWriter, classPath) + unpack.write(output.resolve("unpack.jar"), JarLibraryWriter, classPath) + unpackClass.write(output.resolve("unpackclass.jar"), JarLibraryWriter, classPath) } private companion object {