Search in sources :

Example 1 with Annotation

use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.

the class ClassFile method accept.

public void accept(ClassVisitor visitor) {
    String[] ints = interfaces.getInterfaces().stream().map(i -> i.getName()).toArray(String[]::new);
    visitor.visit(version, access, name.getName(), null, super_class.getName(), ints);
    visitor.visitSource(source, null);
    for (Annotation annotation : annotations.getAnnotations()) {
        AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true);
        annotation.accept(av);
    }
    for (Field field : fields) {
        FieldVisitor fv = visitor.visitField(field.getAccessFlags(), field.getName(), field.getType().toString(), null, field.getValue());
        field.accept(fv);
    }
    for (Method method : methods) {
        String[] exceptions = method.getExceptions().getExceptions().stream().map(cl -> cl.getName()).toArray(String[]::new);
        if (exceptions.length == 0) {
            exceptions = null;
        }
        MethodVisitor mv = visitor.visitMethod(method.getAccessFlags(), method.getName(), method.getDescriptor().toString(), null, exceptions);
        method.accept(mv);
    }
    visitor.visitEnd();
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) List(java.util.List) Annotation(net.runelite.asm.attributes.annotation.Annotation) Opcodes(org.objectweb.asm.Opcodes) MethodVisitor(org.objectweb.asm.MethodVisitor) FieldVisitor(org.objectweb.asm.FieldVisitor) Signature(net.runelite.asm.signature.Signature) ClassVisitor(org.objectweb.asm.ClassVisitor) ArrayList(java.util.ArrayList) Class(net.runelite.asm.pool.Class) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) FieldVisitor(org.objectweb.asm.FieldVisitor) Annotation(net.runelite.asm.attributes.annotation.Annotation) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 2 with Annotation

use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.

the class Method method accept.

public void accept(MethodVisitor visitor) {
    for (Annotation annotation : annotations.getAnnotations()) {
        AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true);
        annotation.accept(av);
    }
    if (code != null) {
        code.getInstructions().rebuildLabels();
        visitor.visitCode();
        net.runelite.asm.attributes.code.Exceptions exceptions = code.getExceptions();
        for (net.runelite.asm.attributes.code.Exception exception : exceptions.getExceptions()) {
            assert exception.getStart().getLabel() != null;
            assert exception.getEnd().getLabel() != null;
            assert exception.getHandler().getLabel() != null;
            int idxStart = code.getInstructions().getInstructions().indexOf(exception.getStart());
            int idxEnd = code.getInstructions().getInstructions().indexOf(exception.getEnd());
            assert idxStart != -1;
            assert idxEnd != -1;
            assert code.getInstructions().getInstructions().contains(exception.getHandler());
            assert idxEnd > idxStart;
            visitor.visitTryCatchBlock(exception.getStart().getLabel(), exception.getEnd().getLabel(), exception.getHandler().getLabel(), exception.getCatchType() != null ? exception.getCatchType().getName() : null);
        }
        for (Instruction i : code.getInstructions().getInstructions()) {
            i.accept(visitor);
        }
        visitor.visitMaxs(code.getMaxStack(), code.getMaxLocals());
    }
    visitor.visitEnd();
}
Also used : AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 3 with Annotation

use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.

the class AnnotationMapper method copyAnnotations.

private int copyAnnotations(Annotations from, Annotations to) {
    int count = 0;
    if (from.getAnnotations() == null)
        return count;
    for (Annotation a : from.getAnnotations()) {
        if (isCopyable(a)) {
            Annotation annotation = new Annotation(to);
            annotation.setType(a.getType());
            to.addAnnotation(annotation);
            for (Element e : a.getElements()) {
                Element element = new Element(annotation);
                element.setName(e.getName());
                element.setValue(e.getValue());
                annotation.addElement(element);
            }
            ++count;
        }
    }
    return count;
}
Also used : Element(net.runelite.asm.attributes.annotation.Element) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 4 with Annotation

use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.

the class MappingImporter method makeMappings.

@Test
@Ignore
public void makeMappings() throws IOException {
    InjectionModscript mod = Injection.load(MappingImporter.class.getResourceAsStream(RL_INJECTION));
    int fields = 0, classes = 0;
    for (int i = 0; i < mod.getGetterInjects().size(); ++i) {
        GetterInjectInstruction gii = (GetterInjectInstruction) mod.getGetterInjects().get(i);
        ClassFile cf = this.findClassWithObfuscatedName(gii.getGetterClassName());
        Assert.assertNotNull(cf);
        Field f = this.findFieldWithObfuscatedName(cf, gii.getGetterFieldName());
        if (f == null) {
            // so they don't all exist
            continue;
        }
        String attrName = gii.getGetterName();
        attrName = Utils.toExportedName(attrName);
        Annotations an = f.getAnnotations();
        Annotation a = an.find(EXPORT);
        if (a != null) {
            String exportedName = a.getElement().getString();
            if (!attrName.equals(exportedName)) {
                logger.info("Exported field " + f + " with mismatched name. Theirs: " + attrName + ", mine: " + exportedName);
            }
        } else {
            an.addAnnotation(EXPORT, "value", attrName);
            logger.info("Exporting field " + f + " with name " + attrName);
            ++fields;
        }
    }
    for (AddInterfaceInstruction aii : mod.getAddInterfaceInjects()) {
        ClassFile cf = this.findClassWithObfuscatedName(aii.getClientClass());
        Assert.assertNotNull(cf);
        String iface = aii.getInterfaceClass();
        iface = iface.replace("com/runeloader/api/bridge/os/accessor/", "");
        Annotations an = cf.getAnnotations();
        Annotation a = an.find(IMPLEMENTS);
        if (a != null) {
            String implementsName = a.getElement().getString();
            if (!iface.equals(implementsName)) {
                logger.info("Implements class " + cf + " with mismatched name. Theirs: " + iface + ", mine: " + implementsName);
            }
        } else {
            an.addAnnotation(IMPLEMENTS, "value", iface);
            logger.info("Exporting class " + cf.getName() + " with name " + iface);
            ++classes;
        }
    }
    logger.info("Added {} fields, {} classes", fields, classes);
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Annotations(net.runelite.asm.attributes.Annotations) InjectionModscript(net.runelite.runeloader.inject.InjectionModscript) AddInterfaceInstruction(net.runelite.runeloader.inject.AddInterfaceInstruction) GetterInjectInstruction(net.runelite.runeloader.inject.GetterInjectInstruction) Annotation(net.runelite.asm.attributes.annotation.Annotation) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Annotation

use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.

the class Inject method getFieldType.

public Type getFieldType(Field f) {
    Type type = f.getType();
    Annotation obfSignature = f.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE);
    if (obfSignature != null) {
        // Annotation exists. Type was updated by us during deobfuscation
        type = DeobAnnotations.getObfuscatedType(f);
    }
    return type;
}
Also used : Type(net.runelite.asm.Type) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Aggregations

Annotation (net.runelite.asm.attributes.annotation.Annotation)21 ClassFile (net.runelite.asm.ClassFile)10 Method (net.runelite.asm.Method)8 Annotations (net.runelite.asm.attributes.Annotations)8 Field (net.runelite.asm.Field)7 Element (net.runelite.asm.attributes.annotation.Element)6 Signature (net.runelite.asm.signature.Signature)6 DeobAnnotations (net.runelite.deob.DeobAnnotations)6 IOException (java.io.IOException)5 Type (net.runelite.asm.Type)5 List (java.util.List)4 GetField (net.runelite.asm.attributes.code.instructions.GetField)4 PutField (net.runelite.asm.attributes.code.instructions.PutField)4 ArrayList (java.util.ArrayList)3 ClassGroup (net.runelite.asm.ClassGroup)3 Instruction (net.runelite.asm.attributes.code.Instruction)3 Class (net.runelite.asm.pool.Class)3 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2