Search in sources :

Example 1 with Method

use of net.runelite.asm.Method in project runelite by runelite.

the class Code method getMaxLocalsFromSig.

private int getMaxLocalsFromSig() {
    Method m = getMethod();
    int num = m.isStatic() ? 0 : 1;
    Signature sig = m.getDescriptor();
    for (int i = 0; i < sig.size(); ++i) num += sig.getTypeOfArg(i).getSize();
    return num;
}
Also used : Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method)

Example 2 with Method

use of net.runelite.asm.Method 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 3 with Method

use of net.runelite.asm.Method 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 4 with Method

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

Example 5 with Method

use of net.runelite.asm.Method in project runelite by runelite.

the class ParallelExecutorMapping method mapClass.

private void mapClass(StaticInitializerIndexer staticIndexer1, StaticInitializerIndexer staticIndexer2, Object one, Object two) {
    ClassFile cf1, cf2;
    if (one instanceof Field || two instanceof Field) {
        assert one instanceof Field;
        assert two instanceof Field;
        Field f1 = (Field) one;
        Field f2 = (Field) two;
        assert f1.isStatic() == f2.isStatic();
        if (staticIndexer1.isStatic(f1) && staticIndexer2.isStatic(f2)) {
            logger.debug("Mapping class of {} -> {} due to static initializer", f1, f2);
        } else if (f1.isStatic() || f2.isStatic()) {
            return;
        }
        cf1 = f1.getClassFile();
        cf2 = f2.getClassFile();
    } else if (one instanceof Method || two instanceof Method) {
        assert one instanceof Method;
        assert two instanceof Method;
        Method m1 = (Method) one;
        Method m2 = (Method) two;
        assert m1.isStatic() == m1.isStatic();
        if (m1.isStatic() || m2.isStatic()) {
            return;
        }
        cf1 = m1.getClassFile();
        cf2 = m2.getClassFile();
    } else {
        assert false;
        return;
    }
    belongs(cf1, group);
    belongs(cf2, group2);
    Mapping m = getMapping(cf1, cf2);
    m.inc();
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Aggregations

Method (net.runelite.asm.Method)90 ClassFile (net.runelite.asm.ClassFile)64 Field (net.runelite.asm.Field)34 Instruction (net.runelite.asm.attributes.code.Instruction)29 Code (net.runelite.asm.attributes.Code)28 Instructions (net.runelite.asm.attributes.code.Instructions)28 Signature (net.runelite.asm.signature.Signature)28 ClassGroup (net.runelite.asm.ClassGroup)20 ArrayList (java.util.ArrayList)18 Type (net.runelite.asm.Type)18 List (java.util.List)13 Test (org.junit.Test)13 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)10 DeobAnnotations (net.runelite.deob.DeobAnnotations)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)8 InstructionType (net.runelite.asm.attributes.code.InstructionType)8 Label (net.runelite.asm.attributes.code.Label)8