Search in sources :

Example 11 with Code

use of net.runelite.asm.attributes.Code in project runelite by runelite.

the class MultiplicationDeobfuscatorTest method test1.

// aload                 2
// ldc_w                 1587543155
// iload                 4
// imul
// dup_x1
// ldc_w                 -2130376517
// imul
// putfield              class2/field279 I
// ldc_w                 -67313687
// imul
// putstatic             class29/field949 I
@Test
public void test1() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(5);
    // 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, 1587543155), constant2 = new LDC(ins, -2130376517), constant3 = new LDC(ins, -67313687);
    Instruction[] body = { // for dup_x1 to place before this
    new LDC(ins, 0), constant1, new ILoad(ins, 0), new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), new Pop(ins), new Pop(ins), constant3, new IMul(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    // check execution runs ok
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
    assert constant1.getConstantAsInt() * constant3.getConstantAsInt() == -1_095_175_765;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(1, constant2.getConstantAsInt());
    Assert.assertEquals(-1_095_175_765, constant3.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 Code

use of net.runelite.asm.attributes.Code in project runelite by runelite.

the class MultiplicationDeobfuscatorTest method test4.

@Test
public void test4() {
    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) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    LDC constant1 = new LDC(ins, 1807370871);
    LDC constant2 = new LDC(ins, 981643079);
    Label label1 = new Label(ins);
    Instruction[] body = { new ILoad(ins, 0), new LDC(ins, 2), new IMul(ins), new LDC(ins, 0), new IfEq(ins, label1), new Pop(ins), new LDC(ins, 3), label1, constant1, new IMul(ins), constant2, 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() * 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) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) 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 Code

use of net.runelite.asm.attributes.Code in project runelite by runelite.

the class MultiplicationDeobfuscatorTest method test13.

// sipush                512
// ldc                   -688421113
// imul
// ldc                   -585812297
// imul
// putstatic             class134/field2009 I
@Test
public void test13() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    LDC constant1 = new LDC(ins, -688421113);
    LDC constant2 = new LDC(ins, -585812297);
    Instruction[] body = { new SiPush(ins, (short) 512), constant1, new IMul(ins), constant2, 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() * constant2.getConstantAsInt() == 1;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(1, constant2.getConstantAsInt());
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) 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) Test(org.junit.Test)

Example 14 with Code

use of net.runelite.asm.attributes.Code 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)

Example 15 with Code

use of net.runelite.asm.attributes.Code in project runelite by runelite.

the class ModArith method insertGetterSetterMuls.

private void insertGetterSetterMuls(Encryption encr) {
    // before setfield insert imul * getter
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null) {
                continue;
            }
            Instructions ins = code.getInstructions();
            List<Instruction> ilist = ins.getInstructions();
            for (int i = 0; i < ilist.size(); ++i) {
                Instruction in = ilist.get(i);
                if (in instanceof SetFieldInstruction) {
                    SetFieldInstruction sfi = (SetFieldInstruction) in;
                    Field f = sfi.getMyField();
                    if (f == null) {
                        continue;
                    }
                    Pair p = encr.getField(f.getPoolField());
                    if (p == null) {
                        continue;
                    }
                    // insert imul
                    if (p.getType() == Integer.class) {
                        ilist.add(i++, new LDC(ins, (int) p.getter));
                        ilist.add(i++, new IMul(ins));
                    } else if (p.getType() == Long.class) {
                        ilist.add(i++, new LDC(ins, (long) p.getter));
                        ilist.add(i++, new LMul(ins));
                    } else {
                        throw new IllegalStateException();
                    }
                } else if (in instanceof GetFieldInstruction) {
                    GetFieldInstruction sfi = (GetFieldInstruction) in;
                    Field f = sfi.getMyField();
                    if (f == null) {
                        continue;
                    }
                    Pair p = encr.getField(f.getPoolField());
                    if (p == null) {
                        continue;
                    }
                    // imul
                    if (p.getType() == Integer.class) {
                        ilist.add(++i, new LDC(ins, (int) p.setter));
                        ilist.add(++i, new IMul(ins));
                    } else if (p.getType() == Long.class) {
                        ilist.add(++i, new LDC(ins, (long) p.setter));
                        ilist.add(++i, new LMul(ins));
                    } else {
                        throw new IllegalStateException();
                    }
                }
            }
        }
    }
}
Also used : SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) ClassFile(net.runelite.asm.ClassFile) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) DivisionInstruction(net.runelite.asm.attributes.code.instruction.types.DivisionInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) ArrayStoreInstruction(net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) Field(net.runelite.asm.Field) IMul(net.runelite.asm.attributes.code.instructions.IMul) LMul(net.runelite.asm.attributes.code.instructions.LMul) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Aggregations

Code (net.runelite.asm.attributes.Code)62 Instruction (net.runelite.asm.attributes.code.Instruction)49 Instructions (net.runelite.asm.attributes.code.Instructions)45 LDC (net.runelite.asm.attributes.code.instructions.LDC)31 ClassGroup (net.runelite.asm.ClassGroup)30 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)30 Test (org.junit.Test)29 Method (net.runelite.asm.Method)26 IStore (net.runelite.asm.attributes.code.instructions.IStore)23 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)22 IMul (net.runelite.asm.attributes.code.instructions.IMul)21 Execution (net.runelite.asm.execution.Execution)21 Deobfuscator (net.runelite.deob.Deobfuscator)19 ClassFile (net.runelite.asm.ClassFile)18 Signature (net.runelite.asm.signature.Signature)15 Type (net.runelite.asm.Type)12 Pop (net.runelite.asm.attributes.code.instructions.Pop)12 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)11 Label (net.runelite.asm.attributes.code.Label)10 Field (net.runelite.asm.Field)8