Search in sources :

Example 41 with Field

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

the class ModArith method guess.

private void guess() {
    for (ClassFile cf : group.getClasses()) {
        for (Field f : cf.getFields()) {
            FieldInfo fieldInfo = getFieldInfo(f);
            // all constants in instructions associated with the field
            Collection<AssociatedConstant> col = fieldInfo.constants;
            if (col.isEmpty()) {
                continue;
            }
            Type type = f.getType();
            assert type.equals(Type.INT) || type.equals(Type.LONG);
            Class typeOfField = type.equals(Type.INT) ? Integer.class : Long.class;
            // filter collect constants of the correct type
            Collection<AssociatedConstant> col2 = col.stream().filter(i -> i.value.getClass() == typeOfField).collect(Collectors.toList());
            // filer out ones that have another field in the expression
            List<Number> noOther = col2.stream().filter(i -> !i.other && !i.constant).map(i -> i.value).distinct().collect(Collectors.toList());
            List<Number> other = col2.stream().filter(i -> i.other || i.constant).map(i -> i.value).collect(Collectors.toList());
            other.addAll(noOther);
            other = ImmutableSet.copyOf(other).asList();
            // guess with constants not associated with other fields
            Pair p = this.guess(f, noOther);
            if (p == null) {
                // fall back to all constants
                p = this.guess(f, other);
            }
            // check that this guess doesn't increase constants
            if (p != null && !fieldInfo.guessDecreasesConstants(p)) {
                continue;
            }
            if (p != null) {
                pairs.add(p);
            }
        }
    }
}
Also used : 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) IMul(net.runelite.asm.attributes.code.instructions.IMul) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Code(net.runelite.asm.attributes.Code) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) StackContext(net.runelite.asm.execution.StackContext) HashSet(java.util.HashSet) ArrayStoreInstruction(net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction) DMath.modInverse(net.runelite.deob.deobfuscators.arithmetic.DMath.modInverse) Method(net.runelite.asm.Method) Map(java.util.Map) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) If(net.runelite.asm.attributes.code.instructions.If) LAdd(net.runelite.asm.attributes.code.instructions.LAdd) ISub(net.runelite.asm.attributes.code.instructions.ISub) ArrayLoad(net.runelite.asm.attributes.code.instruction.types.ArrayLoad) ImmutableSet(com.google.common.collect.ImmutableSet) DeobAnnotations(net.runelite.deob.DeobAnnotations) Logger(org.slf4j.Logger) Collection(java.util.Collection) LCmp(net.runelite.asm.attributes.code.instructions.LCmp) Field(net.runelite.asm.Field) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Set(java.util.Set) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) DMath.multiply(net.runelite.deob.deobfuscators.arithmetic.DMath.multiply) Type(net.runelite.asm.Type) Deobfuscator(net.runelite.deob.Deobfuscator) Collectors(java.util.stream.Collectors) InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) LDC(net.runelite.asm.attributes.code.instructions.LDC) MethodContext(net.runelite.asm.execution.MethodContext) Instructions(net.runelite.asm.attributes.code.Instructions) LMul(net.runelite.asm.attributes.code.instructions.LMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Instruction(net.runelite.asm.attributes.code.Instruction) If0(net.runelite.asm.attributes.code.instructions.If0) LSub(net.runelite.asm.attributes.code.instructions.LSub) IShR(net.runelite.asm.attributes.code.instructions.IShR) Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) ClassFile(net.runelite.asm.ClassFile)

Example 42 with Field

use of net.runelite.asm.Field 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 43 with Field

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

the class AnnotationIntegrityChecker method checkAnnotationCounts.

private void checkAnnotationCounts() {
    for (ClassFile cf : two.getClasses()) {
        for (Field f : cf.getFields()) {
            int num = this.getNumberOfExports(f.getAnnotations());
            if (num > 1) {
                logger.warn("Field {} has more than 1 export", f);
                ++errors;
            }
        }
        for (Method m : cf.getMethods()) {
            int num = this.getNumberOfExports(m.getAnnotations());
            if (num > 1) {
                logger.warn("Method {} has more than 1 export", m);
                ++errors;
            }
        }
    }
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 44 with Field

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

the class AnnotationIntegrityChecker method run.

public void run() {
    for (ClassFile cf : one.getClasses()) {
        ClassFile other = (ClassFile) mapping.get(cf);
        List<Field> exf1 = getExportedFields(cf);
        List<Method> exm1 = getExportedMethods(cf);
        for (Field f1 : exf1) {
            boolean isImported = isImported(cf, f1.getName(), f1.isStatic());
            Field f2;
            if (other == null) {
                if (!f1.isStatic() && isImported) {
                    ++errors;
                    logger.error("No other class for {} which contains imported field {}", cf, f1);
                }
                continue;
            }
            if (f1.isStatic()) {
                f2 = findExportedFieldStatic(two, DeobAnnotations.getExportedName(f1.getAnnotations()));
            } else {
                f2 = findExportedField(other, DeobAnnotations.getExportedName(f1.getAnnotations()));
            }
            if (f2 == null) {
                if (isImported) {
                    logger.error("Missing IMPORTED field on {} named {}", other, DeobAnnotations.getExportedName(f1.getAnnotations()));
                    ++errors;
                } else {
                    logger.warn("Missing exported field on {} named {}", other, DeobAnnotations.getExportedName(f1.getAnnotations()));
                    ++warnings;
                }
            }
        }
        for (Method m1 : exm1) {
            boolean isImported = isImported(cf, m1.getName(), m1.isStatic());
            Method m2;
            if (other == null) {
                if (!m1.isStatic() && isImported) {
                    ++errors;
                    logger.error("No other class for {} which contains imported method {}", cf, m1);
                }
                continue;
            }
            if (m1.isStatic()) {
                m2 = findExportedMethodStatic(two, DeobAnnotations.getExportedName(m1.getAnnotations()));
            } else {
                m2 = findExportedMethod(other, DeobAnnotations.getExportedName(m1.getAnnotations()));
            }
            if (m2 == null) {
                if (isImported) {
                    logger.error("Missing IMPORTED method on {} named {} ({})", other, DeobAnnotations.getExportedName(m1.getAnnotations()), m1);
                    ++errors;
                } else {
                    logger.warn("Missing exported method on {} named {} ({})", other, DeobAnnotations.getExportedName(m1.getAnnotations()), m1);
                    ++warnings;
                }
            }
        }
    }
    checkAnnotationCounts();
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 45 with Field

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

the class PacketLengthFinder method run.

// getstatic             class272/field3690 [I
// getstatic             Client/packetType I
// iaload
// putstatic             Client/packetLength I
private void run(Code code) {
    if (code == null) {
        return;
    }
    Instructions instructions = code.getInstructions();
    Field type = packetType.getPacketType();
    for (int i = 0; i < instructions.getInstructions().size() - 3; ++i) {
        Instruction i1 = instructions.getInstructions().get(i), i2 = instructions.getInstructions().get(i + 1), i3 = instructions.getInstructions().get(i + 2), i4 = instructions.getInstructions().get(i + 3);
        if (!(i1 instanceof GetStatic)) {
            continue;
        }
        if (!(i2 instanceof GetStatic)) {
            continue;
        }
        GetStatic gs = (GetStatic) i2;
        if (gs.getMyField() != type) {
            continue;
        }
        if (!(i3 instanceof IALoad)) {
            continue;
        }
        if (!(i4 instanceof PutStatic)) {
            continue;
        }
        PutStatic ps = (PutStatic) i4;
        assert packetLength == null : "packetLength already found";
        packetLength = ps.getMyField();
        getArray = (GetStatic) i1;
        getType = gs;
        load = (IALoad) i3;
        store = ps;
        return;
    }
}
Also used : Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) IALoad(net.runelite.asm.attributes.code.instructions.IALoad) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic)

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