Add shorthand MemberRef constructors

bzip2
Graham 5 years ago
parent 5d63904075
commit 0a5901cde4
  1. 22
      asm/src/main/java/dev/openrs2/asm/MemberRef.java
  2. 2
      bundler/src/main/java/dev/openrs2/bundler/transform/BufferSizeTransformer.java
  3. 6
      deob/src/main/java/dev/openrs2/deob/transform/BitwiseOpTransformer.java
  4. 10
      deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.java
  5. 6
      deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.java
  6. 4
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.java
  7. 6
      deob/src/main/java/dev/openrs2/deob/transform/ResetTransformer.java
  8. 8
      deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.java

@ -2,9 +2,31 @@ package dev.openrs2.asm;
import java.util.Objects; import java.util.Objects;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
public final class MemberRef { public final class MemberRef {
private final String owner, name, desc; private final String owner, name, desc;
public MemberRef(ClassNode clazz, FieldNode field) {
this(clazz.name, field.name, field.desc);
}
public MemberRef(ClassNode clazz, MethodNode method) {
this(clazz.name, method.name, method.desc);
}
public MemberRef(FieldInsnNode fieldInsn) {
this(fieldInsn.owner, fieldInsn.name, fieldInsn.desc);
}
public MemberRef(MethodInsnNode methodInsn) {
this(methodInsn.owner, methodInsn.name, methodInsn.desc);
}
public MemberRef(String owner, MemberDesc desc) { public MemberRef(String owner, MemberDesc desc) {
this(owner, desc.getName(), desc.getDesc()); this(owner, desc.getName(), desc.getDesc());
} }

@ -30,7 +30,7 @@ public final class BufferSizeTransformer extends Transformer {
}) })
.map(match -> { .map(match -> {
var getstatic = (FieldInsnNode) match.get(2); var getstatic = (FieldInsnNode) match.get(2);
return new MemberRef(getstatic.owner, getstatic.name, getstatic.desc); return new MemberRef(getstatic);
}) })
.findAny(); .findAny();
} }

@ -57,7 +57,7 @@ public final class BitwiseOpTransformer extends Transformer {
return; return;
} }
var methodRef = new MemberRef(clazz.name, method.name, method.desc); var methodRef = new MemberRef(clazz, method);
methodOps.put(methodRef, match.get(2).getOpcode()); methodOps.put(methodRef, match.get(2).getOpcode());
}); });
} }
@ -67,7 +67,7 @@ public final class BitwiseOpTransformer extends Transformer {
@Override @Override
protected boolean transformClass(ClassPath classPath, Library library, 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, m)));
return false; return false;
} }
@ -80,7 +80,7 @@ public final class BitwiseOpTransformer extends Transformer {
} }
var invokestatic = (MethodInsnNode) insn; var invokestatic = (MethodInsnNode) insn;
var methodRef = new MemberRef(invokestatic.owner, invokestatic.name, invokestatic.desc); var methodRef = new MemberRef(invokestatic);
var opcode = methodOps.get(methodRef); var opcode = methodOps.get(methodRef);
if (opcode != null) { if (opcode != null) {
it.set(new InsnNode(opcode)); it.set(new InsnNode(opcode));

@ -55,19 +55,19 @@ public final class CounterTransformer extends Transformer {
} }
var fieldInsn = (FieldInsnNode) insn; var fieldInsn = (FieldInsnNode) insn;
references.merge(new MemberRef(fieldInsn.owner, fieldInsn.name, fieldInsn.desc), 1, Integer::sum); references.merge(new MemberRef(fieldInsn), 1, Integer::sum);
} }
RESET_PATTERN.match(method).forEach(match -> { RESET_PATTERN.match(method).forEach(match -> {
var putstatic = (FieldInsnNode) match.get(1); var putstatic = (FieldInsnNode) match.get(1);
resets.merge(new MemberRef(putstatic.owner, putstatic.name, putstatic.desc), 1, Integer::sum); resets.merge(new MemberRef(putstatic), 1, Integer::sum);
}); });
INCREMENT_PATTERN.match(method).forEach(match -> { INCREMENT_PATTERN.match(method).forEach(match -> {
var getstatic = (FieldInsnNode) match.get(0); var getstatic = (FieldInsnNode) match.get(0);
var putstatic = (FieldInsnNode) match.get(3); var putstatic = (FieldInsnNode) match.get(3);
if (getstatic.owner.equals(putstatic.owner) && getstatic.name.equals(putstatic.name) && getstatic.desc.equals(putstatic.desc)) { if (getstatic.owner.equals(putstatic.owner) && getstatic.name.equals(putstatic.name) && getstatic.desc.equals(putstatic.desc)) {
increments.merge(new MemberRef(putstatic.owner, putstatic.name, putstatic.desc), 1, Integer::sum); increments.merge(new MemberRef(putstatic), 1, Integer::sum);
} }
}); });
} }
@ -99,7 +99,7 @@ public final class CounterTransformer extends Transformer {
public boolean transformCode(ClassPath classPath, Library library, 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))) {
match.forEach(method.instructions::remove); match.forEach(method.instructions::remove);
} }
}); });
@ -109,7 +109,7 @@ public final class CounterTransformer extends Transformer {
var putstatic = (FieldInsnNode) match.get(3); var putstatic = (FieldInsnNode) match.get(3);
if (getstatic.owner.equals(putstatic.owner) && getstatic.name.equals(putstatic.name) && getstatic.desc.equals(putstatic.desc) && if (getstatic.owner.equals(putstatic.owner) && getstatic.name.equals(putstatic.name) && getstatic.desc.equals(putstatic.desc) &&
counters.contains(new MemberRef(putstatic.owner, putstatic.name, putstatic.desc))) { counters.contains(new MemberRef(putstatic))) {
match.forEach(method.instructions::remove); match.forEach(method.instructions::remove);
} }
}); });

@ -241,7 +241,7 @@ public final class DummyArgTransformer extends Transformer {
@Override @Override
protected boolean transformCode(ClassPath classPath, Library library, 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, method));
var stores = new boolean[method.maxLocals]; var stores = new boolean[method.maxLocals];
@ -301,7 +301,7 @@ public final class DummyArgTransformer extends Transformer {
} }
} }
var callee = inheritedMethodSets.get(new MemberRef(invoke.owner, invoke.name, invoke.desc)); var callee = inheritedMethodSets.get(new MemberRef(invoke));
if (callee == null) { if (callee == null) {
return; return;
} }
@ -334,7 +334,7 @@ public final class DummyArgTransformer extends Transformer {
case Opcodes.INVOKESTATIC: case Opcodes.INVOKESTATIC:
case Opcodes.INVOKEINTERFACE: case Opcodes.INVOKEINTERFACE:
var invoke = (MethodInsnNode) insn; var invoke = (MethodInsnNode) insn;
var invokedMethod = inheritedMethodSets.get(new MemberRef(invoke.owner, invoke.name, invoke.desc)); var invokedMethod = inheritedMethodSets.get(new MemberRef(invoke));
if (invokedMethod == null) { if (invokedMethod == null) {
continue; continue;
} }

@ -52,7 +52,7 @@ public final class OpaquePredicateTransformer extends Transformer {
FLOW_OBSTRUCTOR_INITIALIZER_MATCHER.match(method).forEach(match -> { FLOW_OBSTRUCTOR_INITIALIZER_MATCHER.match(method).forEach(match -> {
/* add flow obstructor to set */ /* add flow obstructor to set */
var putstatic = (FieldInsnNode) match.get(match.size() - 1); var putstatic = (FieldInsnNode) match.get(match.size() - 1);
flowObstructors.add(new MemberRef(putstatic.owner, putstatic.name, putstatic.desc)); flowObstructors.add(new MemberRef(putstatic));
/* remove initializer */ /* remove initializer */
match.forEach(method.instructions::remove); match.forEach(method.instructions::remove);
@ -64,7 +64,7 @@ public final class OpaquePredicateTransformer extends Transformer {
} }
private boolean isFlowObstructor(FieldInsnNode insn) { private boolean isFlowObstructor(FieldInsnNode insn) {
return flowObstructors.contains(new MemberRef(insn.owner, insn.name, insn.desc)); return flowObstructors.contains(new MemberRef(insn));
} }
private boolean isOpaquePredicate(MethodNode method, List<AbstractInsnNode> match) { private boolean isOpaquePredicate(MethodNode method, List<AbstractInsnNode> match) {

@ -59,7 +59,7 @@ public final class ResetTransformer extends Transformer {
continue; continue;
} }
return new MemberRef(invoke.owner, invoke.name, invoke.desc); return new MemberRef(invoke);
} }
return null; return null;
@ -74,7 +74,7 @@ public final class ResetTransformer extends Transformer {
} }
var invoke = (MethodInsnNode) insn; var invoke = (MethodInsnNode) insn;
resetMethods.add(new MemberRef(invoke.owner, invoke.name, invoke.desc)); resetMethods.add(new MemberRef(invoke));
} }
} }
@ -117,7 +117,7 @@ public final class ResetTransformer extends Transformer {
@Override @Override
protected boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) { protected boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) {
clazz.methods.removeIf(m -> resetMethods.contains(new MemberRef(clazz.name, m.name, m.desc))); clazz.methods.removeIf(m -> resetMethods.contains(new MemberRef(clazz, m)));
return false; return false;
} }

@ -75,7 +75,7 @@ public final class UnusedArgTransformer extends Transformer {
} }
private void populateRetainedArgs(ClassPath classPath, ClassNode clazz, MethodNode method) throws AnalyzerException { private void populateRetainedArgs(ClassPath classPath, ClassNode clazz, MethodNode method) throws AnalyzerException {
var partition = inheritedMethodSets.get(new MemberRef(clazz.name, method.name, method.desc)); var partition = inheritedMethodSets.get(new MemberRef(clazz, method));
var localToArgMap = createLocalToArgMap(method); var localToArgMap = createLocalToArgMap(method);
var analyzer = new Analyzer<>(new ConstSourceInterpreter()); var analyzer = new Analyzer<>(new ConstSourceInterpreter());
@ -103,7 +103,7 @@ public final class UnusedArgTransformer extends Transformer {
case Opcodes.INVOKESTATIC: case Opcodes.INVOKESTATIC:
case Opcodes.INVOKEINTERFACE: case Opcodes.INVOKEINTERFACE:
var invoke = (MethodInsnNode) insn; var invoke = (MethodInsnNode) insn;
var invokePartition = inheritedMethodSets.get(new MemberRef(invoke.owner, invoke.name, invoke.desc)); var invokePartition = inheritedMethodSets.get(new MemberRef(invoke));
if (invokePartition == null || TypedRemapper.isMethodImmutable(classPath, invokePartition)) { if (invokePartition == null || TypedRemapper.isMethodImmutable(classPath, invokePartition)) {
continue; continue;
} }
@ -142,7 +142,7 @@ public final class UnusedArgTransformer extends Transformer {
} }
var methodInsn = (MethodInsnNode) insn; var methodInsn = (MethodInsnNode) insn;
var partition = inheritedMethodSets.get(new MemberRef(methodInsn.owner, methodInsn.name, methodInsn.desc)); var partition = inheritedMethodSets.get(new MemberRef(methodInsn));
if (partition == null || TypedRemapper.isMethodImmutable(classPath, partition)) { if (partition == null || TypedRemapper.isMethodImmutable(classPath, partition)) {
continue; continue;
} }
@ -174,7 +174,7 @@ public final class UnusedArgTransformer extends Transformer {
@Override @Override
protected boolean postTransformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) { protected boolean postTransformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) {
/* delete unused int args from the method itself */ /* delete unused int args from the method itself */
var partition = inheritedMethodSets.get(new MemberRef(clazz.name, method.name, method.desc)); var partition = inheritedMethodSets.get(new MemberRef(clazz, method));
if (TypedRemapper.isMethodImmutable(classPath, partition)) { if (TypedRemapper.isMethodImmutable(classPath, partition)) {
return false; return false;
} }

Loading…
Cancel
Save