Search in sources :

Example 1 with VReturn

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

the class OpcodesTransformer method transform.

@Override
public void transform(ClassGroup group) {
    ClassFile runeliteOpcodes = group.findClass(RUNELITE_OPCODES);
    if (runeliteOpcodes == null) {
        runeliteOpcodes = new ClassFile(group);
        runeliteOpcodes.setName(RUNELITE_OPCODES);
        runeliteOpcodes.setSuperName(Type.OBJECT.getInternalName());
        runeliteOpcodes.setAccess(Opcodes.ACC_PUBLIC);
        group.addClass(runeliteOpcodes);
    } else {
        runeliteOpcodes.getFields().clear();
    }
    Method clinit = runeliteOpcodes.findMethod("<clinit>");
    if (clinit == null) {
        clinit = new Method(runeliteOpcodes, "<clinit>", new Signature("()V"));
        clinit.setStatic();
        Code code = new Code(clinit);
        code.setMaxStack(1);
        clinit.setCode(code);
        runeliteOpcodes.addMethod(clinit);
        Instructions instructions = code.getInstructions();
        instructions.addInstruction(new VReturn(instructions));
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn)

Example 2 with VReturn

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

the class ClientErrorTransformer method transform.

private void transform(Method m) {
    if (!m.isStatic() || m.getDescriptor().size() != 2 || !m.getDescriptor().getTypeOfArg(0).equals(Type.STRING) || !m.getDescriptor().getTypeOfArg(1).equals(Type.THROWABLE))
        return;
    Code code = m.getCode();
    Instructions ins = code.getInstructions();
    /*
			Makes it so the old code in this method is logically dead,
			letting the mapper map it but making it so it's never executed.
		 */
    // load throwable
    Instruction aload0 = new ALoad(ins, 1);
    IfNull ifNull = new IfNull(ins, InstructionType.IFNULL);
    ifNull.setTo(ins.createLabelFor(ins.getInstructions().get(0)));
    // load throwable
    Instruction aload1 = new ALoad(ins, 1);
    InvokeVirtual printStackTrace = new InvokeVirtual(ins, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("java/lang/Throwable"), "printStackTrace", new Signature("()V")));
    Instruction ret = new VReturn(ins);
    ins.addInstruction(0, aload0);
    ins.addInstruction(1, ifNull);
    ins.addInstruction(2, aload1);
    ins.addInstruction(3, printStackTrace);
    ins.addInstruction(4, ret);
    done = true;
}
Also used : Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) IfNull(net.runelite.asm.attributes.code.instructions.IfNull) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) ALoad(net.runelite.asm.attributes.code.instructions.ALoad)

Example 3 with VReturn

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

the class ClassGroupFactory method addVoidMethod.

private static void addVoidMethod(ClassFile cf, String name) {
    Method method = new Method(cf, name, new Signature("()V"));
    method.setStatic();
    cf.addMethod(method);
    Code code = new Code(method);
    method.setCode(code);
    Instructions ins = code.getInstructions();
    ins.addInstruction(new VReturn(ins));
}
Also used : Signature(net.runelite.asm.signature.Signature) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn)

Example 4 with VReturn

use of net.runelite.asm.attributes.code.instructions.VReturn 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 5 with VReturn

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

Aggregations

VReturn (net.runelite.asm.attributes.code.instructions.VReturn)31 Code (net.runelite.asm.attributes.Code)30 Instructions (net.runelite.asm.attributes.code.Instructions)30 Instruction (net.runelite.asm.attributes.code.Instruction)28 ClassGroup (net.runelite.asm.ClassGroup)26 LDC (net.runelite.asm.attributes.code.instructions.LDC)26 Test (org.junit.Test)25 IStore (net.runelite.asm.attributes.code.instructions.IStore)23 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)21 IMul (net.runelite.asm.attributes.code.instructions.IMul)19 Execution (net.runelite.asm.execution.Execution)18 Deobfuscator (net.runelite.deob.Deobfuscator)18 Pop (net.runelite.asm.attributes.code.instructions.Pop)11 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)10 Label (net.runelite.asm.attributes.code.Label)9 LDC (net.runelite.asm.attributes.code.InstructionType.LDC)6 Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)6 AConstNull (net.runelite.asm.attributes.code.instructions.AConstNull)5 IfEq (net.runelite.asm.attributes.code.instructions.IfEq)5 SiPush (net.runelite.asm.attributes.code.instructions.SiPush)5