Fix right clicking on modern versions of Java

bzip2
Graham 5 years ago
parent 555620887f
commit 5fd2488988
  1. 65
      bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.java
  2. 5
      deob/pom.xml
  3. 2
      deob/src/main/java/dev/openrs2/deob/Deobfuscator.java

@ -0,0 +1,65 @@
package dev.openrs2.bundler.transform;
import dev.openrs2.asm.classpath.ClassPath;
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.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.analysis.AnalyzerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class RightClickTransformer extends Transformer {
private static final Logger logger = LoggerFactory.getLogger(RightClickTransformer.class);
private int metaDownCalls;
@Override
protected void preTransform(ClassPath classPath) throws AnalyzerException {
metaDownCalls = 0;
}
@Override
protected boolean transformCode(ClassNode clazz, MethodNode method) throws AnalyzerException {
for (var it = method.instructions.iterator(); it.hasNext(); ) {
var insn = it.next();
if (insn.getOpcode() != Opcodes.INVOKEVIRTUAL) {
continue;
}
var invokevirtual = (MethodInsnNode) insn;
if (!invokevirtual.owner.equals("java/awt/event/MouseEvent")) {
continue;
}
if (!invokevirtual.name.equals("isMetaDown")) {
continue;
}
if (!invokevirtual.desc.equals("()Z")) {
continue;
}
invokevirtual.name = "getModifiersEx";
invokevirtual.desc = "()I";
var list = new InsnList();
list.add(new FieldInsnNode(Opcodes.GETSTATIC, "java/awt/event/MouseEvent", "BUTTON3_DOWN_MASK", "I"));
list.add(new InsnNode(Opcodes.IAND));
method.instructions.insert(invokevirtual, list);
metaDownCalls++;
}
return false;
}
@Override
protected void postTransform(ClassPath classPath) throws AnalyzerException {
logger.info("Replaced {} isMetaDown calls with getModifiersEx", metaDownCalls);
}
}

@ -27,6 +27,11 @@
<artifactId>openrs2-asm</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.openrs2</groupId>
<artifactId>openrs2-bundler</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.openrs2</groupId>
<artifactId>openrs2-deob-annotations</artifactId>

@ -10,6 +10,7 @@ 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.bundler.transform.RightClickTransformer;
import dev.openrs2.deob.remap.ClassNamePrefixer;
import dev.openrs2.deob.remap.TypedRemapper;
import dev.openrs2.deob.transform.BitShiftTransformer;
@ -30,6 +31,7 @@ public final class Deobfuscator {
private static final Logger logger = LoggerFactory.getLogger(Deobfuscator.class);
private static final List<Transformer> TRANSFORMERS = List.of(
new RightClickTransformer(),
new OpaquePredicateTransformer(),
new ExceptionTracingTransformer(),
new BitShiftTransformer(),

Loading…
Cancel
Save