Package soot

Class SootClass

  • All Implemented Interfaces:
    Host
    Direct Known Subclasses:
    SootModuleInfo

    public class SootClass
    extends AbstractHost
    Soot representation of a Java class. They are usually created by a Scene, but can also be constructed manually through the given constructors.
    • Constructor Detail

      • SootClass

        public SootClass​(String name,
                         int modifiers)
        Constructs an empty SootClass with the given name and modifiers.
      • SootClass

        public SootClass​(String name,
                         String moduleName)
      • SootClass

        public SootClass​(String name)
      • SootClass

        public SootClass​(String name,
                         int modifiers,
                         String moduleName)
    • Method Detail

      • initializeRefType

        protected void initializeRefType​(String name,
                                         String moduleName)
        Makes sure that there is a RefType pointing to this SootClass. Client code that provides its own SootClass implementation can override and modify this behavior.
        Parameters:
        name - The name of the new class
      • levelToString

        protected static String levelToString​(int level)
      • checkLevel

        public void checkLevel​(int level)
        Checks if the class has at least the resolving level specified. This check does nothing is the class resolution process is not completed.
        Parameters:
        level - the resolution level, one of DANGLING, HIERARCHY, SIGNATURES, and BODIES
        Throws:
        RuntimeException - if the resolution is at an insufficient level
      • checkLevelIgnoreResolving

        public void checkLevelIgnoreResolving​(int level)
        Checks if the class has at least the resolving level specified. This check ignores the resolution completeness.
        Parameters:
        level - the resolution level, one of DANGLING, HIERARCHY, SIGNATURES, and BODIES
        Throws:
        RuntimeException - if the resolution is at an insufficient level
      • resolvingLevel

        public int resolvingLevel()
      • setResolvingLevel

        public void setResolvingLevel​(int newLevel)
      • isInScene

        public boolean isInScene()
      • setInScene

        public void setInScene​(boolean isInScene)
        Tells this class if it is being managed by a Scene.
      • getFieldCount

        public int getFieldCount()
        Returns the number of fields in this class.
      • getFields

        public Chain<SootField> getFields()
        Returns a backed Chain of fields.
      • addField

        public void addField​(SootField f)
        Adds the given field to this class.
      • removeField

        public void removeField​(SootField f)
        Removes the given field from this class.
      • getField

        public SootField getField​(String name,
                                  Type type)
        Returns the field of this class with the given name and type. If the field cannot be found, an exception is thrown.
      • getFieldUnsafe

        public SootField getFieldUnsafe​(String name,
                                        Type type)
        Returns the field of this class with the given name and type. If the field cannot be found, null is returned.
      • getFieldByName

        public SootField getFieldByName​(String name)
        Returns the field of this class with the given name. Throws a RuntimeException if there is more than one field with the given name or if no such field exists at all.
      • getFieldByNameUnsafe

        public SootField getFieldByNameUnsafe​(String name)
        Returns the field of this class with the given name. Throws a RuntimeException if there is more than one field with the given name. Returns null if no field with the given name exists.
      • getField

        public SootField getField​(String subsignature)
        Returns the field of this class with the given subsignature. If such a field does not exist, an exception is thrown.
      • getFieldUnsafe

        public SootField getFieldUnsafe​(String subsignature)
        Returns the field of this class with the given subsignature. If such a field does not exist, null is returned.
      • declaresField

        public boolean declaresField​(String subsignature)
        Does this class declare a field with the given subsignature?
      • getMethod

        public SootMethod getMethod​(NumberedString subsignature)
        Returns the method of this class with the given subsignature. If no method with the given subsignature can be found, an exception is thrown.
      • getMethodUnsafe

        public SootMethod getMethodUnsafe​(NumberedString subsignature)
        Returns the method of this class with the given subsignature. If no method with the given subsignature can be found, null is returned.
      • declaresMethod

        public boolean declaresMethod​(NumberedString subsignature)
        Does this class declare a method with the given subsignature?
      • declaresMethod

        public boolean declaresMethod​(String subsignature)
        Does this class declare a method with the given subsignature?
      • declaresFieldByName

        public boolean declaresFieldByName​(String name)
        Does this class declare a field with the given name?
      • declaresField

        public boolean declaresField​(String name,
                                     Type type)
        Does this class declare a field with the given name and type.
      • getMethodCount

        public int getMethodCount()
        Returns the number of methods in this class.
      • methodIterator

        public Iterator<SootMethod> methodIterator()
        Returns an iterator over the methods in this class.
      • getMethod

        public SootMethod getMethod​(String name,
                                    List<Type> parameterTypes,
                                    Type returnType)
        Attempts to retrieve the method with the given name, parameters and return type. If no matching method can be found, an exception is thrown.
      • getMethodUnsafe

        public SootMethod getMethodUnsafe​(String name,
                                          List<Type> parameterTypes,
                                          Type returnType)
        Attempts to retrieve the method with the given name, parameters and return type. If no matching method can be found, null is returned.
      • getMethod

        public SootMethod getMethod​(String name,
                                    List<Type> parameterTypes)
        Attempts to retrieve the method with the given name and parameters. This method may throw an AmbiguousMethodException if there is more than one method with the given name and parameter.
      • getMethodByNameUnsafe

        public SootMethod getMethodByNameUnsafe​(String name)
        Attempts to retrieve the method with the given name. This method may throw an AmbiguousMethodException if there are more than one method with the given name. If no method with the given is found, null is returned.
      • getMethodByName

        public SootMethod getMethodByName​(String name)
        Attempts to retrieve the method with the given name. This method may throw an AmbiguousMethodException if there are more than one method with the given name. If no method with the given is found, an exception is thrown as well.
      • declaresMethod

        public boolean declaresMethod​(String name,
                                      List<Type> parameterTypes)
        Does this class declare a method with the given name and parameter types?
      • declaresMethod

        public boolean declaresMethod​(String name,
                                      List<Type> parameterTypes,
                                      Type returnType)
        Does this class declare a method with the given name, parameter types, and return type?
      • declaresMethodByName

        public boolean declaresMethodByName​(String name)
        Does this class declare a method with the given name?
      • addMethod

        public void addMethod​(SootMethod m)
        Adds the given method to this class.
      • removeMethod

        public void removeMethod​(SootMethod m)
        Removes the given method from this class.
      • getModifiers

        public int getModifiers()
        Returns the modifiers of this class.
      • setModifiers

        public void setModifiers​(int modifiers)
        Sets the modifiers for this class.
      • getInterfaceCount

        public int getInterfaceCount()
        Returns the number of interfaces being directly implemented by this class. Note that direct implementation corresponds to an "implements" keyword in the Java class file and that this class may still be implementing additional interfaces in the usual sense by being a subclass of a class which directly implements some interfaces.
      • getInterfaces

        public Chain<SootClass> getInterfaces()
        Returns a backed Chain of the interfaces that are directly implemented by this class. (see getInterfaceCount())
      • implementsInterface

        public boolean implementsInterface​(String name)
        Does this class directly implement the given interface? (see getInterfaceCount())
      • addInterface

        public void addInterface​(SootClass interfaceClass)
        Add the given class to the list of interfaces which are directly implemented by this class.
      • removeInterface

        public void removeInterface​(SootClass interfaceClass)
        Removes the given class from the list of interfaces which are directly implemented by this class.
      • hasSuperclass

        public boolean hasSuperclass()
        WARNING: interfaces are subclasses of the java.lang.Object class! Does this class have a superclass? False implies that this is the java.lang.Object class. Note that interfaces are subclasses of the java.lang.Object class.
      • getSuperclass

        public SootClass getSuperclass()
        WARNING: interfaces are subclasses of the java.lang.Object class! Returns the superclass of this class. (see hasSuperclass())
      • getSuperclassUnsafe

        public SootClass getSuperclassUnsafe()
        This method returns the superclass, or null if no superclass has been specified for this class. WARNING: interfaces are subclasses of the java.lang.Object class! Returns the superclass of this class. (see hasSuperclass())
      • setSuperclass

        public void setSuperclass​(SootClass c)
        Sets the superclass of this class. Note that passing a null will cause the class to have no superclass.
      • hasOuterClass

        public boolean hasOuterClass()
      • getOuterClass

        public SootClass getOuterClass()
      • getOuterClassUnsafe

        public SootClass getOuterClassUnsafe()
        This method returns the outer class, or null if no outer class has been specified for this class.
      • setOuterClass

        public void setOuterClass​(SootClass c)
      • isInnerClass

        public boolean isInnerClass()
      • getName

        public String getName()
        Returns the name of this class.
      • getJavaStyleName

        public String getJavaStyleName()
      • getShortJavaStyleName

        public String getShortJavaStyleName()
      • getShortName

        public String getShortName()
      • getPackageName

        public String getPackageName()
        Returns the package name of this class.
      • getJavaPackageName

        public String getJavaPackageName()
      • setName

        public void setName​(String name)
        Sets the name of this class.
      • isInterface

        public boolean isInterface()
        Convenience method; returns true if this class is an interface.
      • isEnum

        public boolean isEnum()
        Convenience method; returns true if this class is an enumeration.
      • isSynchronized

        public boolean isSynchronized()
        Convenience method; returns true if this class is synchronized.
      • isConcrete

        public boolean isConcrete()
        Returns true if this class is not an interface and not abstract.
      • isPublic

        public boolean isPublic()
        Convenience method; returns true if this class is public.
      • containsBafBody

        public boolean containsBafBody()
        Returns true if some method in this class has an active Baf body.
      • setRefType

        public void setRefType​(RefType refType)
      • hasRefType

        public boolean hasRefType()
      • getType

        public RefType getType()
        Returns the RefType corresponding to this class.
      • toString

        public String toString()
        Returns the name of this class.
        Overrides:
        toString in class Object
      • renameFieldsAndMethods

        public void renameFieldsAndMethods​(boolean privateOnly)
        Renames private fields and methods with numeric names.
      • isApplicationClass

        public boolean isApplicationClass()
        Convenience method returning true if this class is an application class.
        See Also:
        Scene.getApplicationClasses()
      • setApplicationClass

        public void setApplicationClass()
        Makes this class an application class.
      • isLibraryClass

        public boolean isLibraryClass()
        Convenience method returning true if this class is a library class.
        See Also:
        Scene.getLibraryClasses()
      • setLibraryClass

        public void setLibraryClass()
        Makes this class a library class.
      • isJavaLibraryClass

        public boolean isJavaLibraryClass()
        Sometimes we need to know which class is a JDK class. There is no simple way to distinguish a user class and a JDK class, here we use the package prefix as the heuristic.
      • isPhantomClass

        public boolean isPhantomClass()
        Convenience method returning true if this class is a phantom class.
        See Also:
        Scene.getPhantomClasses()
      • setPhantomClass

        public void setPhantomClass()
        Makes this class a phantom class.
      • isPhantom

        public boolean isPhantom()
        Convenience method returning true if this class is phantom.
      • isPrivate

        public boolean isPrivate()
        Convenience method returning true if this class is private.
      • isProtected

        public boolean isProtected()
        Convenience method returning true if this class is protected.
      • isAbstract

        public boolean isAbstract()
        Convenience method returning true if this class is abstract.
      • isFinal

        public boolean isFinal()
        Convenience method returning true if this class is final.
      • isStatic

        public boolean isStatic()
        Convenience method returning true if this class is static.
      • rename

        public void rename​(String newName)
      • validate

        public void validate()
        Validates this SootClass for logical errors. Note that this does not validate the method bodies, only the class structure.
      • validate

        public void validate​(List<ValidationException> exceptionList)
        Validates this SootClass for logical errors. Note that this does not validate the method bodies, only the class structure. All found errors are saved into the given list.
      • getFilePath

        public String getFilePath()
      • setModuleInformation

        public void setModuleInformation​(SootModuleInfo moduleInformation)
      • isExportedByModule

        public boolean isExportedByModule()
        Checks if this class is exported by it's module
        Returns:
        true if the class is public exported
      • isExportedByModule

        public boolean isExportedByModule​(String toModule)
        Checks if this class is exported by it's module
        Returns:
        true if the class is public exported
      • isOpenedByModule

        public boolean isOpenedByModule()
      • getMethodsByNameAndParamCount

        public Collection<SootMethod> getMethodsByNameAndParamCount​(String name,
                                                                    int paramCount)
        Returns all methods with exactly the number of parameters specified.
        Parameters:
        name - the name of the method
        paramCount - the parameter count
        Returns:
        the methods