Add classPath and library arguments to all Transformer methods

master
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;
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;
@ -18,17 +19,17 @@ public abstract class Transformer {
prePass(classPath);
for (var library : classPath.getLibraries()) {
for (var clazz : library) {
changed |= transformClass(clazz);
changed |= transformClass(classPath, library, clazz);
for (var field : clazz.fields) {
changed |= transformField(clazz, field);
changed |= transformField(classPath, library, clazz, field);
}
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) {
changed |= transformCode(clazz, method);
changed |= transformCode(classPath, library, clazz, method);
}
}
}
@ -47,19 +48,19 @@ public abstract class Transformer {
/* empty */
}
protected boolean transformClass(ClassNode clazz) throws AnalyzerException {
protected boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) throws AnalyzerException {
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;
}
protected boolean transformMethod(ClassNode clazz, MethodNode method) throws AnalyzerException {
protected boolean transformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) throws AnalyzerException {
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;
}

@ -1,6 +1,7 @@
package dev.openrs2.bundler.transform;
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;
@ -20,7 +21,7 @@ public final class CachePathTransformer extends Transformer {
}
@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(); ) {
var insn = it.next();
if (insn.getOpcode() != Opcodes.LDC) {

@ -2,6 +2,7 @@ package dev.openrs2.bundler.transform;
import dev.openrs2.asm.InsnMatcher;
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.Type;
@ -25,7 +26,7 @@ public final class HostCheckTransformer extends Transformer {
}
@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) {
return false;
}

@ -1,6 +1,7 @@
package dev.openrs2.bundler.transform;
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;
@ -23,7 +24,7 @@ public final class RightClickTransformer extends Transformer {
}
@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(); ) {
var insn = it.next();
if (insn.getOpcode() != Opcodes.INVOKEVIRTUAL) {

@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet;
import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.InsnNodeUtils;
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;
@ -25,7 +26,7 @@ public final class BitShiftTransformer extends Transformer {
}
@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 -> {
var push = match.get(0);
var bits = InsnNodeUtils.getIntConstant(push);

@ -6,6 +6,7 @@ import java.util.Map;
import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.MemberRef;
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;
@ -65,13 +66,13 @@ public final class BitwiseOpTransformer extends Transformer {
}
@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)));
return false;
}
@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(); ) {
var insn = it.next();
if (insn.getOpcode() != Opcodes.INVOKESTATIC) {

@ -1,12 +1,14 @@
package dev.openrs2.deob.transform;
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;
public final class CanvasTransformer extends Transformer {
@Override
public boolean transformClass(ClassNode clazz) {
public boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
if (!"java/awt/Canvas".equals(clazz.superName)) {
return false;
}

@ -8,6 +8,7 @@ import java.util.Set;
import dev.openrs2.asm.InsnMatcher;
import dev.openrs2.asm.MemberRef;
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;
@ -95,7 +96,7 @@ public final class CounterTransformer extends Transformer {
}
@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 -> {
var putstatic = (FieldInsnNode) match.get(1);
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.StackMetadata;
import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer;
import dev.openrs2.deob.ArgRef;
import dev.openrs2.deob.analysis.IntInterpreter;
@ -151,7 +152,7 @@ public final class DummyArgTransformer extends Transformer {
}
@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 parameters = constArgs.get(parentMethod);

@ -2,6 +2,7 @@ package dev.openrs2.deob.transform;
import dev.openrs2.asm.InsnNodeUtils;
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;
@ -21,7 +22,7 @@ public final class DummyLocalTransformer extends Transformer {
}
@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
* 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.InsnNodeUtils;
import dev.openrs2.asm.classpath.ClassPath;
import dev.openrs2.asm.classpath.Library;
import dev.openrs2.asm.transform.Transformer;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
@ -22,7 +23,7 @@ public final class ExceptionTracingTransformer extends Transformer {
}
@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 -> {
var foundTryCatch = method.tryCatchBlocks.removeIf(tryCatch -> {
if (!"java/lang/RuntimeException".equals(tryCatch.type)) {

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

@ -91,7 +91,7 @@ public final class OpaquePredicateTransformer extends Transformer {
}
@Override
public boolean transformCode(ClassNode clazz, MethodNode method) {
public boolean transformCode(ClassPath classPath, Library library, 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);

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
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.deob.annotation.OriginalArg;
import dev.openrs2.deob.annotation.OriginalClass;
@ -38,7 +40,7 @@ public final class OriginalNameTransformer extends Transformer {
}
@Override
public boolean transformClass(ClassNode clazz) {
public boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
if (clazz.invisibleAnnotations == null) {
clazz.invisibleAnnotations = new ArrayList<>();
}
@ -48,7 +50,7 @@ public final class OriginalNameTransformer extends Transformer {
}
@Override
public boolean transformField(ClassNode clazz, FieldNode field) {
public boolean transformField(ClassPath classPath, Library library, ClassNode clazz, FieldNode field) {
if (field.invisibleAnnotations == null) {
field.invisibleAnnotations = new ArrayList<>();
}
@ -59,7 +61,7 @@ public final class OriginalNameTransformer extends Transformer {
@SuppressWarnings("unchecked")
@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>")) {
return false;
}

Loading…
Cancel
Save