Search in sources :

Example 6 with Element

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

the class ConstantParameter method annotateObfuscatedSignature.

private void annotateObfuscatedSignature(ConstantMethodParameter parameter) {
    for (Method m : parameter.methods) {
        Object value = parameter.values.get(0);
        Annotations annotations = m.getAnnotations();
        Annotation obfuscatedSignature = annotations.find(DeobAnnotations.OBFUSCATED_SIGNATURE);
        if (obfuscatedSignature != null && obfuscatedSignature.getElements().size() == 2) {
            // already annotated
            continue;
        }
        if (obfuscatedSignature == null) {
            obfuscatedSignature = annotations.addAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE, "signature", m.getDescriptor().toString());
        }
        // Add garbage value
        Element element = new Element(obfuscatedSignature);
        element.setName("garbageValue");
        element.setValue(value.toString());
        obfuscatedSignature.addElement(element);
    }
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) DeobAnnotations(net.runelite.deob.DeobAnnotations) Element(net.runelite.asm.attributes.annotation.Element) Method(net.runelite.asm.Method) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 7 with Element

use of net.runelite.asm.attributes.annotation.Element 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 8 with Element

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

the class AnnotationCopier method copy.

private void copy(Annotations an, Annotations an2) {
    for (Annotation a : an2.getAnnotations()) {
        if (isType(a.getType())) {
            an2.removeAnnotation(a);
        }
    }
    for (Annotation a : an.getAnnotations()) {
        if (!isType(a.getType()))
            continue;
        Annotation a2 = new Annotation(an2);
        a2.setType(a.getType());
        for (Element element : a.getElements()) {
            Element element2 = new Element(a2);
            element2.setName(element.getName());
            element2.setValue(element.getValue());
            a2.addElement(element2);
        }
        an2.addAnnotation(a2);
    }
}
Also used : Element(net.runelite.asm.attributes.annotation.Element) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 9 with Element

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

the class Annotations method addAnnotation.

public Annotation addAnnotation(Type type, String name, Object value) {
    Annotation annotation = new Annotation(this);
    annotation.setType(type);
    addAnnotation(annotation);
    Element element = new Element(annotation);
    element.setName(name);
    element.setValue(value);
    annotation.addElement(element);
    return annotation;
}
Also used : Element(net.runelite.asm.attributes.annotation.Element) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Aggregations

Element (net.runelite.asm.attributes.annotation.Element)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)6 Method (net.runelite.asm.Method)2 Annotations (net.runelite.asm.attributes.Annotations)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Optional (java.util.Optional)1 ClassFile (net.runelite.asm.ClassFile)1 ClassGroup (net.runelite.asm.ClassGroup)1 ClassUtil (net.runelite.asm.ClassUtil)1 Type (net.runelite.asm.Type)1 DeobAnnotations (net.runelite.deob.DeobAnnotations)1 JarUtil (net.runelite.deob.util.JarUtil)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1