org.jf.dexlib2.iface.AnnotationElement Java Examples

The following examples show how to use org.jf.dexlib2.iface.AnnotationElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImmutableAnnotation.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public ImmutableAnnotation(int visibility,
                           @Nonnull String type,
                           @Nullable Collection<? extends AnnotationElement> elements) {
    this.visibility = visibility;
    this.type = type;
    this.elements = ImmutableAnnotationElement.immutableSetOf(elements);
}
 
Example #2
Source File: ImmutableAnnotationElement.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) {
    if (annotationElement instanceof ImmutableAnnotationElement) {
        return (ImmutableAnnotationElement)annotationElement;
    }
    return new ImmutableAnnotationElement(
            annotationElement.getName(),
            annotationElement.getValue());
}
 
Example #3
Source File: BuilderContext.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull Set<? extends BuilderAnnotationElement> internAnnotationElements(
        @Nonnull Set<? extends AnnotationElement> elements) {
    return ImmutableSet.copyOf(
            Iterators.transform(elements.iterator(),
                    new Function<AnnotationElement, BuilderAnnotationElement>() {
                        @Nullable @Override
                        public BuilderAnnotationElement apply(AnnotationElement input) {
                            return internAnnotationElement(input);
                        }
                    }));
}
 
Example #4
Source File: ImmutableAnnotationElement.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) {
    if (annotationElement instanceof ImmutableAnnotationElement) {
        return (ImmutableAnnotationElement)annotationElement;
    }
    return new ImmutableAnnotationElement(
            annotationElement.getName(),
            annotationElement.getValue());
}
 
Example #5
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private Annotation buildEnclosingMethodTag(EnclosingMethodTag t, Set<String> skipList) {
	if (!skipList.add("Ldalvik/annotation/EnclosingMethod;"))
		return null;
	
	if (t.getEnclosingMethod() == null)
		return null;

	String[] split1 = t.getEnclosingMethodSig().split("\\)");
 String parametersS = split1[0].replaceAll("\\(", "");
 String returnTypeS = split1[1];
 
 List<String> typeList = new ArrayList<String>();
    if (!parametersS.equals("")) {
        for (String p : Util.splitParameters(parametersS)) {
            if (!p.isEmpty())
            	typeList.add(p);
        }
    }
    
 ImmutableMethodReference mRef = new ImmutableMethodReference
 		(SootToDexUtils.getDexClassName(t.getEnclosingClass()),
 		t.getEnclosingMethod(), typeList, returnTypeS);
	ImmutableMethodEncodedValue methodRef = new ImmutableMethodEncodedValue
			(dexFile.internMethodReference(mRef));
	AnnotationElement methodElement = new ImmutableAnnotationElement("value", methodRef);
	
	return new ImmutableAnnotation(AnnotationVisibility.SYSTEM,
			"Ldalvik/annotation/EnclosingMethod;",
			Collections.singleton(methodElement));
}
 
Example #6
Source File: BaseAnnotationElement.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (o != null && o instanceof AnnotationElement) {
        AnnotationElement other = (AnnotationElement)o;
        return getName().equals(other.getName()) &&
               getValue().equals(other.getValue());
    }
    return false;
}
 
Example #7
Source File: ImmutableAnnotation.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableAnnotation(int visibility,
                           @Nonnull String type,
                           @Nullable Collection<? extends AnnotationElement> elements) {
    this.visibility = visibility;
    this.type = type;
    this.elements = ImmutableAnnotationElement.immutableSetOf(elements);
}
 
Example #8
Source File: ImmutableAnnotation.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableAnnotation(int visibility,
                           @Nonnull String type,
                           @Nullable Collection<? extends AnnotationElement> elements) {
    this.visibility = visibility;
    this.type = type;
    this.elements = ImmutableAnnotationElement.immutableSetOf(elements);
}
 
Example #9
Source File: BaseAnnotationElement.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (o != null && o instanceof AnnotationElement) {
        AnnotationElement other = (AnnotationElement)o;
        return getName().equals(other.getName()) &&
               getValue().equals(other.getValue());
    }
    return false;
}
 
Example #10
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private List<ImmutableAnnotation> buildVisibilityAnnotationTag
		(VisibilityAnnotationTag t, Set<String> skipList) {
   	if (t.getAnnotations() == null)
   		return Collections.emptyList();
   	
   	List<ImmutableAnnotation> annotations = new ArrayList<ImmutableAnnotation>();
       for (AnnotationTag at: t.getAnnotations()) {
           String type = at.getType();
           if (!skipList.add(type))
           	continue;
           
           Set<String> alreadyWritten = new HashSet<String>();
           List<AnnotationElement> elements = null;
           if (!at.getElems().isEmpty()) {
           	elements = new ArrayList<AnnotationElement>();
            for (AnnotationElem ae : at.getElems()) {
            	if (ae.getName() == null || ae.getName().isEmpty())
            		throw new RuntimeException("Null or empty annotation name encountered");
            	if (!alreadyWritten.add(ae.getName()))
            		throw new RuntimeException("Duplicate annotation attribute: " + ae.getName());
            	
                EncodedValue value = buildEncodedValueForAnnotation(ae);
                ImmutableAnnotationElement element = new ImmutableAnnotationElement
                		(ae.getName(), value);
                elements.add(element);
            }
           }
           
           String typeName = SootToDexUtils.getDexClassName(at.getType());
           ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(t.getVisibility()),
           		typeName, elements);
           annotations.add(ann);
       }
       return annotations;
}
 
Example #11
Source File: ImmutableAnnotationElement.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) {
    if (annotationElement instanceof ImmutableAnnotationElement) {
        return (ImmutableAnnotationElement)annotationElement;
    }
    return new ImmutableAnnotationElement(
            annotationElement.getName(),
            annotationElement.getValue());
}
 
Example #12
Source File: BuilderContext.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull Set<? extends BuilderAnnotationElement> internAnnotationElements(
        @Nonnull Set<? extends AnnotationElement> elements) {
    return ImmutableSet.copyOf(
            Iterators.transform(elements.iterator(),
                    new Function<AnnotationElement, BuilderAnnotationElement>() {
                        @Nullable @Override
                        public BuilderAnnotationElement apply(AnnotationElement input) {
                            return internAnnotationElement(input);
                        }
                    }));
}
 
Example #13
Source File: BuilderContext.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nonnull Set<? extends BuilderAnnotationElement> internAnnotationElements(
        @Nonnull Set<? extends AnnotationElement> elements) {
    return ImmutableSet.copyOf(
            Iterators.transform(elements.iterator(),
                    new Function<AnnotationElement, BuilderAnnotationElement>() {
                        @Nullable @Override
                        public BuilderAnnotationElement apply(AnnotationElement input) {
                            return internAnnotationElement(input);
                        }
                    }));
}
 
Example #14
Source File: AnnotationEncodedValueAdaptor.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static void writeElementsTo(IndentingWriter writer,
                                   Collection<? extends AnnotationElement> annotationElements) throws IOException {
    writer.indent(4);
    for (AnnotationElement annotationElement: annotationElements) {
        writer.write(annotationElement.getName());
        writer.write(" = ");
        EncodedValueAdaptor.writeTo(writer, annotationElement.getValue());
        writer.write('\n');
    }
    writer.deindent(4);
}
 
Example #15
Source File: AnnotationPool.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull Annotation annotation) {
    Integer prev = internedItems.put(annotation, 0);
    if (prev == null) {
        typePool.intern(annotation.getType());
        for (AnnotationElement element: annotation.getElements()) {
            stringPool.intern(element.getName());
            DexPool.internEncodedValue(element.getValue(), stringPool, typePool, fieldPool, methodPool);
        }
    }
}
 
Example #16
Source File: BaseAnnotationElement.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (o != null && o instanceof AnnotationElement) {
        AnnotationElement other = (AnnotationElement)o;
        return getName().equals(other.getName()) &&
               getValue().equals(other.getValue());
    }
    return false;
}
 
Example #17
Source File: ImmutableAnnotationElement.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) {
    if (annotationElement instanceof ImmutableAnnotationElement) {
        return (ImmutableAnnotationElement)annotationElement;
    }
    return new ImmutableAnnotationElement(
            annotationElement.getName(),
            annotationElement.getValue());
}
 
Example #18
Source File: AnnotationEncodedValueAdaptor.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static void writeElementsTo(@Nonnull IndentingWriter writer,
                                   @Nonnull Collection<? extends AnnotationElement> annotationElements,
                                   @Nullable String containingClass) throws IOException {
    writer.indent(4);
    for (AnnotationElement annotationElement: annotationElements) {
        writer.write(annotationElement.getName());
        writer.write(" = ");
        EncodedValueAdaptor.writeTo(writer, annotationElement.getValue(), containingClass);
        writer.write('\n');
    }
    writer.deindent(4);
}
 
Example #19
Source File: ApkPatch.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static void getMethodAnnotaionPrepareClasses(DexDiffInfo dexDiffInfo, Set<String> prepareclasses){

        for (DexBackedMethod method:dexDiffInfo.getModifiedMethods()){
            Set<? extends Annotation>annotations = method.getAnnotations();
            if (annotations == null){
                continue;
            }
            for (Annotation annotation:annotations){
                String type = annotation.getType();
                if (type!= null&&type.startsWith("L")&&type.endsWith(";")){
                    prepareclasses.add(type.substring(1, type.length() - 1).replace('/', '.'));
                    System.out.println("prepare class: " + type);
                }
                Set<? extends AnnotationElement> elements = annotation.getElements();
                for (AnnotationElement dexBackedAnnotationElement:elements){
                    if (dexBackedAnnotationElement.getValue() instanceof DexBackedArrayEncodedValue){
                        List<? extends EncodedValue> values = ((DexBackedArrayEncodedValue) dexBackedAnnotationElement.getValue()).getValue();
                        for (EncodedValue encodedValue:values) {
                            if (encodedValue instanceof TypeEncodedValue) {
                                prepareclasses.add(((TypeEncodedValue) encodedValue).getValue().substring(1, ((TypeEncodedValue) encodedValue).getValue().length() - 1).replace('/', '.'));
                                System.out.println("prepare class: " + ((TypeEncodedValue) encodedValue).getValue());
                            }
                        }

                    }else if (dexBackedAnnotationElement.getValue() instanceof DexBackedTypeEncodedValue){
                        String value = ((DexBackedTypeEncodedValue) dexBackedAnnotationElement.getValue()).getValue();
                        prepareclasses.add(value.substring(1, value.length() - 1).replace('/', '.'));
                        System.out.println("prepare class: " + value);
                    }
                }
            }
        }

    }
 
Example #20
Source File: ImmutableAnnotation.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public ImmutableAnnotation(int visibility,
                           @Nonnull String type,
                           @Nullable Collection<? extends AnnotationElement> elements) {
    this.visibility = visibility;
    this.type = type;
    this.elements = ImmutableAnnotationElement.immutableSetOf(elements);
}
 
Example #21
Source File: BackSmaliMain.java    From SimpleSmali with Apache License 2.0 5 votes vote down vote up
private static void annotionToString(Writer printStream, Annotation annotation, Indentation indent)
        throws IOException {
    List<String> attributes = new ArrayList<String>();
    Set<? extends AnnotationElement> elements = annotation.getElements();
    for (AnnotationElement element : elements) {
        attributes.add(String
                .format("%s=%s", element.getName(), DexEncodedValueUtils.getEncodeValue(element.getValue())));
    }
    printStream.write(indent.toString());
    printStream.write(String.format("@%s(%s)", annotation.getType(), String.join(",", attributes)));
    printStream.write(newLine);
}
 
Example #22
Source File: AnnotationPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull Annotation annotation) {
    Integer prev = internedItems.put(annotation, 0);
    if (prev == null) {
        typePool.intern(annotation.getType());
        for (AnnotationElement element: annotation.getElements()) {
            stringPool.intern(element.getName());
            DexPool.internEncodedValue(element.getValue(), stringPool, typePool, fieldPool, methodPool);
        }
    }
}
 
Example #23
Source File: BuilderContext.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull Set<? extends BuilderAnnotationElement> internAnnotationElements(
        @Nonnull Set<? extends AnnotationElement> elements) {
    return ImmutableSet.copyOf(
            Iterators.transform(elements.iterator(),
                    new Function<AnnotationElement, BuilderAnnotationElement>() {
                        @Nullable @Override
                        public BuilderAnnotationElement apply(AnnotationElement input) {
                            return internAnnotationElement(input);
                        }
                    }));
}
 
Example #24
Source File: ImmutableAnnotationElement.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static ImmutableSet<ImmutableAnnotationElement> immutableSetOf(
        @Nullable Iterable<? extends AnnotationElement> list) {
    return CONVERTER.toSet(list);
}
 
Example #25
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private List<ImmutableAnnotation> buildVisibilityParameterAnnotationTag
  		(VisibilityParameterAnnotationTag t, Set<String> skipList,
  				int paramIdx) {
if (t.getVisibilityAnnotations() == null)
  		return Collections.emptyList();

      int paramTagIdx = 0;
  	List<ImmutableAnnotation> annotations = new ArrayList<ImmutableAnnotation>();
      for (VisibilityAnnotationTag vat : t.getVisibilityAnnotations()) {
      	if (paramTagIdx == paramIdx
      			&& vat != null
      			&& vat.getAnnotations() != null)
       	for (AnnotationTag at : vat.getAnnotations()) {
            String type = at.getType();
            if (!skipList.add(type))
            	continue;
            
            Set<String> alreadyWritten = new HashSet<String>();
            List<AnnotationElement> elements = null;
            if (!at.getElems().isEmpty()) {
            	elements = new ArrayList<AnnotationElement>();
	            for (AnnotationElem ae : at.getElems()) {
	            	if (ae.getName() == null || ae.getName().isEmpty())
	            		throw new RuntimeException("Null or empty annotation name encountered");
	            	if (!alreadyWritten.add(ae.getName()))
	            		throw new RuntimeException("Duplicate annotation attribute: " + ae.getName());
	
	            	EncodedValue value = buildEncodedValueForAnnotation(ae);
	                ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value);
	                elements.add(element);
	            }
            }
            
            ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(vat.getVisibility()),
            		SootToDexUtils.getDexClassName(at.getType()),
            		elements);
            annotations.add(ann);
       	}
      	paramTagIdx++;
      }
      return annotations;
  }
 
Example #26
Source File: BaseAnnotationElement.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(AnnotationElement o) {
    int res = getName().compareTo(o.getName());
    if (res != 0) return res;
    return getValue().compareTo(o.getValue());
}
 
Example #27
Source File: ImmutableAnnotationEncodedValue.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public ImmutableAnnotationEncodedValue(@Nonnull String type,
                                       @Nullable Collection<? extends AnnotationElement> elements) {
    this.type = type;
    this.elements = ImmutableAnnotationElement.immutableSetOf(elements);
}
 
Example #28
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private List<Annotation> buildInnerClassAttribute(SootClass parentClass,
 		InnerClassAttribute t, Set<String> skipList) {
 	if (t.getSpecs() == null)
 		return null;
 	
 	List<Annotation> anns = null;
 	for (Tag t2 : t.getSpecs()) {
 		InnerClassTag icTag = (InnerClassTag) t2;
 		
     	// In Dalvik, both the EnclosingMethod/EnclosingClass tag and the
     	// InnerClass tag are written to the inner class which is different
     	// to Java. We thus check whether this tag actually points to our
 		// outer class.
 		String outerClass = getOuterClassNameFromTag(icTag);
String innerClass = icTag.getInnerClass().replaceAll("/", ".");
			
// Only write the InnerClass tag to the inner class itself, not
// the other one. If the outer class points to our parent, but
// this is simply the wrong inner class, we also continue with the
// next tag.
 		if (!parentClass.hasOuterClass()
 				|| !innerClass.equals(parentClass.getName()))
 			continue;
 		
 		// If the outer class points to the very same class, we null it
 		if (parentClass.getName().equals(outerClass)
 				&& icTag.getOuterClass() == null)
 			outerClass = null;
 		
 		// Do not write garbage. Never.
 		if (parentClass.getName().equals(outerClass))
 			continue;
 		
 		// This is an actual inner class. Write the annotation
     	if (skipList.add("Ldalvik/annotation/InnerClass;")) {
  		// InnerClass annotation
      	List<AnnotationElement> elements = new ArrayList<AnnotationElement>();
   	
   	ImmutableAnnotationElement flagsElement = new ImmutableAnnotationElement
   			("accessFlags", new ImmutableIntEncodedValue(icTag.getAccessFlags()));
   	elements.add(flagsElement);
   	
   	ImmutableEncodedValue nameValue;
   	if (icTag.getShortName() != null && !icTag.getShortName().isEmpty())
   		nameValue = new ImmutableStringEncodedValue(icTag.getShortName());
   	else
   		nameValue = ImmutableNullEncodedValue.INSTANCE;
   	
   	ImmutableAnnotationElement nameElement = new ImmutableAnnotationElement
    		("name", nameValue);
    elements.add(nameElement);
   	
   	if (anns == null) anns = new ArrayList<Annotation>();
   	anns.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM,
   			"Ldalvik/annotation/InnerClass;",
   			elements));
     	}
 	}
 	    	
 	return anns;
 }
 
Example #29
Source File: AnnotationPool.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public EncodedValue getElementValue(@Nonnull AnnotationElement annotationElement) {
    return annotationElement.getValue();
}
 
Example #30
Source File: ImmutableAnnotationElement.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected ImmutableAnnotationElement makeImmutable(@Nonnull AnnotationElement item) {
    return ImmutableAnnotationElement.of(item);
}