### Question:
DupDeobfuscator implements Deobfuscator { @Override public void run(ClassGroup group) { Execution e = new Execution(group); e.addMethodContextVisitor(m -> visit(m)); e.populateInitialMethods(); e.run(); logger.info("Replaced {} dup instructions", count); }  @Override void run(ClassGroup group);  }### Answer:
@Test public void test() { ClassGroup group = ClassGroupFactory.generateGroup(); Code code = group.findClass("test").findMethod("func").getCode(); Instructions ins = code.getInstructions(); code.setMaxStack(5); Instruction[] prepareVariables = { new LDC(ins, 1), new IStore(ins, 0) }; for (Instruction i : prepareVariables) { ins.addInstruction(i); } LDC constant1 = new LDC(ins, 1129258489), constant2 = new LDC(ins, -1692330935), constant3 = new LDC(ins, 1641298955), constant4 = new LDC(ins, 1043501435); Instruction body[] = { new AConstNull(ins), new AConstNull(ins), new ILoad(ins, 0), constant1, new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), new Pop2(ins), constant3, new IMul(ins), constant4, new IMul(ins), new Pop2(ins), new VReturn(ins) }; for (Instruction i : body) { ins.addInstruction(i); } Execution e = new Execution(group); e.populateInitialMethods(); e.run(); assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1; assert constant3.getConstantAsInt() * constant4.getConstantAsInt() * constant1.getConstantAsInt() == 1; Deobfuscator d = new DupDeobfuscator(); d.run(group); long dupCount = ins.getInstructions().stream() .filter(i -> i instanceof Dup_X1) .count(); Assert.assertEquals(0, dupCount); }
@Test public void test2() { ClassGroup group = ClassGroupFactory.generateGroup(); Code code = group.findClass("test").findMethod("func").getCode(); Instructions ins = code.getInstructions(); code.setMaxStack(3); Instruction body[] = { new AConstNull(ins), new Dup(ins), new GetField(ins, new Field(new Class("test"), "field", Type.INT)), new LDC(ins, 830083863), new IMul(ins), new LDC(ins, 830083863), new IAdd(ins), new Dup_X1(ins), new LDC(ins, 636900519), new IMul(ins), new VReturn(ins) }; for (Instruction i : body) { ins.addInstruction(i); } Execution e = new Execution(group); e.populateInitialMethods(); e.run(); Deobfuscator d = new DupDeobfuscator(); d.run(group); long dupCount = ins.getInstructions().stream() .filter(i -> i instanceof Dup) .count(); Assert.assertEquals(1, dupCount); dupCount = ins.getInstructions().stream() .filter(i -> i instanceof Dup_X1) .count(); Assert.assertEquals(0, dupCount); }