Search in sources :

Example 11 with Pop

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

the class MultiplicationDeobfuscatorTest method test6.

@Test
public void test6() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    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);
    }
    LDC constant1 = new LDC(ins, 575391417);
    LDC constant2 = new LDC(ins, -497786999);
    Instruction[] body = { new ILoad(ins, 0), new ILoad(ins, 1), new Dup_X1(ins), new Pop(ins), new Pop(ins), constant1, new IMul(ins), constant2, new IMul(ins), new Pop(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;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(1, constant2.getConstantAsInt());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) 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) Pop(net.runelite.asm.attributes.code.instructions.Pop) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 12 with Pop

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

the class MultiplicationDeobfuscatorTest method test7.

@Test
public void test7() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    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);
    }
    LDC constant1 = new LDC(ins, 2131037801), constant2 = new LDC(ins, -1306959399), constant3 = new LDC(ins, -1);
    Instruction[] body = { constant3, constant1, new IMul(ins), constant2, new IMul(ins), new Pop(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;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(-1, constant2.getConstantAsInt());
    Assert.assertEquals(1, constant3.getConstantAsInt());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) 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) Pop(net.runelite.asm.attributes.code.instructions.Pop) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 13 with Pop

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

the class MultiplicationDeobfuscatorTest method test2.

// aload_0
// dup
// getfield              class118/field2201 I
// ldc_w                 -2079217519
// imul
// ldc                   -2079217519
// iadd
// dup_x1
// ldc_w                 561453169
// imul
// putfield              class118/field2201 I
// ldc                   561453169
// imul
@Test
public void test2() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(4);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    LDC constant1 = new LDC(ins, -2079217519), constant2 = new LDC(ins, -2079217519), constant3 = new LDC(ins, 561453169), constant4 = new LDC(ins, 561453169);
    Instruction[] body = { // for dup_x1 to place before this
    new LDC(ins, 0), new ILoad(ins, 0), constant1, new IMul(ins), constant2, new IAdd(ins), // result, 0, result
    new Dup_X1(ins), constant3, new IMul(ins), new Pop(ins), new Pop(ins), constant4, new IMul(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    assert constant1.getConstantAsInt() * constant3.getConstantAsInt() == 1;
    assert constant2.getConstantAsInt() * constant4.getConstantAsInt() == 1;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(1, constant2.getConstantAsInt());
    Assert.assertEquals(1, constant3.getConstantAsInt());
    Assert.assertEquals(1, constant4.getConstantAsInt());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) 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) Pop(net.runelite.asm.attributes.code.instructions.Pop) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 14 with Pop

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

the class ExprArgOrderTest method test3.

@Test
public void test3() {
    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) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { // 512 + (3 + var1) -> var1 + 3 + 512
    new LDC(ins, 512), new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new IAdd(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    // 2: iload
    // 3: iconst 3
    // 4: iadd
    // 5: ldc
    // 6: add
    assertEquals(IADD, instructions.get(4).getType());
    assertEquals(IADD, instructions.get(6).getType());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 15 with Pop

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

the class ExprArgOrderTest method test.

@Test
public void test() {
    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) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { // 2
    new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Aggregations

Pop (net.runelite.asm.attributes.code.instructions.Pop)15 Instructions (net.runelite.asm.attributes.code.Instructions)14 LDC (net.runelite.asm.attributes.code.instructions.LDC)13 Code (net.runelite.asm.attributes.Code)12 Instruction (net.runelite.asm.attributes.code.Instruction)12 ClassGroup (net.runelite.asm.ClassGroup)11 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)11 Test (org.junit.Test)11 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)10 IStore (net.runelite.asm.attributes.code.instructions.IStore)10 IMul (net.runelite.asm.attributes.code.instructions.IMul)7 Execution (net.runelite.asm.execution.Execution)7 Deobfuscator (net.runelite.deob.Deobfuscator)7 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)6 LDC (net.runelite.asm.attributes.code.InstructionType.LDC)4 Method (net.runelite.asm.Method)2 Label (net.runelite.asm.attributes.code.Label)2 Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)2 InvokeSpecial (net.runelite.asm.attributes.code.instructions.InvokeSpecial)2 SiPush (net.runelite.asm.attributes.code.instructions.SiPush)2