Search in sources :

Example 1 with Instruction

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

the class Method method findLVTInstructionsForVariable.

@SuppressWarnings("unchecked")
public <T extends Instruction & LVTInstruction> List<T> findLVTInstructionsForVariable(int index) {
    List<T> list = new ArrayList<>();
    if (getCode() == null) {
        return null;
    }
    for (Instruction ins : getCode().getInstructions().getInstructions()) {
        if (ins instanceof LVTInstruction) {
            LVTInstruction lv = (LVTInstruction) ins;
            if (lv.getVariableIndex() != index) {
                continue;
            }
            list.add((T) ins);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction)

Example 2 with Instruction

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

the class Method method accept.

public void accept(MethodVisitor visitor) {
    for (Annotation annotation : annotations.getAnnotations()) {
        AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true);
        annotation.accept(av);
    }
    if (code != null) {
        code.getInstructions().rebuildLabels();
        visitor.visitCode();
        net.runelite.asm.attributes.code.Exceptions exceptions = code.getExceptions();
        for (net.runelite.asm.attributes.code.Exception exception : exceptions.getExceptions()) {
            assert exception.getStart().getLabel() != null;
            assert exception.getEnd().getLabel() != null;
            assert exception.getHandler().getLabel() != null;
            int idxStart = code.getInstructions().getInstructions().indexOf(exception.getStart());
            int idxEnd = code.getInstructions().getInstructions().indexOf(exception.getEnd());
            assert idxStart != -1;
            assert idxEnd != -1;
            assert code.getInstructions().getInstructions().contains(exception.getHandler());
            assert idxEnd > idxStart;
            visitor.visitTryCatchBlock(exception.getStart().getLabel(), exception.getEnd().getLabel(), exception.getHandler().getLabel(), exception.getCatchType() != null ? exception.getCatchType().getName() : null);
        }
        for (Instruction i : code.getInstructions().getInstructions()) {
            i.accept(visitor);
        }
        visitor.visitMaxs(code.getMaxStack(), code.getMaxLocals());
    }
    visitor.visitEnd();
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 3 with Instruction

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

the class Code method getMaxLocals.

/**
 * calculates the size of the lvt required for this method
 * @return
 */
public int getMaxLocals() {
    int max = -1;
    for (Instruction ins : instructions.getInstructions()) {
        if (ins instanceof LVTInstruction) {
            LVTInstruction lvt = (LVTInstruction) ins;
            int sizeRequired = lvt.getVariableIndex() + lvt.type().getSlots();
            if (sizeRequired > max) {
                max = sizeRequired;
            }
        }
    }
    int fromSig = getMaxLocalsFromSig();
    if (fromSig > max)
        max = fromSig;
    return max;
}
Also used : Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction)

Example 4 with Instruction

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

the class PacketWriteDeobfuscator method insert.

private void insert(Instructions ins, InstructionContext ic, Instruction before) {
    List<StackContext> pops = new ArrayList<>(ic.getPops());
    Collections.reverse(pops);
    for (StackContext sc : pops) {
        insert(ins, sc.getPushed(), before);
    }
    Instruction i = ic.getInstruction().clone();
    i = translate(i);
    assert i.getInstructions() == ins;
    int idx = ins.getInstructions().indexOf(before);
    assert idx != -1;
    ins.addInstruction(idx, i);
}
Also used : StackContext(net.runelite.asm.execution.StackContext) ArrayList(java.util.ArrayList) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 5 with Instruction

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

the class GetPathTransformer method transform.

private void transform(Method m) {
    int count = 0;
    if (m.getCode() == null) {
        return;
    }
    for (Instruction i : m.getCode().getInstructions().getInstructions()) {
        if (i instanceof InvokeInstruction) {
            InvokeInstruction ii = (InvokeInstruction) i;
            if (ii.getMethod().getName().equals("getPath")) {
                if (++count == 2) {
                    removeInvoke(i);
                    done = true;
                    break;
                }
            }
        }
    }
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) 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