Search in sources :

Example 1 with Attribute

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

the class AbstractASMBackend method generateAttributes.

/**
 * Emits the bytecode for all attributes of a field
 * @param fv The FieldVisitor to emit the bytecode to
 * @param f The SootField the bytecode is to be emitted for
 */
protected void generateAttributes(FieldVisitor fv, SootField f) {
    for (Tag t : f.getTags()) {
        if (t instanceof Attribute) {
            org.objectweb.asm.Attribute a = createASMAttribute((Attribute) t);
            fv.visitAttribute(a);
        }
    }
}
Also used : Attribute(soot.tagkit.Attribute) ASMBackendUtils.createASMAttribute(soot.util.backend.ASMBackendUtils.createASMAttribute) InnerClassAttribute(soot.tagkit.InnerClassAttribute) Tag(soot.tagkit.Tag) SourceFileTag(soot.tagkit.SourceFileTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) OuterClassTag(soot.tagkit.OuterClassTag) SignatureTag(soot.tagkit.SignatureTag) AnnotationTag(soot.tagkit.AnnotationTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag)

Example 2 with Attribute

use of soot.tagkit.Attribute 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 3 with Attribute

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

the class ASMBackendUtils method createASMAttribute.

/**
 * Create an ASM attribute from an Soot attribute
 * @param attr Soot attribute
 * @return ASM attribute
 */
public static org.objectweb.asm.Attribute createASMAttribute(Attribute attr) {
    final Attribute a = attr;
    return new org.objectweb.asm.Attribute(attr.getName()) {

        @Override
        protected ByteVector write(final ClassWriter cw, final byte[] code, final int len, final int maxStack, final int maxLocals) {
            ByteVector result = new ByteVector();
            result.putByteArray(a.getValue(), 0, a.getValue().length);
            return result;
        }
    };
}
Also used : Attribute(soot.tagkit.Attribute) ClassWriter(org.objectweb.asm.ClassWriter) ByteVector(org.objectweb.asm.ByteVector)

Example 4 with Attribute

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

the class AbstractASMBackend method generateAttributes.

/**
 * Emits the bytecode for all attributes of a method
 * @param fv The MethodVisitor to emit the bytecode to
 * @param f The SootMethod the bytecode is to be emitted for
 */
protected void generateAttributes(MethodVisitor mv, SootMethod m) {
    for (Tag t : m.getTags()) {
        if (t instanceof Attribute) {
            org.objectweb.asm.Attribute a = createASMAttribute((Attribute) t);
            mv.visitAttribute(a);
        }
    }
}
Also used : Attribute(soot.tagkit.Attribute) ASMBackendUtils.createASMAttribute(soot.util.backend.ASMBackendUtils.createASMAttribute) InnerClassAttribute(soot.tagkit.InnerClassAttribute) Tag(soot.tagkit.Tag) SourceFileTag(soot.tagkit.SourceFileTag) AnnotationDefaultTag(soot.tagkit.AnnotationDefaultTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) InnerClassTag(soot.tagkit.InnerClassTag) OuterClassTag(soot.tagkit.OuterClassTag) SignatureTag(soot.tagkit.SignatureTag) AnnotationTag(soot.tagkit.AnnotationTag) EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag)

Aggregations

Attribute (soot.tagkit.Attribute)4 AnnotationDefaultTag (soot.tagkit.AnnotationDefaultTag)3 AnnotationTag (soot.tagkit.AnnotationTag)3 EnclosingMethodTag (soot.tagkit.EnclosingMethodTag)3 InnerClassAttribute (soot.tagkit.InnerClassAttribute)3 InnerClassTag (soot.tagkit.InnerClassTag)3 SignatureTag (soot.tagkit.SignatureTag)3 SourceFileTag (soot.tagkit.SourceFileTag)3 Tag (soot.tagkit.Tag)3 VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)3 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)3 OuterClassTag (soot.tagkit.OuterClassTag)2 ASMBackendUtils.createASMAttribute (soot.util.backend.ASMBackendUtils.createASMAttribute)2 ByteVector (org.objectweb.asm.ByteVector)1 ClassWriter (org.objectweb.asm.ClassWriter)1 DoubleConstantValueTag (soot.tagkit.DoubleConstantValueTag)1 FloatConstantValueTag (soot.tagkit.FloatConstantValueTag)1 IntegerConstantValueTag (soot.tagkit.IntegerConstantValueTag)1 LongConstantValueTag (soot.tagkit.LongConstantValueTag)1 StringConstantValueTag (soot.tagkit.StringConstantValueTag)1