use of org.jf.dexlib2.immutable.ImmutableAnnotationElement in project soot by Sable.
the class DexPrinter method buildInnerClassAttribute.
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 = DexInnerClassParser.getOuterClassNameFromTag(icTag);
String innerClass = icTag.getInnerClass().replaceAll("/", ".");
// 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;
}
use of org.jf.dexlib2.immutable.ImmutableAnnotationElement in project soot by Sable.
the class DexPrinter method buildMethodAnnotations.
private Set<Annotation> buildMethodAnnotations(SootMethod m) {
Set<String> skipList = new HashSet<String>();
Set<Annotation> annotations = buildCommonAnnotations(m, skipList);
for (Tag t : m.getTags()) {
if (t.getName().equals("VisibilityAnnotationTag")) {
List<ImmutableAnnotation> visibilityItems = buildVisibilityAnnotationTag((VisibilityAnnotationTag) t, skipList);
annotations.addAll(visibilityItems);
}
}
List<SootClass> exceptionList = m.getExceptionsUnsafe();
if (exceptionList != null && !exceptionList.isEmpty()) {
List<ImmutableEncodedValue> valueList = new ArrayList<ImmutableEncodedValue>(exceptionList.size());
for (SootClass exceptionClass : exceptionList) {
valueList.add(new ImmutableTypeEncodedValue(DexType.toDalvikICAT(exceptionClass.getName()).replace(".", "/")));
}
ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList);
ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue);
Set<ImmutableAnnotationElement> elements = Collections.singleton(valueElement);
ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Throws;", elements);
annotations.add(ann);
}
return annotations;
}
use of org.jf.dexlib2.immutable.ImmutableAnnotationElement in project soot by Sable.
the class DexPrinter method buildVisibilityAnnotationTag.
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;
}
use of org.jf.dexlib2.immutable.ImmutableAnnotationElement in project soot by Sable.
the class DexPrinter method buildCommonAnnotations.
private Set<Annotation> buildCommonAnnotations(AbstractHost host, Set<String> skipList) {
Set<Annotation> annotations = new HashSet<Annotation>();
// handle deprecated tag
if (host.hasTag("DeprecatedTag") && !skipList.contains("Ljava/lang/Deprecated;")) {
ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Ljava/lang/Deprecated;", Collections.<AnnotationElement>emptySet());
annotations.add(ann);
skipList.add("Ljava/lang/Deprecated;");
}
// handle signature tag
if (host.hasTag("SignatureTag") && !skipList.contains("Ldalvik/annotation/Signature;")) {
SignatureTag tag = (SignatureTag) host.getTag("SignatureTag");
List<String> splitSignature = SootToDexUtils.splitSignature(tag.getSignature());
Set<ImmutableAnnotationElement> elements = null;
if (splitSignature != null && splitSignature.size() > 0) {
List<ImmutableEncodedValue> valueList = new ArrayList<ImmutableEncodedValue>();
for (String s : splitSignature) {
ImmutableStringEncodedValue val = new ImmutableStringEncodedValue(s);
valueList.add(val);
}
ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList);
ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue);
elements = Collections.singleton(valueElement);
} else
LOGGER.info("Signature annotation without value detected");
ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Signature;", elements);
annotations.add(ann);
skipList.add("Ldalvik/annotation/Signature;");
}
return annotations;
}
use of org.jf.dexlib2.immutable.ImmutableAnnotationElement in project soot by Sable.
the class DexPrinter method buildMemberClassesAttribute.
private List<Annotation> buildMemberClassesAttribute(SootClass parentClass, InnerClassAttribute t, Set<String> skipList) {
List<Annotation> anns = null;
Set<String> memberClasses = null;
// Collect the inner classes
for (Tag t2 : t.getSpecs()) {
InnerClassTag icTag = (InnerClassTag) t2;
String outerClass = DexInnerClassParser.getOuterClassNameFromTag(icTag);
// Only classes with names are member classes
if (icTag.getOuterClass() != null && parentClass.getName().equals(outerClass)) {
if (memberClasses == null)
memberClasses = new HashSet<String>();
memberClasses.add(SootToDexUtils.getDexClassName(icTag.getInnerClass()));
}
}
// Write the member classes
if (memberClasses != null && !memberClasses.isEmpty() && skipList.add("Ldalvik/annotation/MemberClasses;")) {
List<EncodedValue> classes = new ArrayList<EncodedValue>();
for (String memberClass : memberClasses) {
ImmutableTypeEncodedValue classValue = new ImmutableTypeEncodedValue(memberClass);
classes.add(classValue);
}
ImmutableArrayEncodedValue classesValue = new ImmutableArrayEncodedValue(classes);
ImmutableAnnotationElement element = new ImmutableAnnotationElement("value", classesValue);
ImmutableAnnotation memberAnnotation = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/MemberClasses;", Collections.singletonList(element));
if (anns == null)
anns = new ArrayList<Annotation>();
anns.add(memberAnnotation);
}
return anns;
}
Aggregations