Search in sources :

Example 36 with Value

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

the class IfEqTest method testIsSame.

@Test
public void testIsSame() {
    Instructions ins = mock(Instructions.class);
    Frame originalIfEqFrame = mock(Frame.class);
    Stack stack = new Stack(42);
    Variables variables = new Variables(42);
    when(originalIfEqFrame.getStack()).thenReturn(stack);
    when(originalIfEqFrame.getVariables()).thenReturn(variables);
    variables.set(9, new VariableContext(INT));
    Instruction i = new LDC(ins, 0);
    InstructionContext ctx = new InstructionContext(i, originalIfEqFrame);
    // ifeq 0
    IfEq ifeq = new IfEq(ins, InstructionType.IFEQ);
    InstructionContext ifeqCtx = new InstructionContext(ifeq, originalIfEqFrame);
    ifeqCtx.pop(new StackContext(ctx, INT, new Value(1)));
    // 
    ins = mock(Instructions.class);
    Frame originalIfIcmpNeFrame = mock(Frame.class);
    stack = new Stack(42);
    variables = new Variables(42);
    when(originalIfIcmpNeFrame.getStack()).thenReturn(stack);
    when(originalIfIcmpNeFrame.getVariables()).thenReturn(variables);
    variables.set(5, new VariableContext(INT));
    i = new LDC(ins, 1);
    InstructionContext ctx1 = new InstructionContext(i, originalIfIcmpNeFrame);
    i = new ILoad(ins, 5);
    InstructionContext ctx2 = new InstructionContext(i, originalIfIcmpNeFrame);
    // ificmpne 1
    IfICmpNe ificmpne = new IfICmpNe(ins, InstructionType.IF_ICMPNE);
    InstructionContext ificmpneCtx = new InstructionContext(ificmpne, originalIfIcmpNeFrame);
    ificmpneCtx.pop(new StackContext(ctx1, INT, new Value(1)), new StackContext(ctx2, INT, Value.UNKNOWN));
    assertEquals(ifeq.isSame(ifeqCtx, ificmpneCtx), ificmpne.isSame(ificmpneCtx, ifeqCtx));
    // check that both frames jump the same direction
    Frame ifeqBranchFrame = mock(Frame.class);
    ifeqCtx.branch(ifeqBranchFrame);
    Frame ificmpneBranchFrame = mock(Frame.class);
    ificmpneCtx.branch(ificmpneBranchFrame);
    // initially originalIfEqFrame.other == originalIfIcmpNeFrame.other
    when(originalIfEqFrame.getOther()).thenReturn(originalIfIcmpNeFrame);
    when(originalIfIcmpNeFrame.getOther()).thenReturn(originalIfEqFrame);
    ParallelExecutorMapping mapping = mock(ParallelExecutorMapping.class);
    ifeq.map(mapping, ifeqCtx, ificmpneCtx);
    // verify that ifeqBranchFrame.other = ificmpneBranchFrame
    ArgumentCaptor<Frame> frameCapture = ArgumentCaptor.forClass(Frame.class);
    verify(ifeqBranchFrame).setOther(frameCapture.capture());
    assertEquals(ificmpneBranchFrame, frameCapture.getValue());
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) Instructions(net.runelite.asm.attributes.code.Instructions) VariableContext(net.runelite.asm.execution.VariableContext) Instruction(net.runelite.asm.attributes.code.Instruction) ParallelExecutorMapping(net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping) Stack(net.runelite.asm.execution.Stack) Variables(net.runelite.asm.execution.Variables) StackContext(net.runelite.asm.execution.StackContext) Value(net.runelite.asm.execution.Value) Test(org.junit.Test)

Example 37 with Value

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

the class IDiv 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()) {
        int i2 = (int) two.getValue().getValue(), i1 = (int) one.getValue().getValue();
        if (i2 != 0)
            result = new Value(i1 / i2);
    }
    StackContext ctx = new StackContext(ins, Type.INT, 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)

Example 38 with Value

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

the class INeg method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    StackContext value = stack.pop();
    ins.pop(value);
    Value result = Value.UNKNOWN;
    if (!value.getValue().isUnknownOrNull()) {
        int i = (int) value.getValue().getValue();
        result = new Value(-i);
    }
    StackContext ctx = new StackContext(ins, Type.INT, 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)

Example 39 with Value

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

the class ISub 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()) {
        int i2 = (int) two.getValue().getValue(), i1 = (int) one.getValue().getValue();
        result = new Value(i1 - i2);
    }
    StackContext ctx = new StackContext(ins, Type.INT, 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)

Example 40 with Value

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

the class IXor 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()) {
        int i2 = (int) two.getValue().getValue(), i1 = (int) one.getValue().getValue();
        result = new Value(i1 ^ i2);
    }
    StackContext ctx = new StackContext(ins, Type.INT, 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

InstructionContext (net.runelite.asm.execution.InstructionContext)48 Value (net.runelite.asm.execution.Value)48 Stack (net.runelite.asm.execution.Stack)47 StackContext (net.runelite.asm.execution.StackContext)47 Variables (net.runelite.asm.execution.Variables)3 Instructions (net.runelite.asm.attributes.code.Instructions)2 Frame (net.runelite.asm.execution.Frame)2 VariableContext (net.runelite.asm.execution.VariableContext)2 Test (org.junit.Test)2 Instruction (net.runelite.asm.attributes.code.Instruction)1 ParallelExecutorMapping (net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping)1