From 261cc87125314aafe1aa3879a4ea1360673c06a6 Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 29 Aug 2019 09:13:08 +0100 Subject: [PATCH] Add CachePathTransformer --- .../transform/CachePathTransformer.java | 44 +++++++++++++++++++ .../java/dev/openrs2/deob/Deobfuscator.java | 2 + 2 files changed, 46 insertions(+) create mode 100644 bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java diff --git a/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java b/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java new file mode 100644 index 00000000..3303175e --- /dev/null +++ b/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java @@ -0,0 +1,44 @@ +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.LdcInsnNode; +import org.objectweb.asm.tree.MethodNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class CachePathTransformer extends Transformer { + private static final Logger logger = LoggerFactory.getLogger(CachePathTransformer.class); + + private int paths; + + @Override + protected void preTransform(ClassPath classPath) { + paths = 0; + } + + @Override + protected boolean transformCode(ClassNode clazz, MethodNode method) { + for (var it = method.instructions.iterator(); it.hasNext(); ) { + var insn = it.next(); + if (insn.getOpcode() != Opcodes.LDC) { + continue; + } + + var ldc = (LdcInsnNode) insn; + if (ldc.cst.equals(".jagex_cache_") || ldc.cst.equals(".file_store_")) { + ldc.cst = ".openrs2_cache_"; + paths++; + } + } + + return false; + } + + @Override + protected void postTransform(ClassPath classPath) { + logger.info("Updated {} cache paths", paths); + } +} diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java index 47a3e703..398a9fe8 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java @@ -9,6 +9,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.CachePathTransformer; import dev.openrs2.bundler.transform.HostCheckTransformer; import dev.openrs2.bundler.transform.RightClickTransformer; import dev.openrs2.deob.remap.PrefixRemapper; @@ -32,6 +33,7 @@ public final class Deobfuscator { private static final ImmutableList TRANSFORMERS = ImmutableList.of( new OriginalNameTransformer(), + new CachePathTransformer(), new HostCheckTransformer(), new RightClickTransformer(), new OpaquePredicateTransformer(),