Search in sources :

Example 1 with IDiv

use of net.runelite.asm.attributes.code.instructions.IDiv in project runelite by runelite.

the class MultiplyOneDeobfuscatorTest method test2.

// iconst_1
// iconst_m1
// iload                 5
// if_icmpeq             LABEL0x56d1
// iload                 5
// iconst_1
// if_icmpne             LABEL0x56e8
// goto                  LABEL0x56d1
// LABEL0x56d1:
// getstatic             class139/field2130 I
// ldc_w                 -1440517609
// imul
// goto                  LABEL0x5708
// LABEL0x56e8:
// getstatic             class139/field2130 I
// ldc_w                 -1440517609
// imul
// getstatic             client/field377 I
// iadd
// iconst_2
// idiv
// LABEL0x5708:
// imul
// putstatic             client/field377 I
// 
// client.field377 = 1 * (-1 != var5 && var5 != 1?(class139.field2130 + client.field377) / 2:class139.field2130);
@Test
public void test2() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0), new LDC(ins, 2), new IStore(ins, 1) };
    for (Instruction i : prepareVariables) ins.addInstruction(i);
    Label label = new Label(ins), label2 = new Label(ins), label3 = new Label(ins);
    LDC one = new LDC(ins, 1);
    IMul mul = new IMul(ins);
    Instruction[] body = { one, new LDC(ins, -1), new ILoad(ins, 0), new IfICmpEq(ins, label), new Goto(ins, label2), label, new ILoad(ins, 1), new LDC(ins, -1440517609), new IDiv(ins), new Goto(ins, label3), label2, new ILoad(ins, 1), new LDC(ins, -1440517609), new IDiv(ins), label3, mul, new VReturn(ins) };
    for (Instruction i : body) ins.addInstruction(i);
    // check execution runs ok
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    Deobfuscator d = new MultiplyOneDeobfuscator(false);
    d.run(group);
    Assert.assertTrue(one.getInstructions() == null);
    Assert.assertTrue(mul.getInstructions() == null);
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) IStore(net.runelite.asm.attributes.code.instructions.IStore) Goto(net.runelite.asm.attributes.code.instructions.Goto) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) IDiv(net.runelite.asm.attributes.code.instructions.IDiv) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Aggregations

ClassGroup (net.runelite.asm.ClassGroup)1 Code (net.runelite.asm.attributes.Code)1 Instruction (net.runelite.asm.attributes.code.Instruction)1 Instructions (net.runelite.asm.attributes.code.Instructions)1 Label (net.runelite.asm.attributes.code.Label)1 Goto (net.runelite.asm.attributes.code.instructions.Goto)1 IDiv (net.runelite.asm.attributes.code.instructions.IDiv)1 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)1 IMul (net.runelite.asm.attributes.code.instructions.IMul)1 IStore (net.runelite.asm.attributes.code.instructions.IStore)1 IfICmpEq (net.runelite.asm.attributes.code.instructions.IfICmpEq)1 LDC (net.runelite.asm.attributes.code.instructions.LDC)1 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)1 Execution (net.runelite.asm.execution.Execution)1 Deobfuscator (net.runelite.deob.Deobfuscator)1 Test (org.junit.Test)1