Search in sources :

Example 66 with Method

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

the class ConstantParameter method findConstantParameter.

// find constant values passed as parameters
private void findConstantParameter(List<Method> methods, InstructionContext invokeCtx) {
    checkMethodsAreConsistent(methods);
    // all methods must have the same signature etc
    Method method = methods.get(0);
    int offset = method.isStatic() ? 0 : 1;
    List<StackContext> pops = invokeCtx.getPops();
    outer: // object is popped first, then param 1, 2, 3, etc. double and long take two slots.
    for (int lvtOffset = offset, parameterIndex = 0; parameterIndex < method.getDescriptor().size(); lvtOffset += method.getDescriptor().getTypeOfArg(parameterIndex++).getSize()) {
        // get(0) == first thing popped which is the last parameter,
        // get(descriptor.size() - 1) == first parameter
        StackContext ctx = pops.get(method.getDescriptor().size() - 1 - parameterIndex);
        ConstantMethodParameter cmp = getCMPFor(methods, parameterIndex, lvtOffset);
        if (cmp.invalid) {
            continue;
        }
        if (ctx.getPushed().getInstruction() instanceof PushConstantInstruction) {
            PushConstantInstruction pc = (PushConstantInstruction) ctx.getPushed().getInstruction();
            if (!(pc.getConstant() instanceof Number)) {
                cmp.invalid = true;
                continue;
            }
            Number number = (Number) pc.getConstant();
            if (!cmp.values.contains(number)) {
                cmp.values.add((Number) pc.getConstant());
            }
        } else {
            cmp.invalid = true;
        }
    }
}
Also used : PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) StackContext(net.runelite.asm.execution.StackContext) Method(net.runelite.asm.Method)

Example 67 with Method

use of net.runelite.asm.Method 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 68 with Method

use of net.runelite.asm.Method 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 69 with Method

use of net.runelite.asm.Method 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)

Example 70 with Method

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

the class Mapper method mapStaticMethods.

private ParallelExecutorMapping mapStaticMethods() {
    StaticMethodSignatureMapper smsm = new StaticMethodSignatureMapper();
    smsm.map(source, target);
    List<ParallelExecutorMapping> pmes = new ArrayList<>();
    for (Method m : smsm.getMap().keySet()) {
        Collection<Method> methods = smsm.getMap().get(m);
        ExecutionMapper em = new ExecutionMapper(m, methods);
        ParallelExecutorMapping mapping = em.run();
        if (mapping == null) {
            continue;
        }
        Mapping map = mapping.map(null, mapping.m1, mapping.m2);
        map.wasExecuted = true;
        map.setWeight(mapping.same);
        logger.debug("map static methods mapped {} -> {}", mapping.m1, mapping.m2);
        pmes.add(mapping);
    }
    ParallelExecutorMapping finalm = new ParallelExecutorMapping(source, target);
    for (ParallelExecutorMapping pme : pmes) {
        finalm.merge(pme);
    }
    return finalm;
}
Also used : ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method)

Aggregations

Method (net.runelite.asm.Method)90 ClassFile (net.runelite.asm.ClassFile)64 Field (net.runelite.asm.Field)34 Instruction (net.runelite.asm.attributes.code.Instruction)29 Code (net.runelite.asm.attributes.Code)28 Instructions (net.runelite.asm.attributes.code.Instructions)28 Signature (net.runelite.asm.signature.Signature)28 ClassGroup (net.runelite.asm.ClassGroup)20 ArrayList (java.util.ArrayList)18 Type (net.runelite.asm.Type)18 List (java.util.List)13 Test (org.junit.Test)13 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)10 DeobAnnotations (net.runelite.deob.DeobAnnotations)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)8 InstructionType (net.runelite.asm.attributes.code.InstructionType)8 Label (net.runelite.asm.attributes.code.Label)8