From eec9279a2c773d43f14856c79d0ebcd04c20f9a1 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 15 Dec 2019 19:42:38 +0000 Subject: [PATCH] Add hasCode() method --- asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.java | 4 ++++ asm/src/main/java/dev/openrs2/asm/classpath/Library.java | 4 ++-- asm/src/main/java/dev/openrs2/asm/transform/Transformer.kt | 4 ++-- .../dev/openrs2/bundler/transform/BufferSizeTransformer.java | 4 ++-- .../java/dev/openrs2/deob/transform/BitwiseOpTransformer.java | 3 ++- .../java/dev/openrs2/deob/transform/CounterTransformer.java | 4 ++-- .../openrs2/deob/transform/OpaquePredicateTransformer.java | 3 ++- .../java/dev/openrs2/deob/transform/ResetTransformer.java | 2 +- .../java/dev/openrs2/deob/transform/UnusedArgTransformer.java | 4 ++-- 9 files changed, 19 insertions(+), 13 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.java b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.java index 771d4f6273..dfbff08b73 100644 --- a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.java +++ b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.java @@ -163,6 +163,10 @@ public final class MethodNodeUtils { } while (changed); } + public static boolean hasCode(MethodNode method) { + return (method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0; + } + private MethodNodeUtils() { /* empty */ } diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/Library.java b/asm/src/main/java/dev/openrs2/asm/classpath/Library.java index de17088196..d2218ca87d 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/Library.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/Library.java @@ -15,13 +15,13 @@ import java.util.jar.JarOutputStream; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import dev.openrs2.asm.MethodNodeUtils; import dev.openrs2.asm.remap.ClassForNameRemapper; import dev.openrs2.util.io.DeterministicJarOutputStream; import dev.openrs2.util.io.SkipOutputStream; import org.apache.harmony.pack200.Pack200; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.commons.ClassRemapper; import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.tree.ClassNode; @@ -119,7 +119,7 @@ public final class Library implements Iterable { for (var clazz : classes.values()) { for (var method : clazz.methods) { - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { + if (MethodNodeUtils.hasCode(method)) { ClassForNameRemapper.remap(remapper, method); } } diff --git a/asm/src/main/java/dev/openrs2/asm/transform/Transformer.kt b/asm/src/main/java/dev/openrs2/asm/transform/Transformer.kt index cc941d64a8..733e874732 100644 --- a/asm/src/main/java/dev/openrs2/asm/transform/Transformer.kt +++ b/asm/src/main/java/dev/openrs2/asm/transform/Transformer.kt @@ -1,8 +1,8 @@ package dev.openrs2.asm.transform +import dev.openrs2.asm.MethodNodeUtils.hasCode import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.Library -import org.objectweb.asm.Opcodes import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.FieldNode import org.objectweb.asm.tree.MethodNode @@ -29,7 +29,7 @@ abstract class Transformer { for (method in clazz.methods) { changed = changed or preTransformMethod(classPath, library, clazz, method) - if (method.access and (Opcodes.ACC_NATIVE or Opcodes.ACC_ABSTRACT) == 0) { + if (hasCode(method)) { changed = changed or transformCode(classPath, library, clazz, method) } diff --git a/bundler/src/main/java/dev/openrs2/bundler/transform/BufferSizeTransformer.java b/bundler/src/main/java/dev/openrs2/bundler/transform/BufferSizeTransformer.java index f4f6ac97bc..743dff82b8 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/transform/BufferSizeTransformer.java +++ b/bundler/src/main/java/dev/openrs2/bundler/transform/BufferSizeTransformer.java @@ -5,10 +5,10 @@ import java.util.Optional; import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnNodeUtils; import dev.openrs2.asm.MemberRef; +import dev.openrs2.asm.MethodNodeUtils; import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.Library; import dev.openrs2.asm.transform.Transformer; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.LdcInsnNode; @@ -46,7 +46,7 @@ public final class BufferSizeTransformer extends Transformer { for (var library : classPath.getLibraries()) { for (var clazz : library) { for (var method : clazz.methods) { - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) != 0) { + if (!MethodNodeUtils.hasCode(method)) { continue; } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.java index 0bb707820d..70e767d36c 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.java @@ -5,6 +5,7 @@ import java.util.Map; import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.MemberRef; +import dev.openrs2.asm.MethodNodeUtils; import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.Library; import dev.openrs2.asm.transform.Transformer; @@ -34,7 +35,7 @@ public final class BitwiseOpTransformer extends Transformer { for (var library : classPath.getLibraries()) { for (var clazz : library) { for (var method : clazz.methods) { - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) != 0) { + if (!MethodNodeUtils.hasCode(method)) { continue; } 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 c5fe08663b..34a2127041 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java @@ -7,10 +7,10 @@ import java.util.Set; import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.MemberRef; +import dev.openrs2.asm.MethodNodeUtils; import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.Library; import dev.openrs2.asm.transform.Transformer; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldInsnNode; @@ -37,7 +37,7 @@ public final class CounterTransformer extends Transformer { for (var library : classPath.getLibraries()) { for (var clazz : library) { for (var method : clazz.methods) { - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { + if (MethodNodeUtils.hasCode(method)) { findCounters(method, references, resets, increments); } } 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 3d2a740752..4f714df3ff 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java @@ -6,6 +6,7 @@ import java.util.Set; import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.MemberRef; +import dev.openrs2.asm.MethodNodeUtils; import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.Library; import dev.openrs2.asm.transform.Transformer; @@ -38,7 +39,7 @@ public final class OpaquePredicateTransformer extends Transformer { for (var library : classPath.getLibraries()) { for (var clazz : library) { for (var method : clazz.methods) { - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { + if (MethodNodeUtils.hasCode(method)) { findFlowObstructors(library, method); } } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/ResetTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/ResetTransformer.java index bd93807e0e..c4394da7f1 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/ResetTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/ResetTransformer.java @@ -87,7 +87,7 @@ public final class ResetTransformer extends Transformer { for (var library : classPath.getLibraries()) { for (var clazz : library) { for (var method : clazz.methods) { - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) != 0) { + if (!MethodNodeUtils.hasCode(method)) { continue; } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.java index b374bfc64e..4153e2c4c5 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.java @@ -66,7 +66,7 @@ public final class UnusedArgTransformer extends Transformer { for (var library : classPath.getLibraries()) { for (var clazz : library) { for (var method : clazz.methods) { - if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { + if (MethodNodeUtils.hasCode(method)) { populateRetainedArgs(classPath, clazz, method); } } @@ -123,7 +123,7 @@ public final class UnusedArgTransformer extends Transformer { @Override protected boolean preTransformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) throws AnalyzerException { /* delete unused int args from call sites */ - if ((method.access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) == 0) { + if (MethodNodeUtils.hasCode(method)) { var analyzer = new Analyzer<>(new ConstSourceInterpreter()); var frames = analyzer.analyze(clazz.name, method); var deadInsns = new ArrayList();