Add classPath and library arguments to all Transformer methods

bzip2
Graham 5 years ago
parent 46ab5111e6
commit 145ed6b1ee
  1. 17
      asm/src/main/java/dev/openrs2/asm/transform/Transformer.java
  2. 3
      bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java
  3. 3
      bundler/src/main/java/dev/openrs2/bundler/transform/HostCheckTransformer.java
  4. 3
      bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.java
  5. 3
      deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java
  6. 5
      deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.java
  7. 4
      deob/src/main/java/dev/openrs2/deob/transform/CanvasTransformer.java
  8. 3
      deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java
  9. 3
      deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.java
  10. 3
      deob/src/main/java/dev/openrs2/deob/transform/DummyLocalTransformer.java
  11. 3
      deob/src/main/java/dev/openrs2/deob/transform/ExceptionTracingTransformer.java
  12. 4
      deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java
  13. 2
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java
  14. 8
      deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java

@ -1,6 +1,7 @@
package dev.openrs2.asm.transform; package dev.openrs2.asm.transform;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.FieldNode;
@ -18,17 +19,17 @@ public abstract class Transformer {
prePass(classPath); prePass(classPath);
for (var library : classPath.getLibraries()) { for (var library : classPath.getLibraries()) {
for (var clazz : library) { for (var clazz : library) {
changed |= transformClass(clazz); changed |= transformClass(classPath, library, clazz);
for (var field : clazz.fields) { for (var field : clazz.fields) {
changed |= transformField(clazz, field); changed |= transformField(classPath, library, clazz, field);
} }
for (var method : clazz.methods) { for (var method : clazz.methods) {
changed |= transformMethod(clazz, method); changed |= transformMethod(classPath, library, clazz, method);
if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) { if ((method.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) {
changed |= transformCode(clazz, method); changed |= transformCode(classPath, library, clazz, method);
} }
} }
} }
@ -47,19 +48,19 @@ public abstract class Transformer {
/* empty */ /* empty */
} }
protected boolean transformClass(ClassNode clazz) throws AnalyzerException { protected boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) throws AnalyzerException {
return false; return false;
} }
protected boolean transformField(ClassNode clazz, FieldNode field) throws AnalyzerException { protected boolean transformField(ClassPath classPath, Library library, ClassNode clazz, FieldNode field) throws AnalyzerException {
return false; return false;
} }
protected boolean transformMethod(ClassNode clazz, MethodNode method) throws AnalyzerException { protected boolean transformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) throws AnalyzerException {
return false; return false;
} }
protected boolean transformCode(ClassNode clazz, MethodNode method) throws AnalyzerException { protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) throws AnalyzerException {
return false; return false;
} }

@ -1,6 +1,7 @@
package dev.openrs2.bundler.transform; package dev.openrs2.bundler.transform;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
@ -20,7 +21,7 @@ public final class CachePathTransformer extends Transformer {
} }
@Override @Override
protected boolean transformCode(ClassNode clazz, MethodNode method) { protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
for (var it = method.instructions.iterator(); it.hasNext(); ) { for (var it = method.instructions.iterator(); it.hasNext(); ) {
var insn = it.next(); var insn = it.next();
if (insn.getOpcode() != Opcodes.LDC) { if (insn.getOpcode() != Opcodes.LDC) {

@ -2,6 +2,7 @@ package dev.openrs2.bundler.transform;
import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@ -25,7 +26,7 @@ public final class HostCheckTransformer extends Transformer {
} }
@Override @Override
protected boolean transformCode(ClassNode clazz, MethodNode method) { protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
if (Type.getReturnType(method.desc).getSort() != Type.BOOLEAN) { if (Type.getReturnType(method.desc).getSort() != Type.BOOLEAN) {
return false; return false;
} }

@ -1,6 +1,7 @@
package dev.openrs2.bundler.transform; package dev.openrs2.bundler.transform;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
@ -23,7 +24,7 @@ public final class RightClickTransformer extends Transformer {
} }
@Override @Override
protected boolean transformCode(ClassNode clazz, MethodNode method) { protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
for (var it = method.instructions.iterator(); it.hasNext(); ) { for (var it = method.instructions.iterator(); it.hasNext(); ) {
var insn = it.next(); var insn = it.next();
if (insn.getOpcode() != Opcodes.INVOKEVIRTUAL) { if (insn.getOpcode() != Opcodes.INVOKEVIRTUAL) {

@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet;
import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.InsnNodeUtils; import dev.openrs2.asm.InsnNodeUtils;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
@ -25,7 +26,7 @@ public final class BitShiftTransformer extends Transformer {
} }
@Override @Override
public boolean transformCode(ClassNode clazz, MethodNode method) { public boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
CONST_SHIFT_MATCHER.match(method).forEach(match -> { CONST_SHIFT_MATCHER.match(method).forEach(match -> {
var push = match.get(0); var push = match.get(0);
var bits = InsnNodeUtils.getIntConstant(push); var bits = InsnNodeUtils.getIntConstant(push);

@ -6,6 +6,7 @@ import java.util.Map;
import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.MemberRef; import dev.openrs2.asm.MemberRef;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
@ -65,13 +66,13 @@ public final class BitwiseOpTransformer extends Transformer {
} }
@Override @Override
protected boolean transformClass(ClassNode clazz) { protected boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
clazz.methods.removeIf(m -> methodOps.containsKey(new MemberRef(clazz.name, m.name, m.desc))); clazz.methods.removeIf(m -> methodOps.containsKey(new MemberRef(clazz.name, m.name, m.desc)));
return false; return false;
} }
@Override @Override
protected boolean transformCode(ClassNode clazz, MethodNode method) { protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
for (var it = method.instructions.iterator(); it.hasNext(); ) { for (var it = method.instructions.iterator(); it.hasNext(); ) {
var insn = it.next(); var insn = it.next();
if (insn.getOpcode() != Opcodes.INVOKESTATIC) { if (insn.getOpcode() != Opcodes.INVOKESTATIC) {

@ -1,12 +1,14 @@
package dev.openrs2.deob.transform; package dev.openrs2.deob.transform;
import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
public final class CanvasTransformer extends Transformer { public final class CanvasTransformer extends Transformer {
@Override @Override
public boolean transformClass(ClassNode clazz) { public boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
if (!"java/awt/Canvas".equals(clazz.superName)) { if (!"java/awt/Canvas".equals(clazz.superName)) {
return false; return false;
} }

@ -8,6 +8,7 @@ import java.util.Set;
import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.MemberRef; import dev.openrs2.asm.MemberRef;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.AbstractInsnNode;
@ -95,7 +96,7 @@ public final class CounterTransformer extends Transformer {
} }
@Override @Override
public boolean transformCode(ClassNode clazz, MethodNode method) { public boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
RESET_PATTERN.match(method).forEach(match -> { RESET_PATTERN.match(method).forEach(match -> {
var putstatic = (FieldInsnNode) match.get(1); var putstatic = (FieldInsnNode) match.get(1);
if (counters.contains(new MemberRef(putstatic.owner, putstatic.name, putstatic.desc))) { if (counters.contains(new MemberRef(putstatic.owner, putstatic.name, putstatic.desc))) {

@ -14,6 +14,7 @@ import dev.openrs2.asm.InsnNodeUtils;
import dev.openrs2.asm.MemberRef; import dev.openrs2.asm.MemberRef;
import dev.openrs2.asm.StackMetadata; import dev.openrs2.asm.StackMetadata;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import dev.openrs2.deob.ArgRef; import dev.openrs2.deob.ArgRef;
import dev.openrs2.deob.analysis.IntInterpreter; import dev.openrs2.deob.analysis.IntInterpreter;
@ -151,7 +152,7 @@ public final class DummyArgTransformer extends Transformer {
} }
@Override @Override
protected boolean transformCode(ClassNode clazz, MethodNode method) throws AnalyzerException { protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) throws AnalyzerException {
var parentMethod = inheritedMethodSets.get(new MemberRef(clazz.name, method.name, method.desc)); var parentMethod = inheritedMethodSets.get(new MemberRef(clazz.name, method.name, method.desc));
var parameters = constArgs.get(parentMethod); var parameters = constArgs.get(parentMethod);

@ -2,6 +2,7 @@ package dev.openrs2.deob.transform;
import dev.openrs2.asm.InsnNodeUtils; import dev.openrs2.asm.InsnNodeUtils;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
@ -21,7 +22,7 @@ public final class DummyLocalTransformer extends Transformer {
} }
@Override @Override
protected boolean transformCode(ClassNode clazz, MethodNode method) { protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
/* /*
* XXX(gpe): this is primitive (ideally we'd do a proper data flow * XXX(gpe): this is primitive (ideally we'd do a proper data flow
* analysis, but we'd need to do it in reverse and ASM only supports * analysis, but we'd need to do it in reverse and ASM only supports

@ -3,6 +3,7 @@ package dev.openrs2.deob.transform;
import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.InsnNodeUtils; import dev.openrs2.asm.InsnNodeUtils;
import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.MethodNode;
@ -22,7 +23,7 @@ public final class ExceptionTracingTransformer extends Transformer {
} }
@Override @Override
public boolean transformCode(ClassNode clazz, MethodNode method) { public boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
CATCH_MATCHER.match(method).forEach(match -> { CATCH_MATCHER.match(method).forEach(match -> {
var foundTryCatch = method.tryCatchBlocks.removeIf(tryCatch -> { var foundTryCatch = method.tryCatchBlocks.removeIf(tryCatch -> {
if (!"java/lang/RuntimeException".equals(tryCatch.type)) { if (!"java/lang/RuntimeException".equals(tryCatch.type)) {

@ -3,6 +3,8 @@ package dev.openrs2.deob.transform;
import java.util.HashMap; import java.util.HashMap;
import dev.openrs2.asm.MemberDesc; import dev.openrs2.asm.MemberDesc;
import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
@ -46,7 +48,7 @@ public final class FieldOrderTransformer extends Transformer {
} }
@Override @Override
public boolean transformClass(ClassNode clazz) { public boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
sortFields(clazz, CONSTRUCTOR, Opcodes.PUTFIELD); sortFields(clazz, CONSTRUCTOR, Opcodes.PUTFIELD);
sortFields(clazz, STATIC_CONSTRUCTOR, Opcodes.PUTSTATIC); sortFields(clazz, STATIC_CONSTRUCTOR, Opcodes.PUTSTATIC);
return false; return false;

@ -91,7 +91,7 @@ public final class OpaquePredicateTransformer extends Transformer {
} }
@Override @Override
public boolean transformCode(ClassNode clazz, MethodNode method) { public boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
/* find and fix opaque predicates */ /* find and fix opaque predicates */
OPAQUE_PREDICATE_MATCHER.match(method).filter(match -> isOpaquePredicate(method, match)).forEach(match -> { OPAQUE_PREDICATE_MATCHER.match(method).filter(match -> isOpaquePredicate(method, match)).forEach(match -> {
var branch = (JumpInsnNode) match.get(1); var branch = (JumpInsnNode) match.get(1);

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer; import dev.openrs2.asm.transform.Transformer;
import dev.openrs2.deob.annotation.OriginalArg; import dev.openrs2.deob.annotation.OriginalArg;
import dev.openrs2.deob.annotation.OriginalClass; import dev.openrs2.deob.annotation.OriginalClass;
@ -38,7 +40,7 @@ public final class OriginalNameTransformer extends Transformer {
} }
@Override @Override
public boolean transformClass(ClassNode clazz) { public boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
if (clazz.invisibleAnnotations == null) { if (clazz.invisibleAnnotations == null) {
clazz.invisibleAnnotations = new ArrayList<>(); clazz.invisibleAnnotations = new ArrayList<>();
} }
@ -48,7 +50,7 @@ public final class OriginalNameTransformer extends Transformer {
} }
@Override @Override
public boolean transformField(ClassNode clazz, FieldNode field) { public boolean transformField(ClassPath classPath, Library library, ClassNode clazz, FieldNode field) {
if (field.invisibleAnnotations == null) { if (field.invisibleAnnotations == null) {
field.invisibleAnnotations = new ArrayList<>(); field.invisibleAnnotations = new ArrayList<>();
} }
@ -59,7 +61,7 @@ public final class OriginalNameTransformer extends Transformer {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean transformMethod(ClassNode clazz, MethodNode method) { public boolean transformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
if (method.name.equals("<init>") || method.name.equals("<clinit>")) { if (method.name.equals("<init>") || method.name.equals("<clinit>")) {
return false; return false;
} }

Loading…
Cancel
Save