Search in sources :

Example 96 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class HandlerFinder method insertReturn.

private void insertReturn(Instructions ins, Instruction start, Instruction end) {
    assert end instanceof Label;
    int idx = ins.getInstructions().indexOf(end);
    assert idx != -1;
    Instruction before = ins.getInstructions().get(idx - 1);
    if (// XXX check isTerminal?
    before.getType() == InstructionType.RETURN) {
        return;
    }
    // insert return before end
    logger.info("Inserting return before {}", end);
    Instruction ret = new VReturn(ins);
    ins.addInstruction(idx, ret);
    Label label = ins.createLabelFor(ret);
    // Change jumps which go to the next handler to instead go to return
    for (Instruction i : ins.getInstructions()) {
        if (i instanceof JumpingInstruction) {
            JumpingInstruction j = (JumpingInstruction) i;
            if (i == start) {
                continue;
            }
            if (j.getJumps().size() == 1 && j.getJumps().get(0) == end) {
                j.setJumps(Collections.singletonList(label));
            }
        }
    }
}
Also used : JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Label(net.runelite.asm.attributes.code.Label) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) VReturn(net.runelite.asm.attributes.code.instructions.VReturn)

Example 97 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class PacketLengthFinder method run.

// getstatic             class272/field3690 [I
// getstatic             Client/packetType I
// iaload
// putstatic             Client/packetLength I
private void run(Code code) {
    if (code == null) {
        return;
    }
    Instructions instructions = code.getInstructions();
    Field type = packetType.getPacketType();
    for (int i = 0; i < instructions.getInstructions().size() - 3; ++i) {
        Instruction i1 = instructions.getInstructions().get(i), i2 = instructions.getInstructions().get(i + 1), i3 = instructions.getInstructions().get(i + 2), i4 = instructions.getInstructions().get(i + 3);
        if (!(i1 instanceof GetStatic)) {
            continue;
        }
        if (!(i2 instanceof GetStatic)) {
            continue;
        }
        GetStatic gs = (GetStatic) i2;
        if (gs.getMyField() != type) {
            continue;
        }
        if (!(i3 instanceof IALoad)) {
            continue;
        }
        if (!(i4 instanceof PutStatic)) {
            continue;
        }
        PutStatic ps = (PutStatic) i4;
        assert packetLength == null : "packetLength already found";
        packetLength = ps.getMyField();
        getArray = (GetStatic) i1;
        getType = gs;
        load = (IALoad) i3;
        store = ps;
        return;
    }
}
Also used : Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) IALoad(net.runelite.asm.attributes.code.instructions.IALoad) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic)

Example 98 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class PacketTypeFinder method run.

private void run(Code code) {
    if (code == null) {
        return;
    }
    Instructions instructions = code.getInstructions();
    for (int i = 0; i < instructions.getInstructions().size() - 1; ++i) {
        Instruction i1 = instructions.getInstructions().get(i), i2 = instructions.getInstructions().get(i + 1);
        if (i1 instanceof PushConstantInstruction && i2.getType() == InstructionType.PUTSTATIC) {
            PushConstantInstruction pci = (PushConstantInstruction) i1;
            SetFieldInstruction sfi = (SetFieldInstruction) i2;
            Field field = sfi.getMyField();
            if (Objects.equal(-1, pci.getConstant()) && field != null) {
                Integer count = sets.get(field);
                if (count == null) {
                    sets.put(field, 1);
                } else {
                    sets.put(field, count + 1);
                }
            }
        }
    }
}
Also used : Field(net.runelite.asm.Field) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 99 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class OpcodeReplacer method run.

public void run(ClassGroup group, Collection<PacketWrite> writes) {
    int count = 0;
    ClassFile runeliteOpcodes = group.findClass(RUNELITE_OPCODES);
    assert runeliteOpcodes != null : "Opcodes class must exist";
    for (PacketWrite wp : writes) {
        Instructions ins = wp.getInstructions();
        Instruction param = wp.getOpcodeIns();
        if (!(param instanceof PushConstantInstruction)) {
            continue;
        }
        final String fieldName = "PACKET_CLIENT_" + wp.getOpcode();
        net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(RUNELITE_OPCODES), fieldName, Type.INT);
        ins.replace(param, new GetStatic(ins, field));
        if (runeliteOpcodes.findField(fieldName) == null) {
            Field opField = new Field(runeliteOpcodes, fieldName, Type.INT);
            // ACC_FINAL causes javac to inline the fields, which prevents
            // the mapper from doing field mapping
            opField.setAccessFlags(ACC_PUBLIC | ACC_STATIC);
            // setting a non-final static field value
            // doesn't work with fernflower
            opField.setValue(wp.getOpcode());
            runeliteOpcodes.addField(opField);
            // add initialization
            Method clinit = runeliteOpcodes.findMethod("<clinit>");
            assert clinit != null;
            Instructions instructions = clinit.getCode().getInstructions();
            instructions.addInstruction(0, new LDC(instructions, wp.getOpcode()));
            instructions.addInstruction(1, new PutStatic(instructions, opField));
        }
        ++count;
    }
    logger.info("Injected {} packet writes", count);
}
Also used : ClassFile(net.runelite.asm.ClassFile) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic) Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic)

Example 100 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class UnusedParameters method visit.

private void visit(InstructionContext ictx) {
    Instruction i = ictx.getInstruction();
    if (!(i instanceof InvokeInstruction)) {
        return;
    }
    invokes.put(i, ictx);
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Aggregations

Instruction (net.runelite.asm.attributes.code.Instruction)109 Instructions (net.runelite.asm.attributes.code.Instructions)69 Code (net.runelite.asm.attributes.Code)48 LDC (net.runelite.asm.attributes.code.instructions.LDC)39 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)32 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)32 ClassGroup (net.runelite.asm.ClassGroup)31 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)29 IMul (net.runelite.asm.attributes.code.instructions.IMul)28 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)28 Test (org.junit.Test)27 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)25 Method (net.runelite.asm.Method)24 IStore (net.runelite.asm.attributes.code.instructions.IStore)24 Execution (net.runelite.asm.execution.Execution)23 Deobfuscator (net.runelite.deob.Deobfuscator)22 Label (net.runelite.asm.attributes.code.Label)19 ArrayList (java.util.ArrayList)17 InstructionContext (net.runelite.asm.execution.InstructionContext)17 Field (net.runelite.asm.Field)16