Move signed classes in a single pass

bzip2
Graham 5 years ago
parent 12293bb3b1
commit 0b6966c6f8
  1. 19
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.java
  2. 30
      deob/src/main/java/dev/openrs2/deob/SignedClassUtils.java

@ -60,11 +60,13 @@ public final class Deobfuscator {
var unsignedClient = new Library(client); var unsignedClient = new Library(client);
/* overwrite client's classes with signed classes from the loader */ /* overwrite client's classes with signed classes from the loader */
logger.info("Moving signed classes from loader to runescape"); logger.info("Moving signed classes from loader");
var signedClasses = SignedClassSet.create(loader, client); var signLink = new Library();
SignedClassUtils.move(loader, client, signLink);
logger.info("Moving signed classes from loader_gl to runescape_gl"); logger.info("Moving signed classes from loader_gl");
var glSignedClasses = SignedClassSet.create(glLoader, glClient); 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) */ /* 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"); logger.info("Moving unpack from loader to unpack");
@ -75,15 +77,6 @@ public final class Deobfuscator {
var glUnpack = new Library(); var glUnpack = new Library();
glUnpack.add(glLoader.remove("unpack")); 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) */ /* 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"); logger.info("Prefixing loader and unpacker class names");
ClassNamePrefixer.addPrefix(loader, "loader_"); ClassNamePrefixer.addPrefix(loader, "loader_");

@ -16,12 +16,12 @@ import org.objectweb.asm.tree.MethodNode;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public final class SignedClassSet { public final class SignedClassUtils {
private static final Logger logger = LoggerFactory.getLogger(SignedClassSet.class); 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"); 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 */ /* find signed classes */
var signedClasses = findSignedClasses(loader); var signedClasses = findSignedClasses(loader);
logger.info("Identified signed classes {}", signedClasses); logger.info("Identified signed classes {}", signedClasses);
@ -36,18 +36,20 @@ public final class SignedClassSet {
} }
var remapper = new SimpleRemapper(mapping); var remapper = new SimpleRemapper(mapping);
/* move signed classes to the client */ /* delete original signed classes (these have no dependencies) */
var remappedSignedClasses = new HashSet<String>(); for (var name : signedClasses) {
client.remove(name);
}
/* move loader signed classes to signlink */
for (var name : Sets.union(signedClasses, dependencies)) { for (var name : Sets.union(signedClasses, dependencies)) {
var in = loader.remove(name); var in = loader.remove(name);
var out = new ClassNode(); var out = new ClassNode();
in.accept(new ClassRemapper(out, remapper)); in.accept(new ClassRemapper(out, remapper));
remappedSignedClasses.add(out.name); signLink.add(out);
client.add(out);
} }
return new SignedClassSet(remappedSignedClasses);
} }
private static Set<String> findSignedClasses(Library loader) { private static Set<String> findSignedClasses(Library loader) {
@ -100,15 +102,7 @@ public final class SignedClassSet {
return dependencies; return dependencies;
} }
private final Set<String> signedClasses; private SignedClassUtils() {
/* empty */
private SignedClassSet(Set<String> signedClasses) {
this.signedClasses = signedClasses;
}
public void move(Library client, Library signLink) {
for (var name : signedClasses) {
signLink.add(client.remove(name));
}
} }
} }
Loading…
Cancel
Save