Search in sources :

Example 1 with Code

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

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

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

the class ReflectionTransformer method transform.

private void transform(Method method) {
    Code code = method.getCode();
    if (code == null) {
        return;
    }
    Instructions ins = code.getInstructions();
    for (Instruction i : new ArrayList<>(ins.getInstructions())) {
        transformFindClass(i);
        transformMethodName(ins, i);
        transformGetParameterTypes(ins, i);
        transformGetDeclaredField(ins, i);
        transformSetInt(ins, i);
        transformGetInt(ins, i);
        transformInvokeVirtual(ins, i);
    }
}
Also used : ArrayList(java.util.ArrayList) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 4 with Code

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

the class RuneliteBufferTransformer method injectLengthHeader.

/**
 * inject the length header after the packet opcode
 *
 * @param group
 */
private void injectLengthHeader(ClassGroup group) {
    RWOpcodeFinder rw = new RWOpcodeFinder(group);
    rw.find();
    Method writeOpcode = rw.getWriteOpcode();
    Code code = writeOpcode.getCode();
    Instructions instructions = code.getInstructions();
    List<Instruction> ins = instructions.getInstructions();
    Instruction start = ins.get(0);
    Instruction end = ins.stream().filter(i -> i.getType() == RETURN).findFirst().get();
    Label labelForStart = instructions.createLabelFor(start);
    Label labelForEnd = instructions.createLabelFor(end);
    final net.runelite.asm.pool.Field runelitePacketField = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(findClient(group).getName()), RUNELITE_PACKET, Type.BOOLEAN);
    int idx = ins.indexOf(labelForStart);
    instructions.addInstruction(idx++, new GetStatic(instructions, runelitePacketField));
    instructions.addInstruction(idx++, new IfEq(instructions, labelForStart));
    net.runelite.asm.pool.Method method = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(writeOpcode.getClassFile().getName()), RUNELITE_FINISH_PACKET, new Signature("()V"));
    instructions.addInstruction(idx++, new ALoad(instructions, 0));
    instructions.addInstruction(idx++, new InvokeVirtual(instructions, method));
    idx = ins.indexOf(labelForEnd);
    instructions.addInstruction(idx++, new GetStatic(instructions, runelitePacketField));
    instructions.addInstruction(idx++, new IfEq(instructions, labelForEnd));
    method = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(writeOpcode.getClassFile().getName()), RUNELITE_INIT_PACKET, new Signature("()V"));
    instructions.addInstruction(idx++, new ALoad(instructions, 0));
    instructions.addInstruction(idx++, new InvokeVirtual(instructions, method));
    logger.info("Injected finish/init packet calls into {}", writeOpcode);
}
Also used : RWOpcodeFinder(net.runelite.deob.c2s.RWOpcodeFinder) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) ALoad(net.runelite.asm.attributes.code.instructions.ALoad)

Example 5 with Code

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

the class BufferMethodInjector method inject.

private void inject(ClassFile bufferClass, Method method) {
    assert method.getExceptions().getExceptions().isEmpty();
    Method newMethod = new Method(bufferClass, method.getName(), method.getDescriptor());
    Code code = new Code(newMethod);
    newMethod.setCode(code);
    method.getCode().getInstructions().getInstructions().stream().forEach(i -> {
        if (!(i instanceof Label)) {
            i = i.clone();
        }
        if (i instanceof FieldInstruction) {
            FieldInstruction fi = (FieldInstruction) i;
            if (fi.getField().getName().equals("offset")) {
                fi.setField(bp.getOffset().getPoolField());
            } else if (fi.getField().getName().equals("payload")) {
                fi.setField(bp.getBuffer().getPoolField());
            } else if (fi.getField().getName().equals("runeliteLengthOffset")) {
                fi.setField(bufferClass.findField("runeliteLengthOffset").getPoolField());
            }
        }
        i.setInstructions(code.getInstructions());
        code.getInstructions().addInstruction(i);
    });
    code.getExceptions().getExceptions().addAll(method.getCode().getExceptions().getExceptions());
    bufferClass.addMethod(newMethod);
}
Also used : Label(net.runelite.asm.attributes.code.Label) Method(net.runelite.asm.Method) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) Code(net.runelite.asm.attributes.Code)

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