Class BaseEntryPointCreator
java.lang.Object
soot.jimple.infoflow.entryPointCreators.BaseEntryPointCreator
- All Implemented Interfaces:
IEntryPointCreator
- Direct Known Subclasses:
DefaultEntryPointCreator,SequentialEntryPointCreator
Common base class for all entry point creators. Implementors must override
the createDummyMainInternal method to provide their entry point
implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected soot.Bodyprotected intprotected StringDefault name of the class containing the dummy main methodprotected StringDefault name of the dummy main methodprotected soot.LocalGeneratorprotected soot.Valueprotected Map<soot.SootClass,soot.Local> protected final org.slf4j.Loggerprotected soot.SootMethodprotected booleanprotected booleanprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptClass(soot.SootClass clazz) Determines whether a class is accepted for generating a constructor.protected soot.jimple.StmtbuildMethodCall(soot.SootMethod methodToCall, soot.Local classLocal) Builds a new invocation statement that invokes the given methodprotected soot.jimple.StmtbuildMethodCall(soot.SootMethod methodToCall, soot.Local classLocal, Set<soot.SootClass> parentClasses) Builds a new invocation statement that invokes the given methodprotected voidCreates additional fields in the entry point class that are required by the dummy main methodprotected voidCreates additional methods in the entry point class that are required by the dummy main methodsoot.SootMethodGenerates a dummy main method that calls all methods in the given listprotected abstract soot.SootMethodImplementors need to overwrite this method for providing the actual dummy main methodprotected voidCreates a new, empty main method containing the given bodyprotected voidcreateIfStmt(soot.Unit target) Creates an opaque predicate that jumps to the given targetprotected voidEliminates all loops of length 0 (if a goto) protected soot.SootMethodfindMethod(soot.SootClass currentClass, String subsignature) Finds a method with the given signature in the given class or one of its super classesprotected soot.LocalgenerateClassConstructor(soot.SootClass createdClass) Generates code which creates a new instance of the given class.protected soot.LocalgenerateClassConstructor(soot.SootClass createdClass, Set<soot.SootClass> parentClasses) Generates code which creates a new instance of the given class.protected soot.LocalgenerateClassConstructor(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 properlySet<soot.SootMethod>Returns all methods from from methodsToCall, where no call was possiblesoot.SootMethodGets the last dummy main method that was generated by this creatorprotected StringgetNonCollidingFieldName(String baseName) Gets a field name that is not already in use by some fieldprotected soot.SootClassGets the class that contains the dummy main method.booleanGets whether the dummy main method shall be overwritten if it already exists.booleanGets whether shallow mode shall be used.protected soot.ValuegetSimpleDefaultValue(soot.Type t) protected soot.ValuegetValueForType(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 fieldsprotected soot.ValuegetValueForType(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 fieldsbooleanGets 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 booleanisCompatible(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 booleanisSimpleType(soot.Type t) protected voidreset()Resets the internal state to make sure that the entry point creator is re-usable.voidsetAllowNonPublicConstructors(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.voidsetAllowSelfReferences(boolean value) Sets whether a call to a method A.foo() may receive an instance of A as a parameter.voidsetDummyClassName(String dummyClassName) Sets the name that shall be used for the new class containing the dummy main methodvoidsetDummyMethodName(String dummyMethodName) Sets the name that shall be used for the new dummy main methodvoidsetIgnoreSystemClassParams(boolean ignoreSystemClassParams) Sets whether the entry point creator shall always pass "null" if a method expects an object of a system class.voidsetOverwriteDummyMainMethod(boolean overwriteDummyMainValue) Sets whether the dummy main method shall be overwritten if it already exists.voidsetShallowMode(boolean shallowMode) Sets whether shallow mode shall be used.voidsetSubstituteCallParams(boolean b) with this option enabled the EntryPointCreator tries to find suitable subclasses of abstract classes and implementers of interfacesvoidset classes that are allowed to substitute (otherwise constructor loops are very likely)voidsetWarnOnConstructorLoop(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, waitMethods inherited from interface soot.jimple.infoflow.entryPointCreators.IEntryPointCreator
getAdditionalFields, getAdditionalMethods, getRequiredClasses
-
Field Details
-
logger
protected final org.slf4j.Logger logger -
localVarsForClasses
-
dummyClassName
Default name of the class containing the dummy main method -
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
Returns a copy of all classes that could not be instantiated properly- Returns:
- The classes where the constructor could not be generated
-
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:IEntryPointCreatorwith this option enabled the EntryPointCreator tries to find suitable subclasses of abstract classes and implementers of interfaces- Specified by:
setSubstituteCallParamsin interfaceIEntryPointCreator- Parameters:
b- sets substitution of call parameters
-
setSubstituteClasses
Description copied from interface:IEntryPointCreatorset classes that are allowed to substitute (otherwise constructor loops are very likely)- Specified by:
setSubstituteClassesin interfaceIEntryPointCreator
-
createDummyMain
public soot.SootMethod createDummyMain()Description copied from interface:IEntryPointCreatorGenerates a dummy main method that calls all methods in the given list- Specified by:
createDummyMainin interfaceIEntryPointCreator- 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
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 callclassLocal- 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 callclassLocal- The local containing an instance of the class on which to invoke the methodparentClasses- 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 valueconstructionStack- 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 valueconstructionStack- 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 typeignoreExcludes- 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 instanceparentClasses- 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 ifallowNonPublicConstructorsistrue, private or protected constructors may be used.- Parameters:
createdClass- The class of which to create an instanceconstructionStack- 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
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 searchsubsignature- 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
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
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:IEntryPointCreatorGets the last dummy main method that was generated by this creator- Specified by:
getGeneratedMainMethodin interfaceIEntryPointCreator- Returns:
- The last dummy main method that was generated by this creator
-