Package soot

Class Scene

  • Direct Known Subclasses:
    ModuleScene

    public class Scene
    extends Object
    Manages the SootClasses of the application being analyzed.
    • Method Detail

      • v

        public static Scene v()
      • setMainClass

        public void setMainClass​(SootClass m)
      • getReservedNames

        public Set<String> getReservedNames()
        Returns a set of tokens which are reserved. Any field, class, method, or local variable with such a name will be quoted.
      • quotedNameOf

        public String quotedNameOf​(String s)
        If this name is in the set of reserved names, then return a quoted version of it. Else pass it through. If the name consists of multiple parts separated by dots, the individual names are checked as well.
      • unescapeName

        public static String unescapeName​(String s)
        This method is the inverse of quotedNameOf(). It takes a possible escaped class and reconstructs the original version of it.
        Parameters:
        s - The possibly escaped name
        Returns:
        The original, non-escaped name
      • hasMainClass

        public boolean hasMainClass()
      • getMainClass

        public SootClass getMainClass()
      • getMainMethod

        public SootMethod getMainMethod()
      • setSootClassPath

        public void setSootClassPath​(String p)
      • extendSootClassPath

        public void extendSootClassPath​(String newPathElement)
      • reset

        public void reset()
      • getSootClassPath

        public String getSootClassPath()
      • getAndroidAPIVersion

        public int getAndroidAPIVersion()
      • defaultClassPath

        public String defaultClassPath()
      • isApk

        public static boolean isApk​(File apk)
      • isJavaGEQ9

        public static boolean isJavaGEQ9​(String version)
        Checks if the version number indicates a Java version >= 9 in order to handle the new virtual filesystem jrt:/
        Parameters:
        version -
        Returns:
      • defaultJavaClassPath

        public static String defaultJavaClassPath()
        Returns the default class path used for this JVM.
        Returns:
        the default class path (or null if none could be found)
      • getState

        public int getState()
      • modifyHierarchy

        protected void modifyHierarchy()
      • addClass

        public void addClass​(SootClass c)
        Adds the given class to the Scene. This method marks the given class as a library class and invalidates the class hierarchy.
        Parameters:
        c - The class to add
      • addClassSilent

        protected void addClassSilent​(SootClass c)
        Adds the given class to the Scene. This method does not handle any dependencies such as invalidating the hierarchy. The class is neither marked as application class, nor library class.
        Parameters:
        c - The class to add
      • removeClass

        public void removeClass​(SootClass c)
      • containsClass

        public boolean containsClass​(String className)
      • containsType

        public boolean containsType​(String className)
      • signatureToClass

        public static String signatureToClass​(String sig)
      • signatureToSubsignature

        public static String signatureToSubsignature​(String sig)
      • containsField

        public boolean containsField​(String fieldSignature)
      • containsMethod

        public boolean containsMethod​(String methodSignature)
      • tryLoadClass

        public SootClass tryLoadClass​(String className,
                                      int desiredLevel)
        Attempts to load the given class and all of the required support classes. Returns the original class if it was loaded, or null otherwise.
      • loadClassAndSupport

        public SootClass loadClassAndSupport​(String className)
        Loads the given class and all of the required support classes. Returns the first class.
      • loadClass

        public SootClass loadClass​(String className,
                                   int desiredLevel)
      • getType

        public Type getType​(String arg)
        Returns the RefType with the given class name or primitive type.
        Throws:
        RuntimeException - if the Type for this name cannot be found. Use getRefTypeUnsafe(String) to check if type is an registered RefType.
      • getTypeUnsafe

        public Type getTypeUnsafe​(String arg)
        Returns a Type object representing the given type string. It will first attempt to resolve the type as a reference type that currently exists in the Scene. If this fails it will attempt to resolve the type as a java primitive type. Lastly, if phantom refs are allowed it will construct a phantom class for the given type and return a reference type based on the phantom class. Otherwise, this method will return null. Note, if the resolved base type is not null and the string representation of the type is an array, the returned type will be an ArrayType with the base type resolved as described above.
        Parameters:
        arg - A string description of the type
        Returns:
        The Type if it can be resolved and null otherwise
      • getTypeUnsafe

        public Type getTypeUnsafe​(String arg,
                                  boolean phantomNonExist)
        Returns a Type object representing the given type string. It will first attempt to resolve the type as a reference type that currently exists in the Scene. If this fails it will attempt to resolve the type as a java primitive type. Lastly, if phantom refs are allowed and phantomNonExist=true it will construct a phantom class for the given type and return a reference type based on the phantom class. Otherwise, this method will return null. Note, if the resolved base type is not null and the string representation of the type is an array, the returned type will be an ArrayType with the base type resolved as described above.
        Parameters:
        arg - A string description of the type
        phantomNonExist - Indicates that a phantom class should be created for the given type string and a Type object should be created based on the phantom class if a class matching the type name does not exists in the scene and phantom refs are allowed
        Returns:
        The Type if it can be resolved and null otherwise
      • getRefTypeUnsafe

        public RefType getRefTypeUnsafe​(String className)
        Returns the RefType with the given className. Returns null if no type with the given name can be found.
      • getBaseExceptionType

        public RefType getBaseExceptionType()
        Returns the base class of exceptions.
        Returns:
        RefType with the given className
      • getSootClassUnsafe

        public SootClass getSootClassUnsafe​(String className)
        Returns the SootClass with the given className. If no class with the given name exists, null is returned unless phantom refs are allowed. In this case, a new phantom class is created. The difference with the getSootClass() version is that this version doesn't throw a RuntimeException if the requested class doesn't exist in the Scene. Instead it returns null.
        Parameters:
        className - The name of the class to get
        Returns:
        The class if it exists, otherwise null
      • getSootClassUnsafe

        public SootClass getSootClassUnsafe​(String className,
                                            boolean phantomNonExist)
        Returns the SootClass with the given className. If no class with the given name exists, null is returned unless phantomNonExist=true and phantom refs are allowed. In this case, a new phantom class is created and returned. The difference with the getSootClass() version is that this version doesn't throw a RuntimeException if the requested class doesn't exist in the Scene. Instead it returns null or a phantom class, depending on the flag.
        Parameters:
        className - The name of the class to get
        phantomNonExist - Indicates that a phantom class should be created if a class with the given name does not exist and phantom refs are allowed
        Returns:
        The class if it exists, otherwise null
      • getSootClass

        public SootClass getSootClass​(String className)
        Returns the SootClass with the given className.
        Parameters:
        className - The name of the class to get; throws RuntimeException if this class does not exist.
      • getClasses

        public Chain<SootClass> getClasses()
        Returns an backed chain of the classes in this manager.
      • getApplicationClasses

        public Chain<SootClass> getApplicationClasses()
        Returns a chain of the application classes in this scene. These classes are the ones which can be freely analysed & modified.
      • getLibraryClasses

        public Chain<SootClass> getLibraryClasses()
        Returns a chain of the library classes in this scene. These classes can be analysed but not modified.
      • getPhantomClasses

        public Chain<SootClass> getPhantomClasses()
        Returns a chain of the phantom classes in this scene. These classes are referred to by other classes, but cannot be loaded.
      • getSideEffectAnalysis

        public SideEffectAnalysis getSideEffectAnalysis()
        Retrieves the active side-effect analysis
      • setSideEffectAnalysis

        public void setSideEffectAnalysis​(SideEffectAnalysis sea)
        Sets the active side-effect analysis
      • hasSideEffectAnalysis

        public boolean hasSideEffectAnalysis()
      • releaseSideEffectAnalysis

        public void releaseSideEffectAnalysis()
      • getPointsToAnalysis

        public PointsToAnalysis getPointsToAnalysis()
        Retrieves the active pointer analysis
      • setPointsToAnalysis

        public void setPointsToAnalysis​(PointsToAnalysis pa)
        Sets the active pointer analysis
      • hasPointsToAnalysis

        public boolean hasPointsToAnalysis()
      • releasePointsToAnalysis

        public void releasePointsToAnalysis()
      • getClientAccessibilityOracle

        public ClientAccessibilityOracle getClientAccessibilityOracle()
        Retrieves the active client accessibility oracle
      • hasClientAccessibilityOracle

        public boolean hasClientAccessibilityOracle()
      • releaseClientAccessibilityOracle

        public void releaseClientAccessibilityOracle()
      • getOrMakeFastHierarchy

        public FastHierarchy getOrMakeFastHierarchy()
        Makes a new fast hierarchy is none is active, and returns the active fast hierarchy.
      • getFastHierarchy

        public FastHierarchy getFastHierarchy()
        Retrieves the active fast hierarchy
      • setFastHierarchy

        public void setFastHierarchy​(FastHierarchy hierarchy)
        Sets the active hierarchy
      • hasFastHierarchy

        public boolean hasFastHierarchy()
      • releaseFastHierarchy

        public void releaseFastHierarchy()
      • getActiveHierarchy

        public Hierarchy getActiveHierarchy()
        Retrieves the active hierarchy
      • setActiveHierarchy

        public void setActiveHierarchy​(Hierarchy hierarchy)
        Sets the active hierarchy
      • hasActiveHierarchy

        public boolean hasActiveHierarchy()
      • releaseActiveHierarchy

        public void releaseActiveHierarchy()
      • hasCustomEntryPoints

        public boolean hasCustomEntryPoints()
      • getEntryPoints

        public List<SootMethod> getEntryPoints()
        Get the set of entry points that are used to build the call graph.
      • setEntryPoints

        public void setEntryPoints​(List<SootMethod> entryPoints)
        Change the set of entry point methods used to build the call graph.
      • getCallGraph

        public CallGraph getCallGraph()
      • setCallGraph

        public void setCallGraph​(CallGraph cg)
      • hasCallGraph

        public boolean hasCallGraph()
      • releaseCallGraph

        public void releaseCallGraph()
      • setReachableMethods

        public void setReachableMethods​(ReachableMethods rm)
      • hasReachableMethods

        public boolean hasReachableMethods()
      • releaseReachableMethods

        public void releaseReachableMethods()
      • getPhantomRefs

        public boolean getPhantomRefs()
      • setPhantomRefs

        public void setPhantomRefs​(boolean value)
      • allowsPhantomRefs

        public boolean allowsPhantomRefs()
      • getDefaultThrowAnalysis

        public ThrowAnalysis getDefaultThrowAnalysis()
        Returns the ThrowAnalysis to be used by default when constructing CFGs which include exceptional control flow.
        Returns:
        the default ThrowAnalysis
      • setDefaultThrowAnalysis

        public void setDefaultThrowAnalysis​(ThrowAnalysis ta)
        Sets the ThrowAnalysis to be used by default when constructing CFGs which include exceptional control flow.
        Parameters:
        ta - the default ThrowAnalysis.
      • addBasicClass

        public void addBasicClass​(String name)
      • addBasicClass

        public void addBasicClass​(String name,
                                  int level)
      • loadBasicClasses

        public void loadBasicClasses()
        Load just the set of basic classes soot needs, ignoring those specified on the command-line. You don't need to use both this and loadNecessaryClasses(), though it will only waste time.
      • getBasicClasses

        public Set<String> getBasicClasses()
      • isBasicClass

        public boolean isBasicClass​(String className)
      • addReflectionTraceClasses

        protected void addReflectionTraceClasses()
      • loadNecessaryClass

        protected void loadNecessaryClass​(String name)
      • loadNecessaryClasses

        public void loadNecessaryClasses()
        Load the set of classes that soot needs, including those specified on the command-line. This is the standard way of initialising the list of classes soot should use.
      • loadDynamicClasses

        public void loadDynamicClasses()
      • prepareClasses

        protected void prepareClasses()
        Generate classes to process, adding or removing package marked by command line options.
      • isExcluded

        public boolean isExcluded​(SootClass sc)
      • isExcluded

        public boolean isExcluded​(String className)
      • isIncluded

        public boolean isIncluded​(SootClass sc)
      • isIncluded

        public boolean isIncluded​(String className)
      • setPkgList

        public void setPkgList​(List<String> list)
      • makeMethodRef

        public SootMethodRef makeMethodRef​(SootClass declaringClass,
                                           String name,
                                           List<Type> parameterTypes,
                                           Type returnType,
                                           boolean isStatic)
        Create an unresolved reference to a method.
      • makeMethodRef

        public SootMethodRef makeMethodRef​(SootClass declaringClass,
                                           String subsig,
                                           boolean isStatic)
        Create an unresolved reference to a method.
      • makeConstructorRef

        public SootMethodRef makeConstructorRef​(SootClass declaringClass,
                                                List<Type> parameterTypes)
        Create an unresolved reference to a constructor.
      • makeFieldRef

        public SootFieldRef makeFieldRef​(SootClass declaringClass,
                                         String name,
                                         Type type,
                                         boolean isStatic)
        Create an unresolved reference to a field.
      • getClasses

        public List<SootClass> getClasses​(int desiredLevel)
        Returns the list of SootClasses that have been resolved at least to the level specified.
      • doneResolving

        public boolean doneResolving()
      • setDoneResolving

        public void setDoneResolving()
      • setResolving

        public void setResolving​(boolean value)
      • setMainClassFromOptions

        public void setMainClassFromOptions()
      • isIncrementalBuild

        public boolean isIncrementalBuild()
        This method returns true when in incremental build mode. Other classes can query this flag and change the way in which they use the Scene, depending on the flag's value.
      • initiateIncrementalBuild

        public void initiateIncrementalBuild()
      • incrementalBuildFinished

        public void incrementalBuildFinished()
      • forceResolve

        public SootClass forceResolve​(String className,
                                      int level)
        Forces Soot to resolve the class with the given name to the given level, even if resolving has actually already finished.
      • makeSootClass

        public SootClass makeSootClass​(String name,
                                       int modifiers)
      • getOrAddRefType

        public RefType getOrAddRefType​(String refTypeName)
      • internalMakeCallGraph

        public CallGraph internalMakeCallGraph()
        SOOT USERS: DO NOT CALL THIS METHOD!

        This method is a Soot-internal factory method for generating callgraph objects. It creates non-initialized object that must then be initialized by a callgraph algorithm

        Returns:
        A new callgraph empty object
      • resetSootClassPathCache

        public void resetSootClassPathCache()
        Resets the sootClassPath to null. This method allows for subsequent calls to loadNecessaryClasses() to recompute and load the classes using updated configurations if provided.
      • registerSootClassAddedListener

        public void registerSootClassAddedListener​(ISootClassAddedListener listener)
        Registers a new listener that is invoked when a new SootClass is added to the scene
        Parameters:
        listener - The listener that shall be invoked when a new SootClass is added to the scene
      • unregisterSootClassAddedListener

        public void unregisterSootClassAddedListener​(ISootClassAddedListener listener)
        Unrgisters a listener that processes new SootClases being added to the scene
        Parameters:
        listener - The listener to remove