From 0b6966c6f855e421268bd2831dd226f9ea2485c4 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 3 Aug 2019 11:52:00 +0100 Subject: [PATCH] Move signed classes in a single pass --- .../java/dev/openrs2/deob/Deobfuscator.java | 19 ++++-------- ...nedClassSet.java => SignedClassUtils.java} | 30 ++++++++----------- 2 files changed, 18 insertions(+), 31 deletions(-) rename deob/src/main/java/dev/openrs2/deob/{SignedClassSet.java => SignedClassUtils.java} (83%) diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java index b7b726344f..f12124f411 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java @@ -60,11 +60,13 @@ public final class Deobfuscator { var unsignedClient = new Library(client); /* 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); + logger.info("Moving signed classes from loader"); + var signLink = new Library(); + SignedClassUtils.move(loader, client, signLink); - logger.info("Moving signed classes from loader_gl to runescape_gl"); - var glSignedClasses = SignedClassSet.create(glLoader, glClient); + logger.info("Moving signed classes from loader_gl"); + var glSignLink = new Library(); + SignedClassUtils.move(glLoader, glClient, glSignLink); /* move unpack class out of the loader (so the unpacker and loader can both depend on it) */ logger.info("Moving unpack from loader to unpack"); @@ -75,15 +77,6 @@ public final class Deobfuscator { var glUnpack = new Library(); glUnpack.add(glLoader.remove("unpack")); - /* move signed classes out of the client (so the client and loader can both depend on them) */ - logger.info("Moving signed classes from runescape to signlink"); - var signLink = new Library(); - signedClasses.move(client, signLink); - - logger.info("Moving signed classes from runescape_gl to signlink_gl"); - var glSignLink = new Library(); - glSignedClasses.move(glClient, glSignLink); - /* prefix remaining loader/unpacker classes (to avoid conflicts when we rename in the same classpath as the client) */ logger.info("Prefixing loader and unpacker class names"); ClassNamePrefixer.addPrefix(loader, "loader_"); diff --git a/deob/src/main/java/dev/openrs2/deob/SignedClassSet.java b/deob/src/main/java/dev/openrs2/deob/SignedClassUtils.java similarity index 83% rename from deob/src/main/java/dev/openrs2/deob/SignedClassSet.java rename to deob/src/main/java/dev/openrs2/deob/SignedClassUtils.java index e3312dc9e9..c714baf9b7 100644 --- a/deob/src/main/java/dev/openrs2/deob/SignedClassSet.java +++ b/deob/src/main/java/dev/openrs2/deob/SignedClassUtils.java @@ -16,12 +16,12 @@ import org.objectweb.asm.tree.MethodNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class SignedClassSet { - private static final Logger logger = LoggerFactory.getLogger(SignedClassSet.class); +public final class SignedClassUtils { + private static final Logger logger = LoggerFactory.getLogger(SignedClassUtils.class); private static final InsnMatcher LOAD_SIGNED_CLASS_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC ASTORE ALOAD GETFIELD ALOAD INVOKEVIRTUAL ALOAD INVOKEVIRTUAL POP"); - public static SignedClassSet create(Library loader, Library client) { + public static void move(Library loader, Library client, Library signLink) { /* find signed classes */ var signedClasses = findSignedClasses(loader); logger.info("Identified signed classes {}", signedClasses); @@ -36,18 +36,20 @@ public final class SignedClassSet { } var remapper = new SimpleRemapper(mapping); - /* move signed classes to the client */ - var remappedSignedClasses = new HashSet(); + /* delete original signed classes (these have no dependencies) */ + for (var name : signedClasses) { + client.remove(name); + } + + /* move loader signed classes to signlink */ for (var name : Sets.union(signedClasses, dependencies)) { var in = loader.remove(name); var out = new ClassNode(); in.accept(new ClassRemapper(out, remapper)); - remappedSignedClasses.add(out.name); - client.add(out); + signLink.add(out); } - return new SignedClassSet(remappedSignedClasses); } private static Set findSignedClasses(Library loader) { @@ -100,15 +102,7 @@ public final class SignedClassSet { return dependencies; } - private final Set signedClasses; - - private SignedClassSet(Set signedClasses) { - this.signedClasses = signedClasses; - } - - public void move(Library client, Library signLink) { - for (var name : signedClasses) { - signLink.add(client.remove(name)); - } + private SignedClassUtils() { + /* empty */ } }