From 1bf39200c564215595899b3edbbdc6b138f2e7eb Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 1 Aug 2019 17:07:07 +0100 Subject: [PATCH] Use jaggl instead of jogl in the deobfuscator --- .../dev/openrs2/decompiler/Decompiler.java | 18 ++++++-------- .../java/dev/openrs2/deob/Deobfuscator.java | 23 ++++++++---------- .../deob/classpath/AsmClassMetadata.java | 6 +++-- .../dev/openrs2/deob/classpath/ClassPath.java | 24 +++++++++++++------ 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java index c04a5d89fb..616585f8e6 100644 --- a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java +++ b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java @@ -19,46 +19,42 @@ public final class Decompiler implements Closeable { ); private static Path getDestination(String archive) { - archive = archive.replaceAll("_gl[.]jar$", ""); + archive = archive.replaceAll("(?:_gl)?[.]jar$", ""); if (archive.equals("runescape")) { archive = "client"; + } else if (archive.equals("jaggl")) { + archive = "gl"; } return Paths.get("nonfree").resolve(archive).resolve("src/main/java"); } public static void main(String[] args) throws IOException { - var libraries = List.of(Paths.get("nonfree/code/jogl.jar")); - var deobOutput = Paths.get("nonfree/code/deob"); var sources = List.of( deobOutput.resolve("runescape_gl.jar"), + deobOutput.resolve("jaggl.jar"), deobOutput.resolve("loader_gl.jar"), deobOutput.resolve("signlink_gl.jar"), deobOutput.resolve("unpack_gl.jar"), deobOutput.resolve("unpacker_gl.jar") ); - try (var decompiler = new Decompiler(libraries, sources, Decompiler::getDestination)) { + try (var decompiler = new Decompiler(sources, Decompiler::getDestination)) { decompiler.run(); } } private final DecompilerIo io; private final Fernflower fernflower; - private final List libraries, sources; + private final List sources; - public Decompiler(List libraries, List sources, Function destination) { + public Decompiler(List sources, Function destination) { this.io = new DecompilerIo(destination); this.fernflower = new Fernflower(io, io, OPTIONS, Slf4jFernflowerLogger.INSTANCE); - this.libraries = libraries; this.sources = sources; } public void run() { - for (var library : libraries) { - fernflower.addLibrary(library.toFile()); - } - for (var source : sources) { fernflower.addSource(source.toFile()); } diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java index 36552b8a27..9b9ddad2a9 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java @@ -1,8 +1,6 @@ package dev.openrs2.deob; import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -51,16 +49,11 @@ public final class Deobfuscator { var glUnpacker = new Library(unpacker); var loader = Library.readJar(input.resolve("loader.jar")); var glLoader = Library.readJar(input.resolve("loader_gl.jar")); + var gl = Library.readPack(input.resolve("jaggl.pack200")); var client = Library.readJar(input.resolve("runescape.jar")); var glClient = Library.readPack(input.resolve("runescape_gl.pack200")); var unsignedClient = new Library(client); - /* read dependencies */ - var runtime = ClassLoader.getPlatformClassLoader(); - var jogl = new URLClassLoader(new URL[] { - input.resolve("jogl.jar").toUri().toURL() - }, runtime); - /* overwrite client's classes with signed classes from the loader */ logger.info("Moving signed classes from loader to runescape"); var signedClasses = SignedClassSet.create(loader, client); @@ -74,6 +67,7 @@ public final class Deobfuscator { "unpacker_gl", glUnpacker, "loader", loader, "loader_gl", glLoader, + "jaggl", gl, "runescape", client, "runescape_gl", glClient, "runescape_unsigned", unsignedClient @@ -115,13 +109,15 @@ public final class Deobfuscator { /* remap all class, method and field names */ logger.info("Creating remappers"); - var libraries = new Library[] { client, loader, signLink, unpack, unpacker }; - var remapper = TypedRemapper.create(new ClassPath(runtime, libraries)); + var runtime = ClassLoader.getPlatformClassLoader(); + + var libraries = List.of(client, loader, signLink, unpack, unpacker); + var remapper = TypedRemapper.create(new ClassPath(runtime, List.of(), libraries)); - var glLibraries = new Library[] { glClient, glLoader, glSignLink, glUnpack, glUnpacker }; - var glRemapper = TypedRemapper.create(new ClassPath(jogl, glLibraries)); + var glLibraries = List.of(glClient, glLoader, glSignLink, glUnpack, glUnpacker); + var glRemapper = TypedRemapper.create(new ClassPath(runtime, List.of(gl), glLibraries)); - var unsignedRemapper = TypedRemapper.create(new ClassPath(runtime, unsignedClient)); + var unsignedRemapper = TypedRemapper.create(new ClassPath(runtime, List.of(), List.of(unsignedClient))); /* transform Class.forName() calls */ logger.info("Transforming Class.forName() calls"); @@ -162,6 +158,7 @@ public final class Deobfuscator { unpack.writeJar(output.resolve("unpack.jar"), remapper); unpacker.writeJar(output.resolve("unpacker.jar"), remapper); + gl.writeJar(output.resolve("jaggl.jar"), glRemapper); glClient.writeJar(output.resolve("runescape_gl.jar"), glRemapper); glLoader.writeJar(output.resolve("loader_gl.jar"), glRemapper); glSignLink.writeJar(output.resolve("signlink_gl.jar"), glRemapper); diff --git a/deob/src/main/java/dev/openrs2/deob/classpath/AsmClassMetadata.java b/deob/src/main/java/dev/openrs2/deob/classpath/AsmClassMetadata.java index cdb294bbdb..27662e715b 100644 --- a/deob/src/main/java/dev/openrs2/deob/classpath/AsmClassMetadata.java +++ b/deob/src/main/java/dev/openrs2/deob/classpath/AsmClassMetadata.java @@ -10,10 +10,12 @@ import org.objectweb.asm.tree.ClassNode; public final class AsmClassMetadata extends ClassMetadata { private final ClassPath classPath; private final ClassNode clazz; + private final boolean dependency; - public AsmClassMetadata(ClassPath classPath, ClassNode clazz) { + public AsmClassMetadata(ClassPath classPath, ClassNode clazz, boolean dependency) { this.classPath = classPath; this.clazz = clazz; + this.dependency = dependency; } @Override @@ -23,7 +25,7 @@ public final class AsmClassMetadata extends ClassMetadata { @Override public boolean isDependency() { - return false; + return dependency; } @Override diff --git a/deob/src/main/java/dev/openrs2/deob/classpath/ClassPath.java b/deob/src/main/java/dev/openrs2/deob/classpath/ClassPath.java index e6e0c777b0..f04f13f7c4 100644 --- a/deob/src/main/java/dev/openrs2/deob/classpath/ClassPath.java +++ b/deob/src/main/java/dev/openrs2/deob/classpath/ClassPath.java @@ -9,13 +9,14 @@ import java.util.Map; import dev.openrs2.asm.Library; public final class ClassPath { - private final ClassLoader dependencyLoader; - private final List libraries; + private final ClassLoader runtime; + private final List dependencies, libraries; private final Map cache = new HashMap<>(); - public ClassPath(ClassLoader dependencyLoader, Library... libraries) { - this.dependencyLoader = dependencyLoader; - this.libraries = List.of(libraries); + public ClassPath(ClassLoader runtime, List dependencies, List libraries) { + this.runtime = runtime; + this.dependencies = dependencies; + this.libraries = libraries; } public List getLibraryClasses() { @@ -39,7 +40,16 @@ public final class ClassPath { for (var library : libraries) { var clazz = library.get(name); if (clazz != null) { - metadata = new AsmClassMetadata(this, clazz); + metadata = new AsmClassMetadata(this, clazz, false); + cache.put(name, metadata); + return metadata; + } + } + + for (var library : dependencies) { + var clazz = library.get(name); + if (clazz != null) { + metadata = new AsmClassMetadata(this, clazz, true); cache.put(name, metadata); return metadata; } @@ -49,7 +59,7 @@ public final class ClassPath { Class clazz; try { - clazz = dependencyLoader.loadClass(reflectionName); + clazz = runtime.loadClass(reflectionName); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Unknown class " + name); }