Make DummyLocalTransformer type-sensitive

This catches a few more dummy locals than the previous code.
master
Graham 5 years ago
parent 7b3ec975d9
commit 318f906ab5
  1. 15
      deob/src/main/java/dev/openrs2/deob/transform/DummyLocalTransformer.java

@ -14,6 +14,8 @@ import org.slf4j.LoggerFactory;
public final class DummyLocalTransformer extends Transformer { public final class DummyLocalTransformer extends Transformer {
private static final Logger logger = LoggerFactory.getLogger(DummyLocalTransformer.class); private static final Logger logger = LoggerFactory.getLogger(DummyLocalTransformer.class);
private static final int TYPES = 5;
private static final ImmutableSet<Integer> LOAD_OPCODES = ImmutableSet.of( private static final ImmutableSet<Integer> LOAD_OPCODES = ImmutableSet.of(
Opcodes.ILOAD, Opcodes.ILOAD,
Opcodes.LLOAD, 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 * 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 * 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 * 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(); ) { for (var it = method.instructions.iterator(); it.hasNext(); ) {
var insn = it.next(); 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; var load = (VarInsnNode) insn;
loads[load.var] = true; loads[type][load.var] = true;
} }
} }
@ -62,8 +66,9 @@ public final class DummyLocalTransformer extends Transformer {
continue; continue;
} }
var type = opcode - Opcodes.ISTORE;
var store = (VarInsnNode) insn; var store = (VarInsnNode) insn;
if (loads[store.var]) { if (loads[type][store.var]) {
continue; continue;
} }

Loading…
Cancel
Save