Search in sources :

Example 11 with Frame

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

the class HandlerFinder method prepareFrame.

private void prepareFrame(Execution e, Method method, List<PacketHandler> handlers) {
    e.step = true;
    Frame f = new Frame(e, method);
    f.initialize();
    e.addFrame(f);
    while (e.frames.isEmpty() == false) {
        f = e.frames.get(0);
        if (!f.isExecuting()) {
            e.frames.remove(0);
            continue;
        }
        assert f.isExecuting();
        f.execute();
        e.paused = false;
        InstructionContext ctx = f.getInstructions().get(f.getInstructions().size() - 1);
        for (PacketHandler handler : handlers) {
            if (handler.getAfterRead() == ctx.getInstruction()) {
                // frame is stopped at jump prior to handler
                handler.frame = f.dup();
                e.frames.remove(handler.frame);
                logger.info("Found frame for {}: {}", handler, handler.frame);
            }
            if (handler.getJump() == ctx.getInstruction()) {
                handler.jumpFrame = f.dup();
                e.frames.remove(handler.jumpFrame);
                assert handler.jumpFrame.isExecuting();
                logger.info("Found jump frame for {}: {}", handler, handler.jumpFrame);
            }
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame)

Example 12 with Frame

use of net.runelite.asm.execution.Frame 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 13 with Frame

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

the class LCmpTest method testIsSame.

@Test
public void testIsSame() {
    LCmp cmp = new LCmp(mock(Instructions.class), InstructionType.LCMP);
    LCmp cmp2 = new LCmp(mock(Instructions.class), InstructionType.LCMP);
    Frame f1 = mock(Frame.class);
    when(f1.getStack()).thenReturn(new Stack(42));
    when(f1.getVariables()).thenReturn(new Variables(42));
    Frame f2 = mock(Frame.class);
    when(f2.getStack()).thenReturn(new Stack(42));
    when(f2.getVariables()).thenReturn(new Variables(42));
    InstructionContext ctx1 = new InstructionContext(cmp, f1);
    InstructionContext ctx2 = new InstructionContext(cmp2, f2);
    boolean result = cmp.isSame(ctx1, ctx2);
    Assert.assertTrue(result);
}
Also used : Variables(net.runelite.asm.execution.Variables) InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) Instructions(net.runelite.asm.attributes.code.Instructions) Stack(net.runelite.asm.execution.Stack) Test(org.junit.Test)

Example 14 with Frame

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

the class InvokeStatic 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);
    }
    if (!method.getType().isVoid()) {
        StackContext ctx = new StackContext(ins, method.getType().getReturnValue(), Value.UNKNOWN);
        stack.push(ctx);
        ins.push(ctx);
    }
    if (myMethod != null) {
        ins.invoke(myMethod);
        assert myMethod.getCode() != null;
        Execution execution = frame.getExecution();
        if (execution.staticStep) {
            Frame staticFrame = stepInto(frame, ins);
            if (staticFrame != null) {
                // this invokestatic instruction hasn't been added to this frame yet.. so it
                // is not yet in the return frame
                staticFrame.returnTo.addInstructionContext(ins);
                staticFrame.returnTo.nextInstruction();
                // returnTo has already be duped from frame which is why executing remains
                // true and it is able to resume later
                frame.stop();
            }
        } else {
            // add possible method call to execution
            execution.invoke(ins, myMethod);
        }
        frame.getExecution().order(frame, myMethod);
    }
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) Execution(net.runelite.asm.execution.Execution) StackContext(net.runelite.asm.execution.StackContext) Stack(net.runelite.asm.execution.Stack)

Example 15 with Frame

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

the class If0 method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    StackContext one = stack.pop();
    ins.pop(one);
    Frame other = frame.dup();
    other.jump(ins, to);
    ins.branch(other);
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) StackContext(net.runelite.asm.execution.StackContext) Stack(net.runelite.asm.execution.Stack)

Aggregations

Frame (net.runelite.asm.execution.Frame)17 InstructionContext (net.runelite.asm.execution.InstructionContext)12 Stack (net.runelite.asm.execution.Stack)8 StackContext (net.runelite.asm.execution.StackContext)7 Instructions (net.runelite.asm.attributes.code.Instructions)5 Label (net.runelite.asm.attributes.code.Label)4 Execution (net.runelite.asm.execution.Execution)4 ClassGroup (net.runelite.asm.ClassGroup)3 Instruction (net.runelite.asm.attributes.code.Instruction)3 Variables (net.runelite.asm.execution.Variables)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClassFile (net.runelite.asm.ClassFile)2 Method (net.runelite.asm.Method)2 InstructionType (net.runelite.asm.attributes.code.InstructionType)2 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)2 MappableInstruction (net.runelite.asm.attributes.code.instruction.types.MappableInstruction)2