diff --git a/asm/src/main/java/dev/openrs2/asm/transform/Transformer.java b/asm/src/main/java/dev/openrs2/asm/transform/Transformer.java index 1dc99b9c52..a3cbdb2eff 100644 --- a/asm/src/main/java/dev/openrs2/asm/transform/Transformer.java +++ b/asm/src/main/java/dev/openrs2/asm/transform/Transformer.java @@ -11,23 +11,28 @@ public abstract class Transformer { public void transform(ClassPath classPath) throws AnalyzerException { preTransform(classPath); - for (var library : classPath.getLibraries()) { - for (var clazz : library) { - transformClass(clazz); + boolean changed; + do { + changed = false; - for (var field : clazz.fields) { - transformField(clazz, field); - } + for (var library : classPath.getLibraries()) { + for (var clazz : library) { + changed |= transformClass(clazz); + + for (var field : clazz.fields) { + changed |= transformField(clazz, field); + } - for (var method : clazz.methods) { - transformMethod(clazz, method); + for (var method : clazz.methods) { + changed |= transformMethod(clazz, method); - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { - transformCode(clazz, method); + if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { + changed |= transformCode(clazz, method); + } } } } - } + } while (changed); postTransform(classPath); } @@ -36,20 +41,20 @@ public abstract class Transformer { /* empty */ } - public void transformClass(ClassNode clazz) throws AnalyzerException { - /* empty */ + public boolean transformClass(ClassNode clazz) throws AnalyzerException { + return false; } - public void transformField(ClassNode clazz, FieldNode field) throws AnalyzerException { - /* empty */ + public boolean transformField(ClassNode clazz, FieldNode field) throws AnalyzerException { + return false; } - public void transformMethod(ClassNode clazz, MethodNode method) throws AnalyzerException { - /* empty */ + public boolean transformMethod(ClassNode clazz, MethodNode method) throws AnalyzerException { + return false; } - public void transformCode(ClassNode clazz, MethodNode method) throws AnalyzerException { - /* empty */ + public boolean transformCode(ClassNode clazz, MethodNode method) throws AnalyzerException { + return false; } public void postTransform(ClassPath classPath) throws AnalyzerException { diff --git a/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java index b96bfe917a..1bdb0b1de1 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java @@ -26,7 +26,7 @@ public final class BitShiftTransformer extends Transformer { } @Override - public void transformCode(ClassNode clazz, MethodNode method) { + public boolean transformCode(ClassNode clazz, MethodNode method) { CONST_SHIFT_MATCHER.match(method).forEach(match -> { var push = match.get(0); var bits = InsnNodeUtils.getIntConstant(push); @@ -39,6 +39,8 @@ public final class BitShiftTransformer extends Transformer { simplified++; } }); + + return false; } @Override diff --git a/deob/src/main/java/dev/openrs2/deob/transform/CanvasTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/CanvasTransformer.java index 9bc73d3e69..9defb29248 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/CanvasTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/CanvasTransformer.java @@ -6,15 +6,17 @@ import org.objectweb.asm.tree.ClassNode; public final class CanvasTransformer extends Transformer { @Override - public void transformClass(ClassNode clazz) { + public boolean transformClass(ClassNode clazz) { if (!"java/awt/Canvas".equals(clazz.superName)) { - return; + return false; } if ((clazz.access & Opcodes.ACC_FINAL) == 0) { - return; + return false; } clazz.interfaces.remove("java/awt/event/FocusListener"); + + return false; } } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/ClassForNameTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/ClassForNameTransformer.java index 43a591f975..b8208d4683 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/ClassForNameTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/ClassForNameTransformer.java @@ -33,7 +33,7 @@ public final class ClassForNameTransformer extends Transformer { } @Override - public void transformCode(ClassNode clazz, MethodNode method) { + public boolean transformCode(ClassNode clazz, MethodNode method) { INVOKE_MATCHER.match(method).filter(ClassForNameTransformer::isClassForName).forEach(match -> { var ldc = (LdcInsnNode) match.get(0); var name = remapper.map((String) ldc.cst); @@ -41,5 +41,7 @@ public final class ClassForNameTransformer extends Transformer { ldc.cst = name; } }); + + return false; } } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java index 4e1ccc2053..0c873cacef 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java @@ -94,7 +94,7 @@ public final class CounterTransformer extends Transformer { } @Override - public void transformCode(ClassNode clazz, MethodNode method) { + public boolean transformCode(ClassNode clazz, MethodNode method) { RESET_PATTERN.match(method).forEach(match -> { var putstatic = (FieldInsnNode) match.get(1); if (counters.contains(new MemberRef(putstatic.owner, putstatic.name, putstatic.desc))) { @@ -111,6 +111,8 @@ public final class CounterTransformer extends Transformer { match.forEach(method.instructions::remove); } }); + + return false; } @Override diff --git a/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java index 0224a07623..bb92f81b79 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java @@ -22,7 +22,7 @@ public final class ExceptionTracingTransformer extends Transformer { } @Override - public void transformCode(ClassNode clazz, MethodNode method) { + public boolean transformCode(ClassNode clazz, MethodNode method) { CATCH_MATCHER.match(method).forEach(match -> { var foundTryCatch = method.tryCatchBlocks.removeIf(tryCatch -> { if (!"java/lang/RuntimeException".equals(tryCatch.type)) { @@ -36,6 +36,8 @@ public final class ExceptionTracingTransformer extends Transformer { tracingTryCatches++; } }); + + return false; } @Override diff --git a/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java index 68cbc1d5ea..66e80be11c 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java @@ -45,8 +45,9 @@ public final class FieldOrderTransformer extends Transformer { } @Override - public void transformClass(ClassNode clazz) { + public boolean transformClass(ClassNode clazz) { sortFields(clazz, CONSTRUCTOR, Opcodes.PUTFIELD); sortFields(clazz, STATIC_CONSTRUCTOR, Opcodes.PUTSTATIC); + return false; } } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java index 8bb1a72a53..b4af79201a 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java @@ -91,7 +91,7 @@ public final class OpaquePredicateTransformer extends Transformer { } @Override - public void transformCode(ClassNode clazz, MethodNode method) { + public boolean transformCode(ClassNode clazz, MethodNode method) { /* find and fix opaque predicates */ OPAQUE_PREDICATE_MATCHER.match(method).filter(match -> isOpaquePredicate(method, match)).forEach(match -> { var branch = (JumpInsnNode) match.get(1); @@ -113,6 +113,8 @@ public final class OpaquePredicateTransformer extends Transformer { match.forEach(method.instructions::remove); stores++; }); + + return false; } @Override diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java index 3dbb213d12..d6e3bf5d71 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java @@ -37,26 +37,30 @@ public final class OriginalNameTransformer extends Transformer { } @Override - public void transformClass(ClassNode clazz) { + public boolean transformClass(ClassNode clazz) { if (clazz.invisibleAnnotations == null) { clazz.invisibleAnnotations = new ArrayList<>(); } clazz.invisibleAnnotations.add(createOriginalClassAnnotation(clazz.name)); + + return false; } @Override - public void transformField(ClassNode clazz, FieldNode field) { + public boolean transformField(ClassNode clazz, FieldNode field) { if (field.invisibleAnnotations == null) { field.invisibleAnnotations = new ArrayList<>(); } field.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, field.name, field.desc)); + + return false; } @SuppressWarnings("unchecked") @Override - public void transformMethod(ClassNode clazz, MethodNode method) { + public boolean transformMethod(ClassNode clazz, MethodNode method) { if (method.name.equals("") || method.name.equals("")) { - return; + return false; } if (method.invisibleAnnotations == null) { @@ -75,5 +79,7 @@ public final class OriginalNameTransformer extends Transformer { } annotations.add(createOriginalArgAnnotation(i)); } + + return false; } }