Search in sources :

Example 11 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class InvokeVirtual method isSame.

@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) {
    if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass()) {
        return false;
    }
    InvokeVirtual thisIi = (InvokeVirtual) thisIc.getInstruction(), otherIi = (InvokeVirtual) otherIc.getInstruction();
    if (!MappingExecutorUtil.isMaybeEqual(thisIi.method.getType(), otherIi.method.getType())) {
        return false;
    }
    List<net.runelite.asm.Method> thisMethods = thisIi.getMethods(), otherMethods = otherIi.getMethods();
    if (thisMethods.size() != otherMethods.size()) {
        return false;
    }
    for (int i = 0; i < thisMethods.size(); ++i) {
        net.runelite.asm.Method m1 = thisMethods.get(i);
        net.runelite.asm.Method m2 = otherMethods.get(i);
        // were loaded, which might not be the same
        if (!MappingExecutorUtil.isMaybeEqual(m1.getDescriptor(), m2.getDescriptor())) {
            return false;
        }
        // descriptors for all methods must be the same
        break;
    }
    /* check arguments */
    assert thisIc.getPops().size() == otherIc.getPops().size();
    for (int i = 0; i < thisIc.getPops().size(); ++i) {
        StackContext s1 = thisIc.getPops().get(i), s2 = otherIc.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 (!MappingExecutorUtil.isMaybeEqual(f1, f2)) {
                return false;
            }
        }
    }
    /* check field that was invoked on */
    StackContext object1 = thisIc.getPops().get(thisIi.method.getType().size()), object2 = otherIc.getPops().get(otherIi.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 (!MappingExecutorUtil.isMaybeEqual(f1, f2)) {
            return false;
        }
    }
    return true;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext) Method(net.runelite.asm.pool.Method) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 12 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class If method isSameField.

protected boolean isSameField(InstructionContext thisIc, InstructionContext otherIc) {
    List<Field> f1s = getComparedFields(thisIc), f2s = getComparedFields(otherIc);
    if ((f1s != null) != (f2s != null)) {
        return false;
    }
    if (f1s == null || f2s == null) {
        return true;
    }
    if (f1s.size() != f2s.size()) {
        return false;
    }
    assert f1s.size() == 1 || f1s.size() == 2;
    if (f1s.size() == 2) {
        Field f1 = f1s.get(0), f2 = f2s.get(0);
        Field j1 = f1s.get(1), j2 = f2s.get(1);
        if (!f1.isStatic() && !j1.isStatic() && !f2.isStatic() && !j2.isStatic()) {
            if ((f1.getClassFile() == j1.getClassFile()) != (f2.getClassFile() == j2.getClassFile())) {
                return false;
            }
        }
        if (couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2)) {
            return true;
        }
        if (couldBeSame(f1, f2) && couldBeSame(j1, j2)) {
            return true;
        }
        if (couldBeSame(f1, j2) && couldBeSame(j1, f2)) {
            return true;
        }
        return false;
    } else {
        Field f1 = f1s.get(0), f2 = f2s.get(0);
        return couldBeSame(f1, f2);
    }
}
Also used : Field(net.runelite.asm.Field)

Example 13 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class If method mapArguments.

private void mapArguments(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other, boolean inverse) {
    List<Field> f1s = getComparedFields(ctx), f2s = getComparedFields(other);
    if (f1s == null || f2s == null || f1s.size() != f2s.size()) {
        return;
    }
    if (f1s.size() == 1) {
        Field f1 = f1s.get(0), f2 = f2s.get(0);
        assert MappingExecutorUtil.isMaybeEqual(f1.getType(), f2.getType());
        mapping.map(this, f1, f2);
    } else if (f1s.size() == 2) {
        Field f1 = f1s.get(0), f2 = f2s.get(0);
        Field j1 = f1s.get(1), j2 = f2s.get(1);
        // }
        if (couldBeSame(f1, f2) && couldBeSame(j1, j2)) {
            mapping.map(this, f1, f2);
            mapping.map(this, j1, j2);
        }
        if (couldBeSame(f1, j2) && couldBeSame(j1, f2)) {
            mapping.map(this, f1, j2);
            mapping.map(this, j1, f2);
        }
    } else {
        assert false;
    }
}
Also used : Field(net.runelite.asm.Field)

Example 14 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class InvokeStatic method map.

@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
    List<net.runelite.asm.Method> myMethods = this.getMethods(), otherMethods = ((InvokeStatic) other.getInstruction()).getMethods();
    assert myMethods.size() == otherMethods.size();
    for (int i = 0; i < myMethods.size(); ++i) {
        mapping.map(this, myMethods.get(i), otherMethods.get(i));
    }
    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);
            }
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext) Method(net.runelite.asm.pool.Method) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 15 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class UpdateMappingsTest method check.

private void check(ClassGroup group1, ClassGroup group2) {
    for (ClassFile cf : group1.getClasses()) {
        ClassFile other = group2.findClass(cf.getName());
        String implname = DeobAnnotations.getImplements(cf);
        String otherimplname = DeobAnnotations.getImplements(other);
        Assert.assertEquals(implname, otherimplname);
        for (Field f : cf.getFields()) {
            Field otherf = other.findField(f.getName(), f.getType());
            assert otherf != null : "unable to find " + f;
            String name = DeobAnnotations.getExportedName(f.getAnnotations());
            String otherName = DeobAnnotations.getExportedName(otherf.getAnnotations());
            Assert.assertEquals(name + " <-> " + otherName, name, otherName);
        }
        for (Method m : cf.getMethods()) {
            Method otherm = other.findMethod(m.getName(), m.getDescriptor());
            assert otherm != null : "unable to find " + m;
            String name = DeobAnnotations.getExportedName(m.getAnnotations());
            String otherName = DeobAnnotations.getExportedName(otherm.getAnnotations());
            Assert.assertEquals(name + " <-> " + otherName, name, otherName);
        }
    }
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Aggregations

Field (net.runelite.asm.Field)65 ClassFile (net.runelite.asm.ClassFile)39 Method (net.runelite.asm.Method)33 Instruction (net.runelite.asm.attributes.code.Instruction)19 InstructionContext (net.runelite.asm.execution.InstructionContext)19 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)17 Instructions (net.runelite.asm.attributes.code.Instructions)16 StackContext (net.runelite.asm.execution.StackContext)16 Type (net.runelite.asm.Type)15 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)11 Code (net.runelite.asm.attributes.Code)10 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)10 Signature (net.runelite.asm.signature.Signature)9 ClassGroup (net.runelite.asm.ClassGroup)8 FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)8 PutField (net.runelite.asm.attributes.code.instructions.PutField)8 Test (org.junit.Test)8 List (java.util.List)7 Annotation (net.runelite.asm.attributes.annotation.Annotation)7