Add shorthand Library read/write methods

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent ae7c19beac
commit 06212b8511
  1. 25
      asm/src/main/java/dev/openrs2/asm/classpath/Library.kt
  2. 50
      bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
  3. 60
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.kt

@ -1,8 +1,13 @@
package dev.openrs2.asm.classpath
import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.io.LibraryReader
import dev.openrs2.asm.io.LibraryWriter
import dev.openrs2.asm.remap
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.ClassNode
import java.nio.file.Files
import java.nio.file.Path
import java.util.TreeMap
class Library() : Iterable<ClassNode> {
@ -43,4 +48,24 @@ class Library() : Iterable<ClassNode> {
classes = classes.mapKeysTo(TreeMap()) { (_, clazz) -> clazz.name }
}
fun write(path: Path, writer: LibraryWriter, classPath: ClassPath) {
logger.info { "Writing library $path" }
Files.newOutputStream(path).use { output ->
writer.write(output, classPath, this)
}
}
companion object {
private val logger = InlineLogger()
fun read(path: Path, reader: LibraryReader): Library {
logger.info { "Reading library $path" }
return Files.newInputStream(path).use { input ->
reader.read(input)
}
}
}
}

@ -42,12 +42,12 @@ class Bundler @Inject constructor(
fun run(input: Path, output: Path, keyStorePath: Path) {
// read input jars/packs
logger.info { "Reading input jars" }
val unpacker = readJar(input.resolve("unpackclass.pack"))
val loader = readJar(input.resolve("loader.jar"))
val glLoader = readJar(input.resolve("loader_gl.jar"))
val gl = readPack(input.resolve("jaggl.pack200"))
val client = readJar(input.resolve("runescape.jar"))
val glClient = readPack(input.resolve("runescape_gl.pack200"))
val unpacker = Library.read(input.resolve("unpackclass.pack"), JarLibraryReader)
val loader = Library.read(input.resolve("loader.jar"), JarLibraryReader)
val glLoader = Library.read(input.resolve("loader_gl.jar"), JarLibraryReader)
val gl = Library.read(input.resolve("jaggl.pack200"), Pack200LibraryReader)
val client = Library.read(input.resolve("runescape.jar"), JarLibraryReader)
val glClient = Library.read(input.resolve("runescape_gl.pack200"), Pack200LibraryReader)
// bundle libraries together into a common classpath
val runtime = ClassLoader.getPlatformClassLoader()
@ -139,43 +139,11 @@ class Bundler @Inject constructor(
}
// write unsigned client and loaders
writeJar(classPath, client, output.resolve("runescape.jar"))
client.write(output.resolve("runescape.jar"), ManifestJarLibraryWriter(unsignedManifest), classPath)
val keyStore = Pkcs12KeyStore.open(keyStorePath, config.game)
writeSignedJar(classPath, loader, output.resolve("loader.jar"), keyStore)
writeSignedJar(glClassPath, glLoader, output.resolve("loader_gl.jar"), keyStore)
}
private fun readJar(path: Path): Library {
logger.info { "Reading jar $path" }
return Files.newInputStream(path).use { input ->
JarLibraryReader.read(input)
}
}
private fun readPack(path: Path): Library {
logger.info { "Reading pack $path" }
return Files.newInputStream(path).use { input ->
Pack200LibraryReader.read(input)
}
}
private fun writeJar(classPath: ClassPath, library: Library, path: Path) {
logger.info { "Writing jar $path" }
Files.newOutputStream(path).use { output ->
ManifestJarLibraryWriter(unsignedManifest).write(output, classPath, library)
}
}
private fun writeSignedJar(classPath: ClassPath, library: Library, path: Path, keyStore: Pkcs12KeyStore) {
logger.info { "Writing signed jar $path" }
Files.newOutputStream(path).use { output ->
SignedJarLibraryWriter(signedManifest, keyStore).write(output, classPath, library)
}
loader.write(output.resolve("loader.jar"), SignedJarLibraryWriter(signedManifest, keyStore), classPath)
glLoader.write(output.resolve("loader_gl.jar"), SignedJarLibraryWriter(signedManifest, keyStore), glClassPath)
}
companion object {

@ -20,13 +20,13 @@ class Deobfuscator @Inject constructor(
fun run(input: Path, output: Path) {
// read input jars/packs
logger.info { "Reading input jars" }
val unpackClass = readJar(input.resolve("unpackclass.pack"))
val unpackClass = Library.read(input.resolve("unpackclass.pack"), JarLibraryReader)
val glUnpackClass = Library(unpackClass)
val loader = readJar(input.resolve("loader.jar"))
val glLoader = readJar(input.resolve("loader_gl.jar"))
val gl = readPack(input.resolve("jaggl.pack200"))
val client = readJar(input.resolve("runescape.jar"))
val glClient = readPack(input.resolve("runescape_gl.pack200"))
val loader = Library.read(input.resolve("loader.jar"), JarLibraryReader)
val glLoader = Library.read(input.resolve("loader_gl.jar"), JarLibraryReader)
val gl = Library.read(input.resolve("jaggl.pack200"), Pack200LibraryReader)
val client = Library.read(input.resolve("runescape.jar"), JarLibraryReader)
val glClient = Library.read(input.resolve("runescape_gl.pack200"), Pack200LibraryReader)
/*
* TODO(gpe): it'd be nice to have separate signlink.jar and
@ -103,44 +103,20 @@ class Deobfuscator @Inject constructor(
Files.createDirectories(output)
writeJar(classPath, client, output.resolve("runescape.jar"))
writeJar(classPath, loader, output.resolve("loader.jar"))
writeJar(classPath, signLink, output.resolve("signlink.jar"))
writeJar(classPath, unpack, output.resolve("unpack.jar"))
writeJar(classPath, unpackClass, output.resolve("unpackclass.jar"))
client.write(output.resolve("runescape.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)
writeJar(glClassPath, gl, output.resolve("jaggl.jar"))
writeJar(glClassPath, glClient, output.resolve("runescape_gl.jar"))
writeJar(glClassPath, glLoader, output.resolve("loader_gl.jar"))
writeJar(glClassPath, glSignLink, output.resolve("signlink_gl.jar"))
writeJar(glClassPath, glUnpack, output.resolve("unpack_gl.jar"))
writeJar(glClassPath, glUnpackClass, output.resolve("unpackclass_gl.jar"))
gl.write(output.resolve("jaggl.jar"), JarLibraryWriter, glClassPath)
glClient.write(output.resolve("runescape_gl.jar"), JarLibraryWriter, glClassPath)
glLoader.write(output.resolve("loader_gl.jar"), JarLibraryWriter, glClassPath)
glSignLink.write(output.resolve("signlink_gl.jar"), JarLibraryWriter, glClassPath)
glUnpack.write(output.resolve("unpack_gl.jar"), JarLibraryWriter, glClassPath)
glUnpackClass.write(output.resolve("unpackclass_gl.jar"), JarLibraryWriter, glClassPath)
writeJar(unsignedClassPath, unsignedClient, output.resolve("runescape_unsigned.jar"))
}
private fun readJar(path: Path): Library {
logger.info { "Reading jar $path" }
return Files.newInputStream(path).use { input ->
JarLibraryReader.read(input)
}
}
private fun readPack(path: Path): Library {
logger.info { "Reading pack $path" }
return Files.newInputStream(path).use { input ->
Pack200LibraryReader.read(input)
}
}
private fun writeJar(classPath: ClassPath, library: Library, path: Path) {
logger.info { "Writing jar $path" }
Files.newOutputStream(path).use { output ->
JarLibraryWriter.write(output, classPath, library)
}
unsignedClient.write(output.resolve("runescape_unsigned.jar"), JarLibraryWriter, unsignedClassPath)
}
companion object {

Loading…
Cancel
Save