Search in sources :

Example 96 with StackContext

use of net.runelite.asm.execution.StackContext in project runelite by runelite.

the class InvokeVirtual method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    int count = method.getType().size();
    for (int i = 0; i < count; ++i) {
        StackContext arg = stack.pop();
        ins.pop(arg);
    }
    StackContext object = stack.pop();
    ins.pop(object);
    if (!method.getType().isVoid()) {
        StackContext ctx = new StackContext(ins, method.getType().getReturnValue(), Value.UNKNOWN);
        stack.push(ctx);
        ins.push(ctx);
    }
    for (net.runelite.asm.Method method : getMethods()) {
        ins.invoke(method);
        if (method.getCode() == null) {
            continue;
        }
        // add possible method call to execution
        Execution execution = frame.getExecution();
        execution.invoke(ins, method);
    }
    if (myMethods != null) {
        for (net.runelite.asm.Method method : myMethods) {
            frame.getExecution().order(frame, method);
        }
    }
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) StackContext(net.runelite.asm.execution.StackContext) Stack(net.runelite.asm.execution.Stack)

Example 97 with StackContext

use of net.runelite.asm.execution.StackContext in project runelite by runelite.

the class InvokeVirtual method map.

@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
    InvokeVirtual otherIv = (InvokeVirtual) other.getInstruction();
    List<net.runelite.asm.Method> myMethods = this.getMethods(), otherMethods = otherIv.getMethods();
    assert MappingExecutorUtil.isMaybeEqual(method.getType(), otherIv.method.getType());
    assert myMethods.size() == otherMethods.size();
    for (int i = 0; i < myMethods.size(); ++i) {
        net.runelite.asm.Method m1 = myMethods.get(i), otherMethod = null;
        ClassFile c1 = m1.getClassFile();
        if (myMethods.size() == 1) {
            otherMethod = otherMethods.get(0);
        } else {
            for (int j = 0; j < myMethods.size(); ++j) {
                net.runelite.asm.Method m2 = otherMethods.get(j);
                ClassFile c2 = m2.getClassFile();
                if (MappingExecutorUtil.isMaybeEqual(c1, c2)) {
                    if (otherMethod != null) {
                        otherMethod = null;
                        break;
                    }
                    otherMethod = m2;
                }
            }
        }
        if (otherMethod != null) {
            mapping.map(this, m1, otherMethod);
        }
    }
    /* map arguments */
    assert ctx.getPops().size() == other.getPops().size();
    for (int i = 0; i < ctx.getPops().size(); ++i) {
        StackContext s1 = ctx.getPops().get(i), s2 = other.getPops().get(i);
        InstructionContext base1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
        InstructionContext base2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
        if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
            GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
            Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
            if (f1 != null && f2 != null) {
                mapping.map(this, f1, f2);
            }
        }
    }
    /* map field that was invoked on */
    StackContext object1 = ctx.getPops().get(method.getType().size()), object2 = other.getPops().get(otherIv.method.getType().size());
    InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1);
    InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2);
    if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
        Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
        if (f1 != null && f2 != null) {
            mapping.map(this, f1, f2);
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.pool.Method) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 98 with StackContext

use of net.runelite.asm.execution.StackContext in project runelite by runelite.

the class L2F method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    StackContext object = stack.pop();
    ins.pop(object);
    StackContext ctx = new StackContext(ins, Type.FLOAT, object.getValue().cast(float.class));
    stack.push(ctx);
    ins.push(ctx);
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) StackContext(net.runelite.asm.execution.StackContext) Stack(net.runelite.asm.execution.Stack)

Example 99 with StackContext

use of net.runelite.asm.execution.StackContext in project runelite by runelite.

the class LAStore method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    StackContext value = stack.pop();
    StackContext index = stack.pop();
    StackContext array = stack.pop();
    ins.pop(value, index, array);
    array.getValue().arraySet(index.getValue(), value.getValue());
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) StackContext(net.runelite.asm.execution.StackContext) Stack(net.runelite.asm.execution.Stack)

Example 100 with StackContext

use of net.runelite.asm.execution.StackContext in project runelite by runelite.

the class LAnd method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    StackContext two = stack.pop();
    StackContext one = stack.pop();
    ins.pop(two, one);
    Value result = Value.UNKNOWN;
    if (!two.getValue().isUnknownOrNull() && !one.getValue().isUnknownOrNull()) {
        long l2 = (long) two.getValue().getValue(), l1 = (long) one.getValue().getValue();
        result = new Value(l1 & l2);
    }
    StackContext ctx = new StackContext(ins, Type.LONG, result);
    stack.push(ctx);
    ins.push(ctx);
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) StackContext(net.runelite.asm.execution.StackContext) Value(net.runelite.asm.execution.Value) Stack(net.runelite.asm.execution.Stack)

Aggregations

StackContext (net.runelite.asm.execution.StackContext)162 InstructionContext (net.runelite.asm.execution.InstructionContext)153 Stack (net.runelite.asm.execution.Stack)119 Value (net.runelite.asm.execution.Value)47 Field (net.runelite.asm.Field)15 Variables (net.runelite.asm.execution.Variables)14 VariableContext (net.runelite.asm.execution.VariableContext)13 Instruction (net.runelite.asm.attributes.code.Instruction)12 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)12 Instructions (net.runelite.asm.attributes.code.Instructions)8 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)8 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)7 Execution (net.runelite.asm.execution.Execution)7 Frame (net.runelite.asm.execution.Frame)7 DupInstruction (net.runelite.asm.attributes.code.instruction.types.DupInstruction)6 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)6 Method (net.runelite.asm.pool.Method)5 ClassFile (net.runelite.asm.ClassFile)4 Method (net.runelite.asm.Method)4 Type (net.runelite.asm.Type)4