Package soot

Class AbstractASMBackend

  • Direct Known Subclasses:
    BafASMBackend

    public abstract class AbstractASMBackend
    extends Object
    Abstract super-class for ASM-based back-ends. Generates byte-code for everything except the method bodies, as they are dependent on the IR.
    Author:
    Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer
    • Field Detail

      • javaVersion

        protected final int javaVersion
      • cv

        protected org.objectweb.asm.ClassVisitor cv
    • Constructor Detail

      • AbstractASMBackend

        public AbstractASMBackend​(SootClass sc,
                                  int javaVersion)
        Creates a new ASM backend
        Parameters:
        sc - The SootClass that is to be converted into bytecode
        javaVersion - A particular Java version enforced by the user, may be 0 for automatic detection, must not be lower than necessary for all features used
    • Method Detail

      • getBafBody

        protected BafBody getBafBody​(SootMethod method)
        Gets the baf body for the given SootMethod. This method will first check whether the method already has a baf body. If not, it will query the local cache. If this fails as well, it will construct a new baf body.
        Parameters:
        method - The method for which to obtain a baf body
        Returns:
        The baf body for the given method
      • getMinJavaVersion

        protected int getMinJavaVersion​(SootMethod sm)
        Determines the minimum Java version required for the bytecode of the given SootMethod Subclasses should override this method to suit their needs, otherwise Java 1.7 is assumed for compatibility with invokeDynamic
        Parameters:
        sm - The SootMethod the minimum Java version is to be determined for
        Returns:
        The minimum Java version required for the given SootMethod
      • generateClassFile

        public void generateClassFile​(OutputStream os)
        Outputs the bytecode generated as a class file
        Parameters:
        os - The OutputStream the class file is written to
      • generateTextualRepresentation

        public void generateTextualRepresentation​(PrintWriter pw)
        Outputs the bytecode generated as a textual representation
        Parameters:
        pw - The PrintWriter the textual representation is written to
      • generateByteCode

        protected void generateByteCode()
        Emits the bytecode for the complete class
      • generateMethods

        protected void generateMethods()
        Emits the bytecode for all methods of the class
      • generateFields

        protected void generateFields()
        Emits the bytecode for all fields of the class
      • generateInnerClassReferences

        protected void generateInnerClassReferences()
        Emits the bytecode for all references to inner classes if present
      • writeInnerClassTags

        protected void writeInnerClassTags​(List<InnerClassTag> sortedTags)
        Write out the given sorted list of inner class tags
        Parameters:
        sortedTags - The sorted list of inner class tags
      • generateAttributes

        protected void generateAttributes()
        Emits the bytecode for all attributes of the class
      • generateAttributes

        protected void generateAttributes​(org.objectweb.asm.FieldVisitor fv,
                                          SootField f)
        Emits the bytecode for all attributes of a field
        Parameters:
        fv - The FieldVisitor to emit the bytecode to
        f - The SootField the bytecode is to be emitted for
      • generateAttributes

        protected void generateAttributes​(org.objectweb.asm.MethodVisitor mv,
                                          SootMethod m)
        Emits the bytecode for all attributes of a method
        Parameters:
        mv - The MethodVisitor to emit the bytecode to
        m - The SootMethod the bytecode is to be emitted for
      • generateAnnotations

        protected void generateAnnotations​(Object visitor,
                                           Host host)
        Emits the bytecode for all annotations of a class, field or method
        Parameters:
        visitor - A ClassVisitor, FieldVisitor or MethodVisitor to emit the bytecode to
        host - A Host (SootClass, SootField or SootMethod) the bytecode is to be emitted for, has to match the visitor
      • generateAnnotationElems

        protected void generateAnnotationElems​(org.objectweb.asm.AnnotationVisitor av,
                                               Collection<AnnotationElem> elements,
                                               boolean addName)
        Emits the bytecode for the values of an annotation
        Parameters:
        av - The AnnotationVisitor to emit the bytecode to
        elements - A collection of AnnatiotionElem that are the values of the annotation
        addName - True, if the name of the annotation has to be added, false otherwise (should be false only in recursive calls!)
      • generateOuterClassReference

        protected void generateOuterClassReference()
        Emits the bytecode for a reference to an outer class if necessary
      • generateClassHeader

        protected void generateClassHeader()
        Emits the bytecode for the class itself, including its signature
      • getModifiers

        protected static int getModifiers​(int modVal,
                                          Host host)
        Utility method to get the access modifiers of a Host
        Parameters:
        modVal - The bitset representation of the Host's modifiers
        host - The Host (SootClass, SootField or SootMethod) the modifiers are to be retrieved from
        Returns:
        A bitset representation of the Host's modifiers in ASM's internal representation
      • generateMethodBody

        protected abstract void generateMethodBody​(org.objectweb.asm.MethodVisitor mv,
                                                   SootMethod method)
        Emits the bytecode for the body of a single method Has to be implemented by subclasses to suit their needs
        Parameters:
        mv - The MethodVisitor to emit the bytecode to
        method - The SootMethod the bytecode is to be emitted for