From 6520c157953522a966eef460744e3aecfba000a4 Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 12 Sep 2019 16:48:42 +0100 Subject: [PATCH] Remove redundant final modifiers --- .../java/dev/openrs2/deob/Deobfuscator.java | 4 +- .../deob/transform/AccessTransformer.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java index 537e207d..6f2860d9 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java @@ -14,6 +14,7 @@ import dev.openrs2.bundler.transform.HostCheckTransformer; import dev.openrs2.bundler.transform.MacResizeTransformer; import dev.openrs2.bundler.transform.RightClickTransformer; import dev.openrs2.deob.remap.PrefixRemapper; +import dev.openrs2.deob.transform.AccessTransformer; import dev.openrs2.deob.transform.BitShiftTransformer; import dev.openrs2.deob.transform.BitwiseOpTransformer; import dev.openrs2.deob.transform.CanvasTransformer; @@ -49,7 +50,8 @@ public final class Deobfuscator { new RemapTransformer(), new DummyArgTransformer(), new DummyLocalTransformer(), - new UnusedArgTransformer() + new UnusedArgTransformer(), + new AccessTransformer() ); public static void main(String[] args) throws IOException, AnalyzerException { diff --git a/deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java new file mode 100644 index 00000000..d0d336f7 --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/transform/AccessTransformer.java @@ -0,0 +1,39 @@ +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; +import org.objectweb.asm.tree.MethodNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AccessTransformer extends Transformer { + private static final Logger logger = LoggerFactory.getLogger(AccessTransformer.class); + + private int redundantFinals; + + @Override + protected void preTransform(ClassPath classPath) { + redundantFinals = 0; + } + + @Override + protected boolean preTransformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) { + if ((method.access & Opcodes.ACC_FINAL) == 0) { + return false; + } + + if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC)) != 0) { + method.access &= ~Opcodes.ACC_FINAL; + redundantFinals++; + } + return false; + } + + @Override + protected void postTransform(ClassPath classPath) { + logger.info("Removed {} redundant final modifiers", redundantFinals); + } +}