Search in sources :

Example 11 with GetFieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction in project runelite by runelite.

the class PutField method mapGetFieldInstructrions.

private void mapGetFieldInstructrions(ParallelExecutorMapping mapping, InstructionContext base1, InstructionContext base2) {
    if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
        net.runelite.asm.Field f1 = gf1.getMyField();
        net.runelite.asm.Field f2 = gf2.getMyField();
        if (f1 != null && f2 != null) {
            mapping.map(this, f1, f2);
        }
    }
}
Also used : GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 12 with GetFieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction 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 13 with GetFieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction in project runelite by runelite.

the class ModArith method findUses.

// find potential getters/setters for each field
private void findUses(MethodContext mctx) {
    for (InstructionContext ctx : mctx.getInstructionContexts()) {
        if (ctx.getInstruction() instanceof IMul || ctx.getInstruction() instanceof LMul) {
            Instruction one = ctx.getPops().get(0).getPushed().getInstruction();
            Instruction two = ctx.getPops().get(1).getPushed().getInstruction();
            PushConstantInstruction pc = null;
            GetFieldInstruction gf = null;
            if (one instanceof PushConstantInstruction && two instanceof GetFieldInstruction) {
                pc = (PushConstantInstruction) one;
                gf = (GetFieldInstruction) two;
            } else if (two instanceof PushConstantInstruction && one instanceof GetFieldInstruction) {
                pc = (PushConstantInstruction) two;
                gf = (GetFieldInstruction) one;
            }
            if (pc == null) {
                continue;
            }
            Field field = gf.getMyField();
            if (field == null) {
                continue;
            }
            FieldInfo fieldInfo = getFieldInfo(field);
            // parse the full multiplication expression to
            // get all associated constants
            List<InstructionContext> insInExpr = getInsInExpr(ctx, new HashSet(), true);
            for (InstructionContext ctx2 : insInExpr) {
                if (!(ctx2.getInstruction() instanceof PushConstantInstruction)) {
                    continue;
                }
                PushConstantInstruction pci3 = (PushConstantInstruction) ctx2.getInstruction();
                Number value = (Number) pci3.getConstant();
                // field * constant
                if (value instanceof Integer || value instanceof Long) {
                    fieldInfo.getters.add(value);
                }
            }
        } else if (ctx.getInstruction() instanceof SetFieldInstruction) {
            SetFieldInstruction sf = (SetFieldInstruction) ctx.getInstruction();
            Field field = sf.getMyField();
            if (field == null) {
                continue;
            }
            FieldInfo fieldInfo = getFieldInfo(field);
            // value being set
            InstructionContext pushedsfi = ctx.getPops().get(0).getPushed();
            pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
            if (!(pushedsfi.getInstruction() instanceof IMul) && !(pushedsfi.getInstruction() instanceof LMul) && !(pushedsfi.getInstruction() instanceof IAdd) && !(pushedsfi.getInstruction() instanceof LAdd) && !(pushedsfi.getInstruction() instanceof ISub) && !(pushedsfi.getInstruction() instanceof LSub)) {
                if (pushedsfi.getInstruction() instanceof LDC) {
                    PushConstantInstruction ldc = (PushConstantInstruction) pushedsfi.getInstruction();
                    if (ldc.getConstant() instanceof Integer || ldc.getConstant() instanceof Long) {
                        Number i = (Number) ldc.getConstant();
                        // field = constant
                        fieldInfo.setters.add(i);
                    }
                }
                continue;
            }
            Instruction one = pushedsfi.getPops().get(0).getPushed().getInstruction();
            Instruction two = pushedsfi.getPops().get(1).getPushed().getInstruction();
            // field = field + imul
            if (pushedsfi.getInstruction() instanceof IAdd) {
                if (one instanceof IMul && two instanceof GetFieldInstruction) {
                    one = pushedsfi.getPops().get(0).getPushed().getPops().get(0).getPushed().getInstruction();
                    two = pushedsfi.getPops().get(0).getPushed().getPops().get(1).getPushed().getInstruction();
                }
            }
            // if both one and two are constants then one of them must not be a setter
            PushConstantInstruction pc = null;
            if (one instanceof PushConstantInstruction && !(two instanceof PushConstantInstruction)) {
                pc = (PushConstantInstruction) one;
            } else if (two instanceof PushConstantInstruction && !(one instanceof PushConstantInstruction)) {
                pc = (PushConstantInstruction) two;
            }
            if (pc == null) {
                continue;
            }
            Number value2 = (Number) pc.getConstant();
            // field = something * constant
            if (value2 instanceof Integer || value2 instanceof Long) {
                fieldInfo.setters.add(value2);
            }
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) LDC(net.runelite.asm.attributes.code.instructions.LDC) DivisionInstruction(net.runelite.asm.attributes.code.instruction.types.DivisionInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) ArrayStoreInstruction(net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Field(net.runelite.asm.Field) ISub(net.runelite.asm.attributes.code.instructions.ISub) LAdd(net.runelite.asm.attributes.code.instructions.LAdd) LSub(net.runelite.asm.attributes.code.instructions.LSub) IMul(net.runelite.asm.attributes.code.instructions.IMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) LMul(net.runelite.asm.attributes.code.instructions.LMul) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) HashSet(java.util.HashSet)

Example 14 with GetFieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction in project runelite by runelite.

the class ArrayStore method getMyField.

public Field getMyField(InstructionContext thisIc) {
    StackContext sctx = thisIc.getPops().get(2);
    InstructionContext pushed = sctx.getPushed();
    InstructionContext r = pushed.resolve(sctx);
    if (r.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction gf = (GetFieldInstruction) r.getInstruction();
        Field f = gf.getMyField();
        return f;
    }
    return null;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 15 with GetFieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction in project runelite by runelite.

the class ArrayStore method isSame.

@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) {
    if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass()) {
        return false;
    }
    Field myField = this.getMyField(thisIc), otherField = ((ArrayStore) otherIc.getInstruction()).getMyField(otherIc);
    if (!MappingExecutorUtil.isMaybeEqual(myField, otherField)) {
        return false;
    }
    StackContext // value set to.
    object1 = thisIc.getPops().get(0), object2 = otherIc.getPops().get(0);
    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 (!MappingExecutorUtil.isMaybeEqual(f1, f2)) {
            return false;
        }
    }
    return true;
}
Also used : Field(net.runelite.asm.Field) InstructionContext(net.runelite.asm.execution.InstructionContext) StackContext(net.runelite.asm.execution.StackContext) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Aggregations

GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)17 Field (net.runelite.asm.Field)13 InstructionContext (net.runelite.asm.execution.InstructionContext)13 StackContext (net.runelite.asm.execution.StackContext)11 ClassFile (net.runelite.asm.ClassFile)5 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)5 LDC (net.runelite.asm.attributes.code.instructions.LDC)5 Method (net.runelite.asm.pool.Method)5 Instruction (net.runelite.asm.attributes.code.Instruction)4 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)4 Method (net.runelite.asm.Method)3 Instructions (net.runelite.asm.attributes.code.Instructions)3 FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)3 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClassGroup (net.runelite.asm.ClassGroup)2 Type (net.runelite.asm.Type)2 Code (net.runelite.asm.attributes.Code)2