Search in sources :

Example 1 with Pop

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

the class GetPathTransformer method removeInvoke.

private void removeInvoke(Instruction i) {
    Instructions ins = i.getInstructions();
    int idx = ins.getInstructions().indexOf(i);
    ins.remove(i);
    // pop File
    ins.getInstructions().add(idx, new Pop(ins));
    ins.getInstructions().add(idx + 1, new LDC(ins, ""));
}
Also used : Pop(net.runelite.asm.attributes.code.instructions.Pop) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC)

Example 2 with Pop

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

the class MaxMemoryTransformer method insert.

private void insert(Instructions ins, int idx) {
    Class randomClass = new net.runelite.asm.pool.Class("java/util/Random");
    ins.getInstructions().remove(idx);
    // pop runtime
    ins.getInstructions().add(idx++, new Pop(ins));
    ins.getInstructions().add(idx++, new New(ins, randomClass));
    ins.getInstructions().add(idx++, new Dup(ins));
    // new Random
    ins.getInstructions().add(idx++, new InvokeSpecial(ins, new net.runelite.asm.pool.Method(randomClass, "<init>", new Signature("()V"))));
    ins.getInstructions().add(idx++, new LDC(ins, 31457280));
    // nextInt(31457280)
    ins.getInstructions().add(idx++, new InvokeVirtual(ins, new net.runelite.asm.pool.Method(randomClass, "nextInt", new Signature("(I)I"))));
    ins.getInstructions().add(idx++, new LDC(ins, 230686720));
    // 230686720 + nextInt(31457280)
    ins.getInstructions().add(idx++, new IAdd(ins));
    ins.getInstructions().add(idx++, new I2L(ins));
}
Also used : New(net.runelite.asm.attributes.code.instructions.New) I2L(net.runelite.asm.attributes.code.instructions.I2L) InvokeSpecial(net.runelite.asm.attributes.code.instructions.InvokeSpecial) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) Pop(net.runelite.asm.attributes.code.instructions.Pop) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) Class(net.runelite.asm.pool.Class) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Dup(net.runelite.asm.attributes.code.instructions.Dup)

Example 3 with Pop

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

the class ExprArgOrderTest method test2.

@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) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { // 2
    new ILoad(ins, 0), new LDC(ins, 3), new IAdd(ins), new Pop(ins), // 6
    new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new SiPush(ins, (short) 512), 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();
    // ensure this stays the same
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
    // 
    assertEquals(ILOAD, instructions.get(6).getType());
    assertEquals(SIPUSH, instructions.get(7).getType());
    assertEquals(IADD, instructions.get(8).getType());
    assertEquals(LDC, instructions.get(9).getType());
    assertEquals(IADD, instructions.get(10).getType());
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) 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 4 with Pop

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

the class ExprArgOrderTest 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);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { new SiPush(ins, (short) 600), new ILoad(ins, 0), new LDC(ins, 3), new IMul(ins), new IAdd(ins), new Pop(ins), new ILoad(ins, 0), new LDC(ins, 3), new IMul(ins), new SiPush(ins, (short) 600), 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();
    for (int i = 2; i <= 7; ++i) {
        assertEquals(instructions.get(i).getType(), instructions.get(i + 6).getType());
    }
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) 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) IMul(net.runelite.asm.attributes.code.instructions.IMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 5 with Pop

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

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