From c6cf9a4d94b60fe540a1ad71940be1e75f5e0408 Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 14 Jan 2020 22:11:04 +0000 Subject: [PATCH] Add initial client bundler --- .idea/runConfigurations/Bundler.xml | 15 +++ all/src/bin/openrs2-bundle | 3 + all/src/bin/openrs2-bundle.cmd | 3 + .../main/java/dev/openrs2/bundler/Bundler.kt | 109 +++++++++++++++++- .../java/dev/openrs2/deob/Deobfuscator.kt | 2 + 5 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 .idea/runConfigurations/Bundler.xml create mode 100755 all/src/bin/openrs2-bundle create mode 100644 all/src/bin/openrs2-bundle.cmd diff --git a/.idea/runConfigurations/Bundler.xml b/.idea/runConfigurations/Bundler.xml new file mode 100644 index 00000000..7d469a65 --- /dev/null +++ b/.idea/runConfigurations/Bundler.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/all/src/bin/openrs2-bundle b/all/src/bin/openrs2-bundle new file mode 100755 index 00000000..8b679885 --- /dev/null +++ b/all/src/bin/openrs2-bundle @@ -0,0 +1,3 @@ +#!/bin/sh -e +cd `dirname "$0"`/.. +exec java -cp lib/openrs2.jar dev.openrs2.bundler.BundlerKt "$@" diff --git a/all/src/bin/openrs2-bundle.cmd b/all/src/bin/openrs2-bundle.cmd new file mode 100644 index 00000000..9b15f127 --- /dev/null +++ b/all/src/bin/openrs2-bundle.cmd @@ -0,0 +1,3 @@ +@echo off +cd /d %~dp0\.. +java -cp lib\openrs2.jar dev.openrs2.bundler.BundlerKt %* diff --git a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt index 0a8f4308..891f3c58 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt @@ -1,5 +1,8 @@ package dev.openrs2.bundler +import com.github.michaelbull.logging.InlineLogger +import dev.openrs2.asm.classpath.ClassPath +import dev.openrs2.asm.classpath.Library import dev.openrs2.bundler.transform.BufferSizeTransformer import dev.openrs2.bundler.transform.CachePathTransformer import dev.openrs2.bundler.transform.HostCheckTransformer @@ -8,9 +11,110 @@ import dev.openrs2.bundler.transform.MacResizeTransformer import dev.openrs2.bundler.transform.PlatformDetectionTransformer import dev.openrs2.bundler.transform.ResourceTransformer import dev.openrs2.bundler.transform.RightClickTransformer +import java.nio.file.Path +import java.nio.file.Paths + +fun main() { + val bundler = Bundler(Paths.get("nonfree/code"), Paths.get("nonfree/code/bundle")) + bundler.run() +} + +class Bundler(private val input: Path, private val output: Path) { + fun run() { + // read input jars/packs + logger.info { "Reading input jars" } + val unpacker = Library.readJar(input.resolve("game_unpacker.dat")) + val loader = Library.readJar(input.resolve("loader.jar")) + val glLoader = Library.readJar(input.resolve("loader_gl.jar")) + val gl = Library.readPack(input.resolve("jaggl.pack200")) + val client = Library.readJar(input.resolve("runescape.jar")) + val glClient = Library.readPack(input.resolve("runescape_gl.pack200")) + + // bundle libraries together into a common classpath + val runtime = ClassLoader.getSystemClassLoader() + val classPath = ClassPath( + runtime, + dependencies = listOf(unpacker), + libraries = listOf(client, loader) + ) + val glClassPath = ClassPath( + runtime, + dependencies = listOf(gl, unpacker), + libraries = listOf(glClient, glLoader) + ) + + // run simple transformers + logger.info { "Transforming client" } + for (transformer in TRANSFORMERS) { + logger.info { "Running transformer ${transformer.javaClass.simpleName} " } + transformer.transform(classPath) + } + + logger.info { "Transforming client_gl" } + for (transformer in TRANSFORMERS) { + logger.info { "Running transformer ${transformer.javaClass.simpleName} " } + transformer.transform(glClassPath) + } + + // compress resources + logger.info { "Compressing resources" } + + val unpackerJar = Resource.compressJar("unpackclass.pack", "game_unpacker.dat", unpacker) + val clientPack = Resource.compressPack("runescape.pack200", "main_file_cache.dat0", client) + val clientJs5 = Resource.compressJs5("runescape.js5", "main_file_cache.dat1", client) + val glClientPack = Resource.compressPack("runescape_gl.pack200", "main_file_cache.dat3", glClient) + val glClientJs5 = Resource.compressJs5("runescape_gl.js5", "main_file_cache.dat4", glClient) + val glPack = Resource.compressPack("jaggl.pack200", "main_file_cache.dat5", gl) + val glJs5 = Resource.compressJs5("jaggl.js5", "main_file_cache.dat6", gl) + + val glNatives = Resource.compressGlResources() + val miscNatives = Resource.compressMiscResources() + + // update checksums in the loader + logger.info { "Updating checksums" } + + val resourceTransformer = ResourceTransformer( + resources = listOf(unpackerJar, clientPack, clientJs5), + glResources = glNatives, + miscResources = miscNatives + ) + resourceTransformer.transform(classPath) + + val glResourceTransformer = ResourceTransformer( + resources = listOf(unpackerJar, glClientPack, glClientJs5, glPack, glJs5), + glResources = glNatives, + miscResources = miscNatives + ) + glResourceTransformer.transform(glClassPath) + + // write all resources to disk + logger.info { "Writing resources" } + + val resources = listOf( + unpackerJar, + clientPack, + clientJs5, + glClientPack, + glClientJs5, + glPack, + glJs5, + *glNatives.flatten().toTypedArray(), + *miscNatives.toTypedArray() + ) + resources.forEach { it.write(output) } + + // write unsigned client and loaders + client.writeJar(output.resolve("runescape.jar")) + loader.writeJar(output.resolve("loader.jar")) + glLoader.writeJar(output.resolve("loader_gl.jar")) + + // sign loaders + logger.info { "Signing loaders" } + // TODO(gpe): implement + } -class Bundler { companion object { + val logger = InlineLogger() val TRANSFORMERS = listOf( BufferSizeTransformer(), CachePathTransformer(), @@ -18,8 +122,7 @@ class Bundler { MacResizeTransformer(), RightClickTransformer(), LoadLibraryTransformer(), - PlatformDetectionTransformer(), - ResourceTransformer() + PlatformDetectionTransformer() ) } } diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt index 85cfebb6..78c7d544 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt @@ -6,6 +6,7 @@ import dev.openrs2.asm.classpath.Library import dev.openrs2.asm.classpath.Library.Companion.readJar import dev.openrs2.asm.classpath.Library.Companion.readPack import dev.openrs2.bundler.Bundler +import dev.openrs2.bundler.transform.ResourceTransformer import dev.openrs2.deob.SignedClassUtils.move import dev.openrs2.deob.remap.PrefixRemapper.create import dev.openrs2.deob.transform.AccessTransformer @@ -146,6 +147,7 @@ class Deobfuscator(private val input: Path, private val output: Path) { private val TRANSFORMERS = listOf( OriginalNameTransformer(), *Bundler.TRANSFORMERS.toTypedArray(), + ResourceTransformer(), OpaquePredicateTransformer(), ExceptionTracingTransformer(), BitShiftTransformer(),