Search in sources :

Example 16 with Method

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

the class AnnotationMapper method run.

private int run(ClassFile from, ClassFile to) {
    int count = 0;
    if (hasCopyableAnnotation(from.getAnnotations())) {
        if (to != null) {
            count += copyAnnotations(from.getAnnotations(), to.getAnnotations());
        } else {
            logger.warn("Class {} has copyable annotations but there is no mapped class", from);
        }
    }
    for (Field f : from.getFields()) {
        if (!hasCopyableAnnotation(f.getAnnotations()))
            continue;
        Field other = (Field) mapping.get(f);
        if (other == null) {
            logger.warn("Unable to map annotated field {} named {}", f, DeobAnnotations.getExportedName(f.getAnnotations()));
            continue;
        }
        count += copyAnnotations(f.getAnnotations(), other.getAnnotations());
    }
    for (Method m : from.getMethods()) {
        if (!hasCopyableAnnotation(m.getAnnotations()))
            continue;
        Method other = (Method) mapping.get(m);
        if (other == null) {
            logger.warn("Unable to map annotated method {} named {}", m, DeobAnnotations.getExportedName(m.getAnnotations()));
            continue;
        }
        count += copyAnnotations(m.getAnnotations(), other.getAnnotations());
    }
    return count;
}
Also used : Field(net.runelite.asm.Field) Method(net.runelite.asm.Method)

Example 17 with Method

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

the class ExecutionMapper method run.

public ParallelExecutorMapping run() {
    ParallelExecutorMapping highest = null;
    boolean multiple = false;
    for (Method m : methods2) {
        ParallelExecutorMapping mapping = MappingExecutorUtil.map(method1, m);
        if (highest == null || mapping.same > highest.same) {
            highest = mapping;
            multiple = false;
        } else if (mapping.same == highest.same) {
            multiple = true;
        }
    }
    if (multiple)
        return null;
    return highest;
}
Also used : Method(net.runelite.asm.Method)

Example 18 with Method

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

the class Mapper method mapUnexecutedMethods.

/**
 * execute and map already mapped methods that have not yet been "executed",
 * and apply their mappings
 * @param mapping
 * @return
 */
private boolean mapUnexecutedMethods(ParallelExecutorMapping mapping) {
    // map has already been reduced
    boolean mapped = false;
    for (Object o : mapping.getMap().keySet()) {
        Mapping m = mapping.getMappings(o).iterator().next();
        if (m.wasExecuted || !(m.getFrom() instanceof Method)) {
            continue;
        }
        Method m1 = (Method) m.getFrom(), m2 = (Method) m.getObject();
        if (m1.getCode() == null || m2.getCode() == null) {
            continue;
        }
        // m was picked up as an invoke instruction when mapping
        // something else, but wasn't executed itself
        logger.debug("Wasn't executed {}", m);
        ParallelExecutorMapping ma = MappingExecutorUtil.map(m1, m2);
        m.wasExecuted = true;
        mapped = true;
        mapping.merge(ma);
    }
    return mapped;
}
Also used : Method(net.runelite.asm.Method)

Example 19 with Method

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

the class Mapper method mapMethods.

private ParallelExecutorMapping mapMethods() {
    MethodSignatureMapper msm = new MethodSignatureMapper();
    msm.map(source, target);
    List<ParallelExecutorMapping> pmes = new ArrayList<>();
    for (Method m : msm.getMap().keySet()) {
        Collection<Method> methods = msm.getMap().get(m);
        ExecutionMapper em = new ExecutionMapper(m, methods);
        ParallelExecutorMapping mapping = em.run();
        if (mapping == null) {
            continue;
        }
        mapping.map(null, mapping.m1, mapping.m2).wasExecuted = true;
        logger.debug("map 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)

Example 20 with Method

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

the class UpdateMappingsTest method check.

private void check(ClassGroup group1, ClassGroup group2) {
    for (ClassFile cf : group1.getClasses()) {
        ClassFile other = group2.findClass(cf.getName());
        String implname = DeobAnnotations.getImplements(cf);
        String otherimplname = DeobAnnotations.getImplements(other);
        Assert.assertEquals(implname, otherimplname);
        for (Field f : cf.getFields()) {
            Field otherf = other.findField(f.getName(), f.getType());
            assert otherf != null : "unable to find " + f;
            String name = DeobAnnotations.getExportedName(f.getAnnotations());
            String otherName = DeobAnnotations.getExportedName(otherf.getAnnotations());
            Assert.assertEquals(name + " <-> " + otherName, name, otherName);
        }
        for (Method m : cf.getMethods()) {
            Method otherm = other.findMethod(m.getName(), m.getDescriptor());
            assert otherm != null : "unable to find " + m;
            String name = DeobAnnotations.getExportedName(m.getAnnotations());
            String otherName = DeobAnnotations.getExportedName(otherm.getAnnotations());
            Assert.assertEquals(name + " <-> " + otherName, name, otherName);
        }
    }
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) 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