Search in sources :

Example 71 with ClassFile

use of net.runelite.asm.ClassFile 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 72 with ClassFile

use of net.runelite.asm.ClassFile 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 73 with ClassFile

use of net.runelite.asm.ClassFile 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 74 with ClassFile

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

the class AnnotationMapper method run.

public void run() {
    int count = 0;
    for (ClassFile c : source.getClasses()) {
        ClassFile other = (ClassFile) mapping.get(c);
        count += run(c, other);
    }
    logger.info("Copied {} annotations", count);
}
Also used : ClassFile(net.runelite.asm.ClassFile)

Example 75 with ClassFile

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

the class ConstructorMapper method mapConstructors.

/**
 * Map constructors based on the class mappings of the given mapping
 */
public void mapConstructors() {
    for (ClassFile cf : source.getClasses()) {
        ClassFile other = (ClassFile) mapping.get(cf);
        if (other == null) {
            continue;
        }
        for (Method m : cf.getMethods()) {
            if (!m.getName().equals("<init>")) {
                continue;
            }
            Signature otherSig = toOtherSignature(m.getDescriptor());
            if (otherSig == null) {
                continue;
            }
            logger.debug("Converted signature {} -> {}", m.getDescriptor(), otherSig);
            Method m2 = other.findMethod(m.getName(), otherSig);
            if (m2 == null) {
                logger.warn("Unable to find other constructor for {}, looking for signature {} on class {}", m, otherSig, other);
                continue;
            }
            ParallelExecutorMapping p = MappingExecutorUtil.map(m, m2);
            p.map(null, m, m2);
            mapping.merge(p);
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method)

Aggregations

ClassFile (net.runelite.asm.ClassFile)103 Method (net.runelite.asm.Method)62 Field (net.runelite.asm.Field)39 ClassGroup (net.runelite.asm.ClassGroup)32 Code (net.runelite.asm.attributes.Code)21 Instruction (net.runelite.asm.attributes.code.Instruction)18 Test (org.junit.Test)18 Signature (net.runelite.asm.signature.Signature)17 Type (net.runelite.asm.Type)16 Instructions (net.runelite.asm.attributes.code.Instructions)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 IOException (java.io.IOException)9 InputStream (java.io.InputStream)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)9 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)9 HashMap (java.util.HashMap)8 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)7