Search in sources :

Example 6 with FieldInstruction

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

the class ModArith method findConstants.

// find associated constants with each field
private void findConstants(MethodContext mctx) {
    for (InstructionContext ctx : mctx.getInstructionContexts()) {
        if (ctx.getInstruction() instanceof FieldInstruction) {
            FieldInstruction fi = (FieldInstruction) ctx.getInstruction();
            if (fi.getMyField() == null) {
                continue;
            }
            if ((!fi.getField().getType().equals(Type.INT) && !fi.getField().getType().equals(Type.LONG)) || fi.getField().getType().isArray()) {
                continue;
            }
            FieldInfo fieldInfo = getFieldInfo(fi.getMyField());
            List<InstructionContext> l = getInsInExpr(ctx, new HashSet(), false);
            // check if this contains another field
            boolean other = false;
            boolean getter = false, setter = false;
            for (InstructionContext i : l) {
                if (i.getInstruction() instanceof FieldInstruction) {
                    FieldInstruction fi2 = (FieldInstruction) i.getInstruction();
                    Field myField = fi2.getMyField();
                    if (myField != null && myField != fi.getMyField()) {
                        Type t = myField.getType();
                        if (t.equals(fi.getMyField().getType())) {
                            other = true;
                        }
                    } else if (myField != null && myField == fi.getMyField()) {
                        if (fi2 instanceof SetFieldInstruction) {
                            setter = true;
                        } else {
                            getter = true;
                        }
                    }
                }
            }
            // check if this is a constant assignment
            boolean constant = false;
            if (fi instanceof SetFieldInstruction) {
                // value being set
                InstructionContext pushedsfi = ctx.getPops().get(0).getPushed();
                pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
                if (pushedsfi.getInstruction() instanceof LDC) {
                    constant = true;
                }
            }
            for (InstructionContext i : l) {
                if (i.getInstruction() instanceof LDC) {
                    PushConstantInstruction w = (PushConstantInstruction) i.getInstruction();
                    if (w.getConstant() instanceof Integer || w.getConstant() instanceof Long) {
                        AssociatedConstant n = new AssociatedConstant();
                        n.value = (Number) w.getConstant();
                        n.other = other;
                        n.constant = constant;
                        n.getter = getter;
                        n.setter = setter;
                        fieldInfo.constants.add(n);
                    }
                }
            }
        }
    }
}
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) Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) HashSet(java.util.HashSet)

Example 7 with FieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction 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)

Aggregations

FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)7 Method (net.runelite.asm.Method)5 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)5 Field (net.runelite.asm.Field)4 Type (net.runelite.asm.Type)4 Code (net.runelite.asm.attributes.Code)4 Instruction (net.runelite.asm.attributes.code.Instruction)4 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)4 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)4 ClassFile (net.runelite.asm.ClassFile)3 LDC (net.runelite.asm.attributes.code.instructions.LDC)3 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClassGroup (net.runelite.asm.ClassGroup)2 Instructions (net.runelite.asm.attributes.code.Instructions)2 Deobfuscator (net.runelite.deob.Deobfuscator)2 Logger (org.slf4j.Logger)2