Search in sources :

Example 31 with InstructionContext

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

the class BAStore 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 32 with InstructionContext

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

the class SubtractionInstruction method map.

@Override
default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) {
    StackContext s1 = ctx.getPops().get(0), s2 = ctx.getPops().get(1);
    StackContext o1 = other.getPops().get(0), o2 = other.getPops().get(1);
    InstructionContext i1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
    InstructionContext i2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
    InstructionContext io1 = MappingExecutorUtil.resolve(o1.getPushed(), o1);
    InstructionContext io2 = MappingExecutorUtil.resolve(o2.getPushed(), o2);
    if (i1.getInstruction() instanceof GetFieldInstruction && io1.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction f1 = (GetFieldInstruction) i1.getInstruction();
        GetFieldInstruction f2 = (GetFieldInstruction) io1.getInstruction();
        Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
        assert MappingExecutorUtil.isMaybeEqual(fi1, fi2);
        if (fi1 != null && fi2 != null) {
            mappings.map((Instruction) this, fi1, fi2);
        }
    }
    if (i2.getInstruction() instanceof GetFieldInstruction && io2.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction f1 = (GetFieldInstruction) i2.getInstruction();
        GetFieldInstruction f2 = (GetFieldInstruction) io2.getInstruction();
        Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
        assert MappingExecutorUtil.isMaybeEqual(fi1, fi2);
        if (fi1 != null && fi2 != null) {
            mappings.map((Instruction) this, fi1, fi2);
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext)

Example 33 with InstructionContext

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

the class AConstNull method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    StackContext ctx = new StackContext(ins, Type.OBJECT, Value.NULL);
    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 34 with InstructionContext

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

the class AdditionInstruction method map.

@Override
default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) {
    /* lhs/rhs of addition instructions are randomally swapped, but
		 * we still map if each side is recognizable
		 *
		 * N.B. since the lhs/rhs of nested iadds can be swapped, and
		 * the mapper maps the first that it encounters, this can certainly
		 * attempt to map the wrong instructions even when mapping the correct
		 * method, so be careful.
		 */
    StackContext ctx1 = ctx.getPops().get(0);
    StackContext ctx2 = ctx.getPops().get(1);
    StackContext other1 = other.getPops().get(0);
    StackContext other2 = other.getPops().get(1);
    InstructionContext rc1 = ctx1.getPushed().resolve(ctx1);
    // iaload
    InstructionContext rc2 = ctx2.getPushed().resolve(ctx2);
    InstructionContext ro1 = other1.getPushed().resolve(other1);
    // iaload
    InstructionContext ro2 = other2.getPushed().resolve(other2);
    // There are a couple static final arrays that are only ever read from 1 or 2 places.. and never written
    InstructionContext al1 = findArrayLoad(rc1, rc2);
    InstructionContext al2 = findArrayLoad(ro1, ro2);
    if (al1 == null || al2 == null) {
        return;
    }
    StackContext array1 = al1.getPops().get(1);
    StackContext array2 = al2.getPops().get(1);
    InstructionContext field1 = array1.getPushed().resolve(array1);
    InstructionContext field2 = array2.getPushed().resolve(array2);
    if (!(field1.getInstruction() instanceof GetFieldInstruction) || !(field2.getInstruction() instanceof GetFieldInstruction)) {
        return;
    }
    GetFieldInstruction gf1 = (GetFieldInstruction) field1.getInstruction();
    GetFieldInstruction gf2 = (GetFieldInstruction) field2.getInstruction();
    Field f1 = gf1.getMyField();
    Field f2 = gf2.getMyField();
    if (f1 == null || f2 == null || !MappingExecutorUtil.isMaybeEqual(f1, f2)) {
        return;
    }
    mappings.map((Instruction) this, f1, f2);
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext)

Example 35 with InstructionContext

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

the class MappingExecutorUtil method map.

public static ParallelExecutorMapping map(Method m1, Method m2) {
    ClassGroup group1 = m1.getClassFile().getGroup();
    ClassGroup group2 = m2.getClassFile().getGroup();
    Execution e = new Execution(group1);
    e.step = true;
    Frame frame = new Frame(e, m1);
    frame.initialize();
    e.frames.add(frame);
    Execution e2 = new Execution(group2);
    e2.step = true;
    Frame frame2 = new Frame(e2, m2);
    frame2.initialize();
    e2.frames.add(frame2);
    frame.other = frame2;
    frame2.other = frame;
    ParallellMappingExecutor parallel = new ParallellMappingExecutor(e, e2);
    ParallelExecutorMapping mappings = new ParallelExecutorMapping(m1.getClassFile().getGroup(), m2.getClassFile().getGroup());
    mappings.m1 = m1;
    mappings.m2 = m2;
    parallel.mappings = mappings;
    int same = 0;
    while (parallel.step()) {
        // get what each frame is paused/exited on
        InstructionContext p1 = parallel.getP1(), p2 = parallel.getP2();
        assert p1.getInstruction() instanceof MappableInstruction;
        assert p2.getInstruction() instanceof MappableInstruction;
        MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(), mi2 = (MappableInstruction) p2.getInstruction();
        boolean isSame = mi1.isSame(p1, p2);
        assert isSame == mi2.isSame(p2, p1) : "isSame fail " + p1.getInstruction() + " <> " + p2.getInstruction();
        if (!isSame) {
            mappings.crashed = true;
            p1.getFrame().stop();
            p2.getFrame().stop();
            continue;
        }
        ++same;
        mi1.map(mappings, p1, p2);
    }
    mappings.same = same;
    return mappings;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) MappableInstruction(net.runelite.asm.attributes.code.instruction.types.MappableInstruction) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) ParallellMappingExecutor(net.runelite.asm.execution.ParallellMappingExecutor)

Aggregations

InstructionContext (net.runelite.asm.execution.InstructionContext)179 StackContext (net.runelite.asm.execution.StackContext)153 Stack (net.runelite.asm.execution.Stack)120 Value (net.runelite.asm.execution.Value)48 Field (net.runelite.asm.Field)18 Instruction (net.runelite.asm.attributes.code.Instruction)18 Variables (net.runelite.asm.execution.Variables)16 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)15 VariableContext (net.runelite.asm.execution.VariableContext)14 Instructions (net.runelite.asm.attributes.code.Instructions)12 Frame (net.runelite.asm.execution.Frame)12 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)11 Execution (net.runelite.asm.execution.Execution)11 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)9 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)8 IMul (net.runelite.asm.attributes.code.instructions.IMul)7 ClassFile (net.runelite.asm.ClassFile)6 Method (net.runelite.asm.Method)6 Label (net.runelite.asm.attributes.code.Label)6 DupInstruction (net.runelite.asm.attributes.code.instruction.types.DupInstruction)6