From 318f906ab5d880572445770411d9daa2af619c18 Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 27 Aug 2019 19:16:33 +0100 Subject: [PATCH] Make DummyLocalTransformer type-sensitive This catches a few more dummy locals than the previous code. --- .../deob/transform/DummyLocalTransformer.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/deob/src/main/java/dev/openrs2/deob/transform/DummyLocalTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/DummyLocalTransformer.java index 7f5b1d0c..cce93fe6 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/DummyLocalTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/DummyLocalTransformer.java @@ -14,6 +14,8 @@ import org.slf4j.LoggerFactory; public final class DummyLocalTransformer extends Transformer { private static final Logger logger = LoggerFactory.getLogger(DummyLocalTransformer.class); + private static final int TYPES = 5; + private static final ImmutableSet LOAD_OPCODES = ImmutableSet.of( Opcodes.ILOAD, Opcodes.LLOAD, @@ -43,15 +45,17 @@ public final class DummyLocalTransformer extends Transformer { * XXX(gpe): this is primitive (ideally we'd do a proper data flow * analysis, but we'd need to do it in reverse and ASM only supports * forward data flow), however, it seems to be good enough to catch - * everything. + * most dummy locals. */ - var loads = new boolean[method.maxLocals]; + var loads = new boolean[TYPES][method.maxLocals]; for (var it = method.instructions.iterator(); it.hasNext(); ) { var insn = it.next(); - if (LOAD_OPCODES.contains(insn.getOpcode())) { + var opcode = insn.getOpcode(); + if (LOAD_OPCODES.contains(opcode)) { + var type = opcode - Opcodes.ILOAD; var load = (VarInsnNode) insn; - loads[load.var] = true; + loads[type][load.var] = true; } } @@ -62,8 +66,9 @@ public final class DummyLocalTransformer extends Transformer { continue; } + var type = opcode - Opcodes.ISTORE; var store = (VarInsnNode) insn; - if (loads[store.var]) { + if (loads[type][store.var]) { continue; }