Add shorthand Library read/write methods

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
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 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 dev.openrs2.asm.remap
import org.objectweb.asm.commons.Remapper import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.ClassNode
import java.nio.file.Files
import java.nio.file.Path
import java.util.TreeMap import java.util.TreeMap
class Library() : Iterable<ClassNode> { class Library() : Iterable<ClassNode> {
@ -43,4 +48,24 @@ class Library() : Iterable<ClassNode> {
classes = classes.mapKeysTo(TreeMap()) { (_, clazz) -> clazz.name } 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) { fun run(input: Path, output: Path, keyStorePath: Path) {
// read input jars/packs // read input jars/packs
logger.info { "Reading input jars" } logger.info { "Reading input jars" }
val unpacker = readJar(input.resolve("unpackclass.pack")) val unpacker = Library.read(input.resolve("unpackclass.pack"), JarLibraryReader)
val loader = readJar(input.resolve("loader.jar")) val loader = Library.read(input.resolve("loader.jar"), JarLibraryReader)
val glLoader = readJar(input.resolve("loader_gl.jar")) val glLoader = Library.read(input.resolve("loader_gl.jar"), JarLibraryReader)
val gl = readPack(input.resolve("jaggl.pack200")) val gl = Library.read(input.resolve("jaggl.pack200"), Pack200LibraryReader)
val client = readJar(input.resolve("runescape.jar")) val client = Library.read(input.resolve("runescape.jar"), JarLibraryReader)
val glClient = readPack(input.resolve("runescape_gl.pack200")) val glClient = Library.read(input.resolve("runescape_gl.pack200"), Pack200LibraryReader)
// bundle libraries together into a common classpath // bundle libraries together into a common classpath
val runtime = ClassLoader.getPlatformClassLoader() val runtime = ClassLoader.getPlatformClassLoader()
@ -139,43 +139,11 @@ class Bundler @Inject constructor(
} }
// write unsigned client and loaders // 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) val keyStore = Pkcs12KeyStore.open(keyStorePath, config.game)
writeSignedJar(classPath, loader, output.resolve("loader.jar"), keyStore) loader.write(output.resolve("loader.jar"), SignedJarLibraryWriter(signedManifest, keyStore), classPath)
writeSignedJar(glClassPath, glLoader, output.resolve("loader_gl.jar"), keyStore) glLoader.write(output.resolve("loader_gl.jar"), SignedJarLibraryWriter(signedManifest, keyStore), glClassPath)
}
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)
}
} }
companion object { companion object {

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

Loading…
Cancel
Save