Search in sources :

Example 56 with Field

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

the class SubtractionInstruction method isSame.

@Override
default boolean isSame(InstructionContext thisIc, InstructionContext otherIc) {
    if (this.getClass() != otherIc.getInstruction().getClass()) {
        return false;
    }
    StackContext s1 = thisIc.getPops().get(0), s2 = thisIc.getPops().get(1);
    StackContext o1 = otherIc.getPops().get(0), o2 = otherIc.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();
        if (!MappingExecutorUtil.isMaybeEqual(fi1, fi2)) {
            return false;
        }
    }
    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();
        if (!MappingExecutorUtil.isMaybeEqual(fi1, fi2)) {
            return false;
        }
    }
    return true;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext)

Example 57 with Field

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

the class DivisionInstruction 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();
        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();
        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) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 58 with Field

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

the class MixinInjector method setOwnersToTargetClass.

private void setOwnersToTargetClass(ClassFile mixinCf, ClassFile cf, Method method, Map<net.runelite.asm.pool.Field, Field> shadowFields, Map<net.runelite.asm.pool.Method, CopiedMethod> copiedMethods) throws InjectionException {
    ListIterator<Instruction> iterator = method.getCode().getInstructions().getInstructions().listIterator();
    while (iterator.hasNext()) {
        Instruction i = iterator.next();
        if (i instanceof InvokeInstruction) {
            InvokeInstruction ii = (InvokeInstruction) i;
            CopiedMethod copiedMethod = copiedMethods.get(ii.getMethod());
            if (copiedMethod != null) {
                ii.setMethod(copiedMethod.obMethod.getPoolMethod());
                // Pass through garbage value if the method has one
                if (copiedMethod.hasGarbageValue) {
                    int garbageIndex = copiedMethod.obMethod.isStatic() ? copiedMethod.obMethod.getDescriptor().size() - 1 : copiedMethod.obMethod.getDescriptor().size();
                    iterator.previous();
                    iterator.add(new ILoad(method.getCode().getInstructions(), garbageIndex));
                    iterator.next();
                }
            } else if (ii.getMethod().getClazz().getName().equals(mixinCf.getName())) {
                ii.setMethod(new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(cf.getName()), ii.getMethod().getName(), ii.getMethod().getType()));
            }
        } else if (i instanceof FieldInstruction) {
            FieldInstruction fi = (FieldInstruction) i;
            Field shadowed = shadowFields.get(fi.getField());
            if (shadowed != null) {
                fi.setField(shadowed.getPoolField());
            } else if (fi.getField().getClazz().getName().equals(mixinCf.getName())) {
                fi.setField(new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(cf.getName()), fi.getField().getName(), fi.getField().getType()));
            }
        } else if (i instanceof PushConstantInstruction) {
            PushConstantInstruction pi = (PushConstantInstruction) i;
            if (mixinCf.getPoolClass().equals(pi.getConstant())) {
                pi.setConstant(cf.getPoolClass());
            }
        }
        verify(mixinCf, i);
    }
}
Also used : PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Method(net.runelite.asm.Method) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.Field) PutField(net.runelite.asm.attributes.code.instructions.PutField) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction)

Example 59 with Field

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

the class MixinInjector method findShadowFields.

/**
 * Find fields which are marked @Shadow, and what they shadow
 *
 * @param mixinClasses
 * @throws InjectionException
 */
private void findShadowFields(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
    // Injected static fields take precedence when looking up shadowed fields
    for (Class<?> mixinClass : mixinClasses.keySet()) {
        ClassFile mixinCf;
        try {
            mixinCf = loadClass(mixinClass);
        } catch (IOException ex) {
            throw new InjectionException(ex);
        }
        for (Field field : mixinCf.getFields()) {
            Annotation shadow = field.getAnnotations().find(SHADOW);
            if (shadow != null) {
                if (!field.isStatic()) {
                    throw new InjectionException("Can only shadow static fields");
                }
                // shadow this field
                String shadowName = shadow.getElement().getString();
                Field injectedField = injectedFields.get(shadowName);
                if (injectedField != null) {
                    // Shadow a field injected by a mixin
                    shadowFields.put(field.getPoolField(), injectedField);
                } else {
                    // Shadow a field already in the gamepack
                    Field shadowField = findDeobField(shadowName);
                    if (shadowField == null) {
                        throw new InjectionException("Shadow of nonexistent field " + shadowName);
                    }
                    Field obShadow = inject.toObField(shadowField);
                    assert obShadow != null;
                    shadowFields.put(field.getPoolField(), obShadow);
                }
            }
        }
    }
}
Also used : GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.Field) PutField(net.runelite.asm.attributes.code.instructions.PutField) ClassFile(net.runelite.asm.ClassFile) IOException(java.io.IOException) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 60 with Field

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

the class MixinInjector method injectFields.

/**
 * Finds fields that are marked @Inject and inject them into the target
 *
 * @param mixinClasses
 * @throws InjectionException
 */
private void injectFields(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
    // Inject fields, and put them in injectedFields if they can be used by other mixins
    for (Class<?> mixinClass : mixinClasses.keySet()) {
        ClassFile mixinCf;
        try {
            mixinCf = loadClass(mixinClass);
        } catch (IOException ex) {
            throw new InjectionException(ex);
        }
        List<ClassFile> targetCfs = mixinClasses.get(mixinClass);
        for (ClassFile cf : targetCfs) {
            for (Field field : mixinCf.getFields()) {
                // Always inject $assertionsEnabled if its missing.
                if (ASSERTION_FIELD.equals(field.getName())) {
                    if (cf.findField(ASSERTION_FIELD, Type.BOOLEAN) != null) {
                        continue;
                    }
                } else {
                    Annotation inject = field.getAnnotations().find(INJECT);
                    if (inject == null) {
                        continue;
                    }
                }
                Field copy = new Field(cf, field.getName(), field.getType());
                copy.setAccessFlags(field.getAccessFlags());
                copy.setPublic();
                copy.setValue(field.getValue());
                cf.addField(copy);
                if (injectedFields.containsKey(field.getName())) {
                    throw new InjectionException("Injected field names must be globally unique");
                }
                injectedFields.put(field.getName(), copy);
            }
        }
    }
}
Also used : GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.Field) PutField(net.runelite.asm.attributes.code.instructions.PutField) ClassFile(net.runelite.asm.ClassFile) IOException(java.io.IOException) Annotation(net.runelite.asm.attributes.annotation.Annotation)

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