Class BaseEntryPointCreator

java.lang.Object
soot.jimple.infoflow.entryPointCreators.BaseEntryPointCreator
All Implemented Interfaces:
IEntryPointCreator
Direct Known Subclasses:
DefaultEntryPointCreator, SequentialEntryPointCreator

public abstract class BaseEntryPointCreator extends Object implements IEntryPointCreator
Common base class for all entry point creators. Implementors must override the createDummyMainInternal method to provide their entry point implementation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected soot.Body
     
    protected int
     
    protected String
    Default name of the class containing the dummy main method
    protected String
    Default name of the dummy main method
    protected soot.LocalGenerator
     
    protected soot.Value
     
    protected Map<soot.SootClass,soot.Local>
     
    protected final org.slf4j.Logger
     
    protected soot.SootMethod
     
    protected boolean
     
    protected boolean
     
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    acceptClass(soot.SootClass clazz)
    Determines whether a class is accepted for generating a constructor.
    protected soot.jimple.Stmt
    buildMethodCall(soot.SootMethod methodToCall, soot.Local classLocal)
    Builds a new invocation statement that invokes the given method
    protected soot.jimple.Stmt
    buildMethodCall(soot.SootMethod methodToCall, soot.Local classLocal, Set<soot.SootClass> parentClasses)
    Builds a new invocation statement that invokes the given method
    protected void
    Creates additional fields in the entry point class that are required by the dummy main method
    protected void
    Creates additional methods in the entry point class that are required by the dummy main method
    soot.SootMethod
    Generates a dummy main method that calls all methods in the given list
    protected abstract soot.SootMethod
    Implementors need to overwrite this method for providing the actual dummy main method
    protected void
    Creates a new, empty main method containing the given body
    protected void
    createIfStmt(soot.Unit target)
    Creates an opaque predicate that jumps to the given target
    protected void
    Eliminates all loops of length 0 (if a goto )
    protected soot.SootMethod
    findMethod(soot.SootClass currentClass, String subsignature)
    Finds a method with the given signature in the given class or one of its super classes
    protected soot.Local
    generateClassConstructor(soot.SootClass createdClass)
    Generates code which creates a new instance of the given class.
    protected soot.Local
    generateClassConstructor(soot.SootClass createdClass, Set<soot.SootClass> parentClasses)
    Generates code which creates a new instance of the given class.
    protected soot.Local
    generateClassConstructor(soot.SootClass createdClass, Set<soot.SootClass> constructionStack, Set<soot.SootClass> parentClasses, Set<soot.Local> tempLocals)
    Generates code which creates a new instance of the given class.
    Set<soot.SootClass>
    Returns a copy of all classes that could not be instantiated properly
    Set<soot.SootMethod>
    Returns all methods from from methodsToCall, where no call was possible
    soot.SootMethod
    Gets the last dummy main method that was generated by this creator
    protected String
    Gets a field name that is not already in use by some field
    protected soot.SootClass
    Gets the class that contains the dummy main method.
    boolean
    Gets whether the dummy main method shall be overwritten if it already exists.
    boolean
    Gets whether shallow mode shall be used.
    protected soot.Value
    getSimpleDefaultValue(soot.Type t)
     
    protected soot.Value
    getValueForType(soot.Type tp, Set<soot.SootClass> constructionStack, Set<soot.SootClass> parentClasses)
    Creates a value of the given type to be used as a substitution in method invocations or fields
    protected soot.Value
    getValueForType(soot.Type tp, Set<soot.SootClass> constructionStack, Set<soot.SootClass> parentClasses, Set<soot.Local> generatedLocals, boolean ignoreExcludes)
    Creates a value of the given type to be used as a substitution in method invocations or fields
    boolean
    Gets whether a warning shall be written to the log when a constructor call cannot be generated because the analysis ran into a loop when trying to generate parameter values.
    protected boolean
    isCompatible(soot.SootClass actual, soot.SootClass expected)
    Checks whether an object of type "actual" can be inserted where an object of type "expected" is required.
    protected static boolean
    isSimpleType(soot.Type t)
     
    protected void
    Resets the internal state to make sure that the entry point creator is re-usable.
    void
    setAllowNonPublicConstructors(boolean allowNonPublicConstructors)
    Sets whether the entry point creator may use private or protected constructors in order to generate a class instance in the dummyMain method.
    void
    setAllowSelfReferences(boolean value)
    Sets whether a call to a method A.foo() may receive an instance of A as a parameter.
    void
    setDummyClassName(String dummyClassName)
    Sets the name that shall be used for the new class containing the dummy main method
    void
    setDummyMethodName(String dummyMethodName)
    Sets the name that shall be used for the new dummy main method
    void
    setIgnoreSystemClassParams(boolean ignoreSystemClassParams)
    Sets whether the entry point creator shall always pass "null" if a method expects an object of a system class.
    void
    setOverwriteDummyMainMethod(boolean overwriteDummyMainValue)
    Sets whether the dummy main method shall be overwritten if it already exists.
    void
    setShallowMode(boolean shallowMode)
    Sets whether shallow mode shall be used.
    void
    with this option enabled the EntryPointCreator tries to find suitable subclasses of abstract classes and implementers of interfaces
    void
    set classes that are allowed to substitute (otherwise constructor loops are very likely)
    void
    setWarnOnConstructorLoop(boolean warnOnConstructorLoop)
    Sets whether a warning shall be written to the log when a constructor call cannot be generated because the analysis ran into a loop when trying to generate parameter values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface soot.jimple.infoflow.entryPointCreators.IEntryPointCreator

    getAdditionalFields, getAdditionalMethods, getRequiredClasses
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
    • localVarsForClasses

      protected Map<soot.SootClass,soot.Local> localVarsForClasses
    • dummyClassName

      protected String dummyClassName
      Default name of the class containing the dummy main method
    • dummyMethodName

      protected String dummyMethodName
      Default name of the dummy main method
    • shallowMode

      protected boolean shallowMode
    • overwriteDummyMainMethod

      protected boolean overwriteDummyMainMethod
    • warnOnConstructorLoop

      protected boolean warnOnConstructorLoop
    • intCounter

      protected soot.Value intCounter
    • conditionCounter

      protected int conditionCounter
    • mainMethod

      protected soot.SootMethod mainMethod
    • body

      protected soot.Body body
    • generator

      protected soot.LocalGenerator generator
  • Constructor Details

    • BaseEntryPointCreator

      public BaseEntryPointCreator()
  • Method Details

    • getFailedClasses

      public Set<soot.SootClass> getFailedClasses()
      Returns a copy of all classes that could not be instantiated properly
      Returns:
      The classes where the constructor could not be generated
    • getFailedMethods

      public Set<soot.SootMethod> getFailedMethods()
      Returns all methods from from methodsToCall, where no call was possible
      Returns:
      A Set of methods that were not called in the main method
    • setSubstituteCallParams

      public void setSubstituteCallParams(boolean b)
      Description copied from interface: IEntryPointCreator
      with this option enabled the EntryPointCreator tries to find suitable subclasses of abstract classes and implementers of interfaces
      Specified by:
      setSubstituteCallParams in interface IEntryPointCreator
      Parameters:
      b - sets substitution of call parameters
    • setSubstituteClasses

      public void setSubstituteClasses(List<String> l)
      Description copied from interface: IEntryPointCreator
      set classes that are allowed to substitute (otherwise constructor loops are very likely)
      Specified by:
      setSubstituteClasses in interface IEntryPointCreator
    • createDummyMain

      public soot.SootMethod createDummyMain()
      Description copied from interface: IEntryPointCreator
      Generates a dummy main method that calls all methods in the given list
      Specified by:
      createDummyMain in interface IEntryPointCreator
      Returns:
      The generated main method
    • createDummyMainInternal

      protected abstract soot.SootMethod createDummyMainInternal()
      Implementors need to overwrite this method for providing the actual dummy main method
      Returns:
      The generated dummy main method
    • getOrCreateDummyMainClass

      protected soot.SootClass getOrCreateDummyMainClass()
      Gets the class that contains the dummy main method. If such a class does not exist yet, it is created
      Returns:
      The class tha contains the dummy main method
    • createEmptyMainMethod

      protected void createEmptyMainMethod()
      Creates a new, empty main method containing the given body
    • createAdditionalFields

      protected void createAdditionalFields()
      Creates additional fields in the entry point class that are required by the dummy main method
    • createAdditionalMethods

      protected void createAdditionalMethods()
      Creates additional methods in the entry point class that are required by the dummy main method
    • getNonCollidingFieldName

      protected String getNonCollidingFieldName(String baseName)
      Gets a field name that is not already in use by some field
      Parameters:
      baseName - The base name, i.e., prefix of the new field
      Returns:
      A field name that is still free
    • buildMethodCall

      protected soot.jimple.Stmt buildMethodCall(soot.SootMethod methodToCall, soot.Local classLocal)
      Builds a new invocation statement that invokes the given method
      Parameters:
      methodToCall - The method to call
      classLocal - The local containing an instance of the class on which to invoke the method
      Returns:
      The newly created invocation statement
    • buildMethodCall

      protected soot.jimple.Stmt buildMethodCall(soot.SootMethod methodToCall, soot.Local classLocal, Set<soot.SootClass> parentClasses)
      Builds a new invocation statement that invokes the given method
      Parameters:
      methodToCall - The method to call
      classLocal - The local containing an instance of the class on which to invoke the method
      parentClasses - The classes for which we already have instances that shall be reused
      Returns:
      The newly created invocation statement
    • getValueForType

      protected soot.Value getValueForType(soot.Type tp, Set<soot.SootClass> constructionStack, Set<soot.SootClass> parentClasses)
      Creates a value of the given type to be used as a substitution in method invocations or fields
      Parameters:
      tp - The type for which to get a value
      constructionStack - The set of classes we're currently constructing. Attempts to create a parameter of one of these classes will trigger the constructor loop check and the respective parameter will be substituted by null.
      parentClasses - If the given type is compatible with one of the types in this list, the already-created object is used instead of creating a new one.
      Returns:
      The generated value, or null if no value could be generated
    • getValueForType

      protected soot.Value getValueForType(soot.Type tp, Set<soot.SootClass> constructionStack, Set<soot.SootClass> parentClasses, Set<soot.Local> generatedLocals, boolean ignoreExcludes)
      Creates a value of the given type to be used as a substitution in method invocations or fields
      Parameters:
      tp - The type for which to get a value
      constructionStack - The set of classes we're currently constructing. Attempts to create a parameter of one of these classes will trigger the constructor loop check and the respective parameter will be substituted by null.
      parentClasses - If the given type is compatible with one of the types in this list, the already-created object is used instead of creating a new one.
      generatedLocals - The set that receives all (temporary) locals created to provide a value of the requested type
      ignoreExcludes - True to ignore the exclude lists
      Returns:
      The generated value, or null if no value could be generated
    • generateClassConstructor

      protected soot.Local generateClassConstructor(soot.SootClass createdClass)
      Generates code which creates a new instance of the given class.
      Parameters:
      createdClass - The class of which to create an instance
      Returns:
      The local containing the new object instance if the operation completed successfully, otherwise null.
    • generateClassConstructor

      protected soot.Local generateClassConstructor(soot.SootClass createdClass, Set<soot.SootClass> parentClasses)
      Generates code which creates a new instance of the given class.
      Parameters:
      createdClass - The class of which to create an instance
      parentClasses - If a constructor call requires an object of a type which is compatible with one of the types in this list, the already-created object is used instead of creating a new one.
      Returns:
      The local containing the new object instance if the operation completed successfully, otherwise null.
    • acceptClass

      protected boolean acceptClass(soot.SootClass clazz)
      Determines whether a class is accepted for generating a constructor.
      Parameters:
      clazz - The class of which to create an instance
      Returns:
      Whether the class is accepted for generating a constructor
    • generateClassConstructor

      protected soot.Local generateClassConstructor(soot.SootClass createdClass, Set<soot.SootClass> constructionStack, Set<soot.SootClass> parentClasses, Set<soot.Local> tempLocals)
      Generates code which creates a new instance of the given class. Note that if allowNonPublicConstructors is true, private or protected constructors may be used.
      Parameters:
      createdClass - The class of which to create an instance
      constructionStack - The stack of classes currently under construction. This is used to detect constructor loops. If a constructor requires a parameter of a type that is already on the stack, this value is substituted by null.
      parentClasses - If a constructor call requires an object of a type which is compatible with one of the types in this list, the already-created object is used instead of creating a new one.
      tempLocals - The set that receives all generated temporary locals that were necessary for calling the constructor of the requested class
      Returns:
      The local containing the new object instance if the operation completed successfully, otherwise null.
    • isSimpleType

      protected static boolean isSimpleType(soot.Type t)
    • getSimpleDefaultValue

      protected soot.Value getSimpleDefaultValue(soot.Type t)
    • findMethod

      protected soot.SootMethod findMethod(soot.SootClass currentClass, String subsignature)
      Finds a method with the given signature in the given class or one of its super classes
      Parameters:
      currentClass - The current class in which to start the search
      subsignature - The subsignature of the method to find
      Returns:
      The method with the given signature if it has been found, otherwise null
    • isCompatible

      protected boolean isCompatible(soot.SootClass actual, soot.SootClass expected)
      Checks whether an object of type "actual" can be inserted where an object of type "expected" is required.
      Parameters:
      actual - The actual type (the substitution candidate)
      expected - The requested type
      Returns:
      True if the two types are compatible and "actual" can be used as a substitute for "expected", otherwise false
    • eliminateSelfLoops

      protected void eliminateSelfLoops()
      Eliminates all loops of length 0 (if a goto )
    • setDummyClassName

      public void setDummyClassName(String dummyClassName)
      Sets the name that shall be used for the new class containing the dummy main method
      Parameters:
      dummyClassName - The name for the new class containing the dummy main method
    • setDummyMethodName

      public void setDummyMethodName(String dummyMethodName)
      Sets the name that shall be used for the new dummy main method
      Parameters:
      dummyMethodName - The name for the new dummy main method
    • setAllowSelfReferences

      public void setAllowSelfReferences(boolean value)
      Sets whether a call to a method A.foo() may receive an instance of A as a parameter. If this is not allowed, other type-compatible class instances are taken. If they don't exist, null is used.
      Parameters:
      value - True if method calls may receive instances of their containing class as parameter values, otherwise false
    • setShallowMode

      public void setShallowMode(boolean shallowMode)
      Sets whether shallow mode shall be used. Normally, if a call to a method a() is to be created, this class first creates instances of all required parameter objects. If these, in turn, require other objects, they are instantiated as well. In shallow mode, this does not happen. Instead, all values on the first level are replaced with default values (e.g., null for objects).
      Parameters:
      shallowMode - True if shallow mode shall be used, otherwise false
    • getShallowMode

      public boolean getShallowMode()
      Gets whether shallow mode shall be used. Normally, if a call to a method a() is to be created, this class first creates instances of all required parameter objects. If these, in turn, require other objects, they are instantiated as well. In shallow mode, this does not happen. Instead, all values on the first level are replaced with default values (e.g., null for objects).
      Returns:
      True if shallow mode shall be used, otherwise false
    • setIgnoreSystemClassParams

      public void setIgnoreSystemClassParams(boolean ignoreSystemClassParams)
      Sets whether the entry point creator shall always pass "null" if a method expects an object of a system class.
      Parameters:
      ignoreSystemClassParams -
    • setAllowNonPublicConstructors

      public void setAllowNonPublicConstructors(boolean allowNonPublicConstructors)
      Sets whether the entry point creator may use private or protected constructors in order to generate a class instance in the dummyMain method.
      Parameters:
      allowNonPublicConstructors -
    • setOverwriteDummyMainMethod

      public void setOverwriteDummyMainMethod(boolean overwriteDummyMainValue)
      Sets whether the dummy main method shall be overwritten if it already exists. If this flag is set to "false", a new, non-conflicting method and class name is chosen.
      Parameters:
      overwriteDummyMainValue - True if existing methods that conflict with the entry point to be created shall be overwritten, false to automatically chose a new, non-conflicting name.
    • getOverwriteDummyMainMethod

      public boolean getOverwriteDummyMainMethod()
      Gets whether the dummy main method shall be overwritten if it already exists. If this flag is set to "false", a new, non-conflicting method and class name is chosen.
      Returns:
      True if existing methods that conflict with the entry point to be created shall be overwritten, false to automatically chose a new, non-conflicting name.
    • setWarnOnConstructorLoop

      public void setWarnOnConstructorLoop(boolean warnOnConstructorLoop)
      Sets whether a warning shall be written to the log when a constructor call cannot be generated because the analysis ran into a loop when trying to generate parameter values.
      Parameters:
      warnOnConstructorLoop - True if a warning shall be written to the log when a constructor generation loop is encountered, otherwise false
    • getWarnOnConstructorLoop

      public boolean getWarnOnConstructorLoop()
      Gets whether a warning shall be written to the log when a constructor call cannot be generated because the analysis ran into a loop when trying to generate parameter values.
      Returns:
      True if a warning shall be written to the log when a constructor generation loop is encountered, otherwise false
    • reset

      protected void reset()
      Resets the internal state to make sure that the entry point creator is re-usable. Note that this method will not reset the sets of failed classes and methods, because it doesn't make much sense to try them again and fail again on later re-runs.
    • createIfStmt

      protected void createIfStmt(soot.Unit target)
      Creates an opaque predicate that jumps to the given target
      Parameters:
      target - The target to which the opaque predicate shall jump
    • getGeneratedMainMethod

      public soot.SootMethod getGeneratedMainMethod()
      Description copied from interface: IEntryPointCreator
      Gets the last dummy main method that was generated by this creator
      Specified by:
      getGeneratedMainMethod in interface IEntryPointCreator
      Returns:
      The last dummy main method that was generated by this creator