Search in sources :

Example 76 with ClassFile

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

the class ConstructorMapper method toOtherType.

private Type toOtherType(Type type) {
    if (type.isPrimitive()) {
        return type;
    }
    ClassFile cf = source.findClass(type.getInternalName());
    if (cf == null) {
        return type;
    }
    ClassFile other = (ClassFile) mapping.get(cf);
    if (other == null) {
        logger.debug("Unable to map other type due to no class mapping for {}", cf);
        return null;
    }
    return new Type("L" + other.getName() + ";");
}
Also used : Type(net.runelite.asm.Type) ClassFile(net.runelite.asm.ClassFile)

Example 77 with ClassFile

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

the class Mapper method mapMemberMethods.

private void mapMemberMethods(ParallelExecutorMapping mapping) {
    for (ClassFile cf : source.getClasses()) {
        ClassFile other = (ClassFile) mapping.get(cf);
        if (other == null) {
            continue;
        }
        List<Method> methods1 = cf.getMethods().stream().filter(m -> !m.isStatic()).filter(m -> !m.getName().equals("<init>")).filter(m -> m.getCode() != null).collect(Collectors.toList());
        List<Method> methods2 = other.getMethods().stream().filter(m -> !m.isStatic()).filter(m -> !m.getName().equals("<init>")).filter(m -> m.getCode() != null).collect(Collectors.toList());
        for (Method method : methods1) {
            if (// already mapped
            mapping.get(method) != null) {
                continue;
            }
            List<Method> possible = methods2.stream().filter(m -> MappingExecutorUtil.isMaybeEqual(m.getDescriptor(), method.getDescriptor())).collect(Collectors.toList());
            // Run over execution mapper
            ExecutionMapper em = new ExecutionMapper(method, possible);
            ParallelExecutorMapping map = em.run();
            if (map == null) {
                continue;
            }
            map.map(null, map.m1, map.m2);
            logger.debug("Mapped {} -> {} based on exiting class mapping and method signatures", map.m1, map.m2);
            mapping.merge(map);
        }
    }
}
Also used : List(java.util.List) ClassFile(net.runelite.asm.ClassFile) Logger(org.slf4j.Logger) Method(net.runelite.asm.Method) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 78 with ClassFile

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

the class StaticInitializerIndexer method index.

public void index() {
    for (ClassFile cf : group.getClasses()) {
        Method method = cf.findMethod("<clinit>");
        if (method == null) {
            continue;
        }
        Instructions instructions = method.getCode().getInstructions();
        for (Instruction i : instructions.getInstructions()) {
            if (i.getType() != InstructionType.PUTSTATIC) {
                continue;
            }
            PutStatic putstatic = (PutStatic) i;
            if (!putstatic.getField().getClazz().equals(cf.getPoolClass()) || putstatic.getMyField() == null) {
                continue;
            }
            fields.add(putstatic.getMyField());
        }
    }
    logger.debug("Indexed {} statically initialized fields", fields.size());
}
Also used : ClassFile(net.runelite.asm.ClassFile) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic)

Example 79 with ClassFile

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

the class AnnotationTest method testAnnotation.

@Test
public void testAnnotation() throws IOException {
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("net/runelite/asm/annotations/TestClass.class");
    Assert.assertNotNull(in);
    ClassGroup group = new ClassGroup();
    ClassFile cf = ClassUtil.loadClass(in);
    group.addClass(cf);
    byte[] out = JarUtil.writeClass(group, cf);
    // parse it again
    cf = ClassUtil.loadClass(new ByteArrayInputStream(out));
    Method method = cf.getMethods().get(1);
    Assert.assertEquals("method1", method.getName());
    Annotations annotations = method.getAnnotations();
    Assert.assertNotNull(annotations);
    Optional<Annotation> annotation = annotations.getAnnotations().stream().filter(a -> a.getType().equals(new Type("Lnet/runelite/asm/annotations/MyAnnotation;"))).findFirst();
    Assert.assertTrue(annotation.isPresent());
    Annotation an = annotation.get();
    List<Element> elements = an.getElements();
    Assert.assertEquals(1, elements.size());
    Element element = elements.get(0);
    Assert.assertEquals("value", element.getName());
    Assert.assertEquals("method1", element.getValue());
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) IOException(java.io.IOException) Test(org.junit.Test) Type(net.runelite.asm.Type) ClassGroup(net.runelite.asm.ClassGroup) JarUtil(net.runelite.deob.util.JarUtil) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) Annotation(net.runelite.asm.attributes.annotation.Annotation) ByteArrayInputStream(java.io.ByteArrayInputStream) Method(net.runelite.asm.Method) ClassUtil(net.runelite.asm.ClassUtil) Element(net.runelite.asm.attributes.annotation.Element) Optional(java.util.Optional) Assert(org.junit.Assert) InputStream(java.io.InputStream) ClassFile(net.runelite.asm.ClassFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(net.runelite.asm.attributes.annotation.Element) Method(net.runelite.asm.Method) Annotation(net.runelite.asm.attributes.annotation.Annotation) Type(net.runelite.asm.Type) Annotations(net.runelite.asm.attributes.Annotations) ByteArrayInputStream(java.io.ByteArrayInputStream) ClassGroup(net.runelite.asm.ClassGroup) Test(org.junit.Test)

Example 80 with ClassFile

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

the class ParallellMappingExecutorTest method testStaticStep.

@Test
public void testStaticStep() throws Exception {
    ClassFile cf1 = ClassUtil.loadClass(getClass().getResourceAsStream("mapper/StaticStepTest.class"));
    ClassFile cf2 = ClassUtil.loadClass(getClass().getResourceAsStream("mapper/StaticStepTest.class"));
    ClassGroup group1 = new ClassGroup();
    ClassGroup group2 = new ClassGroup();
    group1.addClass(cf1);
    group2.addClass(cf2);
    group1.buildClassGraph();
    group1.lookup();
    group2.buildClassGraph();
    group2.lookup();
    Method m1 = cf1.findMethod("entry");
    Method m2 = cf2.findMethod("entry");
    Method map1 = cf1.findMethod("map"), map2 = cf2.findMethod("map");
    Assert.assertNotNull(map1);
    Assert.assertNotNull(map2);
    ParallelExecutorMapping map = MappingExecutorUtil.map(m1, m2);
    Assert.assertEquals(map2, map.get(map1));
}
Also used : ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Method(net.runelite.asm.Method) ParallelExecutorMapping(net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping) Test(org.junit.Test)

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