Search in sources :

Example 6 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.

the class AbstractJasminClass method emitMethod.

protected void emitMethod(SootMethod method) {
    if (method.isPhantom())
        return;
    // Emit prologue
    emit(".method " + Modifier.toString(method.getModifiers()) + " " + method.getName() + jasminDescriptorOf(method.makeRef()));
    Iterator<SootClass> throwsIt = method.getExceptions().iterator();
    while (throwsIt.hasNext()) {
        SootClass exceptClass = throwsIt.next();
        emit(".throws " + exceptClass.getName());
    }
    if (method.hasTag("SyntheticTag") || Modifier.isSynthetic(method.getModifiers())) {
        emit(".synthetic");
    }
    if (method.hasTag("DeprecatedTag")) {
        emit(".deprecated");
    }
    if (method.hasTag("SignatureTag")) {
        String sigAttr = ".signature_attr ";
        SignatureTag sigTag = (SignatureTag) method.getTag("SignatureTag");
        sigAttr += "\"" + sigTag.getSignature() + "\"";
        emit(sigAttr);
    }
    if (method.hasTag("AnnotationDefaultTag")) {
        String annotDefAttr = ".annotation_default ";
        AnnotationDefaultTag annotDefTag = (AnnotationDefaultTag) method.getTag("AnnotationDefaultTag");
        annotDefAttr += getElemAttr(annotDefTag.getDefaultVal());
        annotDefAttr += ".end .annotation_default";
        emit(annotDefAttr);
    }
    Iterator<Tag> vit = method.getTags().iterator();
    while (vit.hasNext()) {
        Tag t = (Tag) vit.next();
        if (t.getName().equals("VisibilityAnnotationTag")) {
            emit(getVisibilityAnnotationAttr((VisibilityAnnotationTag) t));
        }
        if (t.getName().equals("VisibilityParameterAnnotationTag")) {
            emit(getVisibilityParameterAnnotationAttr((VisibilityParameterAnnotationTag) t));
        }
    }
    if (method.isConcrete()) {
        if (!method.hasActiveBody())
            throw new RuntimeException("method: " + method.getName() + " has no active body!");
        else
            emitMethodBody(method);
    }
    // Emit epilogue
    emit(".end method");
    Iterator<Tag> it = method.getTags().iterator();
    while (it.hasNext()) {
        Tag tag = (Tag) it.next();
        if (tag instanceof Attribute)
            emit(".method_attribute " + tag.getName() + " \"" + new String(Base64.encode(tag.getValue())) + "\"");
    }
}
Also used : VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) Attribute(soot.tagkit.Attribute) InnerClassAttribute(soot.tagkit.InnerClassAttribute) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) SignatureTag(soot.tagkit.SignatureTag) Tag(soot.tagkit.Tag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag) SignatureTag(soot.tagkit.SignatureTag) AnnotationTag(soot.tagkit.AnnotationTag) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag) LongConstantValueTag(soot.tagkit.LongConstantValueTag) SourceFileTag(soot.tagkit.SourceFileTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag)

Example 7 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project robovm by robovm.

the class Annotations method getParameterAnnotations.

public static List<AnnotationTag>[] getParameterAnnotations(SootMethod method, Visibility visibility) {
    @SuppressWarnings("unchecked") ArrayList<AnnotationTag>[] result = new ArrayList[method.getParameterCount()];
    for (int i = 0; i < result.length; i++) {
        result[i] = new ArrayList<>();
    }
    for (Tag tag : method.getTags()) {
        if (tag instanceof VisibilityParameterAnnotationTag) {
            if (visibility == Visibility.Any || ((VisibilityParameterAnnotationTag) tag).getKind() == visibility.ordinal()) {
                ArrayList<VisibilityAnnotationTag> l = ((VisibilityParameterAnnotationTag) tag).getVisibilityAnnotations();
                if (l != null) {
                    int i = 0;
                    for (VisibilityAnnotationTag t : l) {
                        ArrayList<AnnotationTag> annotations = t.getAnnotations();
                        if (annotations != null) {
                            result[i].addAll(annotations);
                        }
                        i++;
                    }
                }
            }
        }
    }
    return result;
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ArrayList(java.util.ArrayList) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) Tag(soot.tagkit.Tag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 8 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project robovm by robovm.

the class Annotations method copyParameterAnnotations.

private static void copyParameterAnnotations(SootMethod fromMethod, SootMethod toMethod, int start, int end, int shift, int visibility) {
    List<AnnotationTag>[] fromAnnos = getParameterAnnotations(fromMethod, Visibility.values()[visibility]);
    List<AnnotationTag>[] toAnnos = getParameterAnnotations(toMethod, Visibility.values()[visibility]);
    for (int i = start; i < end; i++) {
        toAnnos[i + shift].addAll(fromAnnos[i]);
    }
    for (Iterator<Tag> it = toMethod.getTags().iterator(); it.hasNext(); ) {
        Tag tag = it.next();
        if (tag instanceof VisibilityParameterAnnotationTag) {
            if (((VisibilityParameterAnnotationTag) tag).getKind() == visibility) {
                it.remove();
            }
        }
    }
    VisibilityParameterAnnotationTag vpaTag = new VisibilityParameterAnnotationTag(toAnnos.length, visibility);
    for (List<AnnotationTag> annos : toAnnos) {
        VisibilityAnnotationTag vaTag = new VisibilityAnnotationTag(visibility);
        for (AnnotationTag anno : annos) {
            vaTag.addAnnotation(anno);
        }
        vpaTag.addVisibilityAnnotation(vaTag);
    }
    toMethod.addTag(vpaTag);
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) ArrayList(java.util.ArrayList) List(java.util.List) Tag(soot.tagkit.Tag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 9 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.

the class DexPrinter method buildVisibilityParameterAnnotationTag.

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ImmutableAnnotationElement(org.jf.dexlib2.immutable.ImmutableAnnotationElement) ArrayList(java.util.ArrayList) ImmutableAnnotation(org.jf.dexlib2.immutable.ImmutableAnnotation) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ImmutableNullEncodedValue(org.jf.dexlib2.immutable.value.ImmutableNullEncodedValue) ImmutableFieldEncodedValue(org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue) ImmutableByteEncodedValue(org.jf.dexlib2.immutable.value.ImmutableByteEncodedValue) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) ImmutableEncodedValue(org.jf.dexlib2.immutable.value.ImmutableEncodedValue) ImmutableAnnotationEncodedValue(org.jf.dexlib2.immutable.value.ImmutableAnnotationEncodedValue) ImmutableCharEncodedValue(org.jf.dexlib2.immutable.value.ImmutableCharEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) ImmutableFloatEncodedValue(org.jf.dexlib2.immutable.value.ImmutableFloatEncodedValue) ImmutableLongEncodedValue(org.jf.dexlib2.immutable.value.ImmutableLongEncodedValue) ImmutableShortEncodedValue(org.jf.dexlib2.immutable.value.ImmutableShortEncodedValue) ImmutableTypeEncodedValue(org.jf.dexlib2.immutable.value.ImmutableTypeEncodedValue) ImmutableDoubleEncodedValue(org.jf.dexlib2.immutable.value.ImmutableDoubleEncodedValue) ImmutableMethodEncodedValue(org.jf.dexlib2.immutable.value.ImmutableMethodEncodedValue) ImmutableArrayEncodedValue(org.jf.dexlib2.immutable.value.ImmutableArrayEncodedValue) ImmutableEnumEncodedValue(org.jf.dexlib2.immutable.value.ImmutableEnumEncodedValue) ImmutableIntEncodedValue(org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue) ImmutableBooleanEncodedValue(org.jf.dexlib2.immutable.value.ImmutableBooleanEncodedValue) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) ArrayList(java.util.ArrayList) List(java.util.List) AnnotationElem(soot.tagkit.AnnotationElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem)

Example 10 with VisibilityParameterAnnotationTag

use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.

the class MethodBuilder method visitEnd.

@Override
public void visitEnd() {
    super.visitEnd();
    if (visibleParamAnnotations != null) {
        VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(visibleParamAnnotations.length, AnnotationConstants.RUNTIME_VISIBLE);
        for (VisibilityAnnotationTag vat : visibleParamAnnotations) {
            tag.addVisibilityAnnotation(vat);
        }
        method.addTag(tag);
    }
    if (invisibleParamAnnotations != null) {
        VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(invisibleParamAnnotations.length, AnnotationConstants.RUNTIME_INVISIBLE);
        for (VisibilityAnnotationTag vat : invisibleParamAnnotations) {
            tag.addVisibilityAnnotation(vat);
        }
        method.addTag(tag);
    }
    if (method.isConcrete()) {
        method.setSource(new AsmMethodSource(maxLocals, instructions, localVariables, tryCatchBlocks));
    }
}
Also used : VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Aggregations

VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)11 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)11 AnnotationTag (soot.tagkit.AnnotationTag)9 Tag (soot.tagkit.Tag)8 ArrayList (java.util.ArrayList)7 AnnotationDefaultTag (soot.tagkit.AnnotationDefaultTag)5 EnclosingMethodTag (soot.tagkit.EnclosingMethodTag)5 InnerClassTag (soot.tagkit.InnerClassTag)5 SignatureTag (soot.tagkit.SignatureTag)5 SourceFileTag (soot.tagkit.SourceFileTag)4 List (java.util.List)2 ImmutableAnnotation (org.jf.dexlib2.immutable.ImmutableAnnotation)2 AnnotationAnnotationElem (soot.tagkit.AnnotationAnnotationElem)2 AnnotationElem (soot.tagkit.AnnotationElem)2 DoubleConstantValueTag (soot.tagkit.DoubleConstantValueTag)2 FloatConstantValueTag (soot.tagkit.FloatConstantValueTag)2 IntegerConstantValueTag (soot.tagkit.IntegerConstantValueTag)2 LongConstantValueTag (soot.tagkit.LongConstantValueTag)2 ParamNamesTag (soot.tagkit.ParamNamesTag)2 StringConstantValueTag (soot.tagkit.StringConstantValueTag)2