From 5fd24889881ca8add230188bd179ea6b2ad8c96d Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 25 Aug 2019 13:53:20 +0100 Subject: [PATCH] Fix right clicking on modern versions of Java --- .../transform/RightClickTransformer.java | 65 +++++++++++++++++++ deob/pom.xml | 5 ++ .../java/dev/openrs2/deob/Deobfuscator.java | 2 + 3 files changed, 72 insertions(+) create mode 100644 bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.java diff --git a/bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.java b/bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.java new file mode 100644 index 00000000..cb4e387c --- /dev/null +++ b/bundler/src/main/java/dev/openrs2/bundler/transform/RightClickTransformer.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); + } +} diff --git a/deob/pom.xml b/deob/pom.xml index a98098fd..7ad2ee07 100644 --- a/deob/pom.xml +++ b/deob/pom.xml @@ -27,6 +27,11 @@ openrs2-asm ${project.version} + + dev.openrs2 + openrs2-bundler + ${project.version} + dev.openrs2 openrs2-deob-annotations diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java index f151fe32..09c5bf13 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java @@ -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 TRANSFORMERS = List.of( + new RightClickTransformer(), new OpaquePredicateTransformer(), new ExceptionTracingTransformer(), new BitShiftTransformer(),