Class SetupApplication

java.lang.Object
soot.jimple.infoflow.android.SetupApplication
All Implemented Interfaces:
ITaintWrapperDataFlowAnalysis

public class SetupApplication extends Object implements ITaintWrapperDataFlowAnalysis
  • Field Details

  • Constructor Details

    • SetupApplication

      public SetupApplication(InfoflowAndroidConfiguration config)
      Creates a new instance of the SetupApplication class
      Parameters:
      config - The data flow configuration to use
    • SetupApplication

      public SetupApplication(File androidJar, File apkFile)
      Creates a new instance of the SetupApplication class
      Parameters:
      androidJar - The path to the Android SDK's "platforms" directory if Soot shall automatically select the JAR file to be used or the path to a single JAR file to force one.
      apkFile - The APK file to be analyzed
    • SetupApplication

      public SetupApplication(File androidJar, File apkFileLocation, IIPCManager ipcManager)
      Creates a new instance of the SetupApplication class
      Parameters:
      androidJar - The path to the Android SDK's "platforms" directory if Soot shall automatically select the JAR file to be used or the path to a single JAR file to force one.
      apkFileLocation - The path to the APK file to be analyzed
      ipcManager - The IPC manager to use for modeling inter-component and inter-application data flows
    • SetupApplication

      public SetupApplication(InfoflowAndroidConfiguration config, IIPCManager ipcManager)
      Creates a new instance of the SetupApplication class
      Parameters:
      config - The data flow configuration to use
      ipcManager - The IPC manager to use for modelling inter-component and inter-application data flows
  • Method Details

    • addOptimizationPass

      public void addOptimizationPass(SetupApplication.OptimizationPass pass)
      Add an optimization pass to be applied before the analysis.
      Parameters:
      pass - optimization pass
    • getSinks

      public Collection<? extends ISourceSinkDefinition> getSinks()
      Gets the set of sinks loaded into FlowDroid These are the sinks as they are defined through the SourceSinkManager.
      Returns:
      The set of sinks loaded into FlowDroid
    • getCollectedSinks

      public Set<soot.jimple.Stmt> getCollectedSinks()
      Gets the concrete instances of sinks that have been collected inside the app. This method returns null if source and sink logging has not been enabled (see InfoflowConfiguration.setLogSourcesAndSinks()).
      Returns:
      The set of concrete sink instances in the app
    • printSinks

      public void printSinks()
      Prints the list of sinks registered with FlowDroud to stdout
    • getSources

      public Collection<? extends ISourceSinkDefinition> getSources()
      Gets the set of sources loaded into FlowDroid. These are the sources as they are defined through the SourceSinkManager.
      Returns:
      The set of sources loaded into FlowDroid
    • getCollectedSources

      public Set<soot.jimple.Stmt> getCollectedSources()
      Gets the concrete instances of sources that have been collected inside the app. This method returns null if source and sink logging has not been enabled (see InfoflowConfiguration.setLogSourcesAndSinks()).
      Returns:
      The set of concrete source instances in the app
    • printSources

      public void printSources()
      Prints the list of sources registered with FlowDroud to stdout
    • getEntrypointClasses

      public Set<soot.SootClass> getEntrypointClasses()
      Gets the set of classes containing entry point methods for the lifecycle
      Returns:
      The set of classes containing entry point methods for the lifecycle
    • printEntrypoints

      public void printEntrypoints()
      Prints list of classes containing entry points to stdout
    • setCallbackClasses

      public void setCallbackClasses(Set<String> callbackClasses)
      Sets the class names of callbacks. hese are the callback classes defined by the Android SDK, and they are not mapped to the current application. If this value is null, FlowDroid automatically loads the names from AndroidCallbacks.txt as the default behavior.
      Parameters:
      callbackClasses - The class names of callbacks or null to use the default file.
    • getCallbackClasses

      public Set<String> getCallbackClasses()
      Gets the class names of callbacks. These are the callback classes defined by the Android SDK, and they are not mapped to the current application.
      Returns:
      The class names of callbacks or null to use the default file.
    • setTaintWrapper

      public void setTaintWrapper(ITaintPropagationWrapper taintWrapper)
      Specified by:
      setTaintWrapper in interface ITaintWrapperDataFlowAnalysis
    • getTaintWrapper

      public ITaintPropagationWrapper getTaintWrapper()
      Specified by:
      getTaintWrapper in interface ITaintWrapperDataFlowAnalysis
    • parseAppResources

      protected void parseAppResources() throws IOException
      Parses common app resources such as the manifest file
      Throws:
      IOException - Thrown if the given source/sink file could not be read.
    • getResources

      public ARSCFileParser getResources()
      Get the ARSC file parser to read resources.
      Returns:
      ARSCFileParser
    • createManifestParser

      protected IManifestHandler createManifestParser(File targetAPK) throws IOException
      Creates the manifest handler for processing the app manifest
      Parameters:
      targetAPK - The target APK file
      Returns:
      The manifest handler for reading the given app's manifest file
      Throws:
      IOException
    • createSourceSinkProvider

      protected void createSourceSinkProvider(soot.SootClass entryPoint, LayoutFileParser lfp)
      Creates the source/sink provider
      Parameters:
      entryPoint - The entry point on which to run the data flow analysis
      lfp - The layout file parser
    • createLayoutFileParser

      protected LayoutFileParser createLayoutFileParser()
      Creates a new layout file parser. Derived classes can override this method to supply their own parser.
      Returns:
      The newly created layout file parser.
    • createSourceSinkManager

      protected ISourceSinkManager createSourceSinkManager(LayoutFileParser lfp, Set<AndroidCallbackDefinition> callbacks)
      Creates an instance of ISourceSinkManager that defines what FlowDorid shall consider as a source or sink, respectively.
      Parameters:
      lfp - The parser that handles the layout XML files
      callbacks - The callbacks that have been collected so far
      Returns:
      The new source sink manager
    • constructCallgraphInternal

      protected void constructCallgraphInternal()
      Triggers the callgraph construction in Soot
    • createIccInstrumenter

      protected IccInstrumenter createIccInstrumenter()
      Creates the ICC instrumentation class
      Returns:
      An instance of the class for instrumenting the app's code for inter-component communication
    • createCallbackMemoryWatcher

      protected FlowDroidMemoryWatcher createCallbackMemoryWatcher(AbstractCallbackAnalyzer jimpleClass)
      Creates the memory watcher for aborting the callback analysis in case it runs out of memory. This method also starts the watchdog thread. Derived classes can implement their own timeout handling if necessary.
      Parameters:
      callbackConfig - The configuration for the callback analysis
      analyzer - The callback analyzer
      Returns:
      The memory watcher that keeps track of the amount of memory spent in the callback analysis
    • createCallbackTimeoutWatcher

      protected FlowDroidTimeoutWatcher createCallbackTimeoutWatcher(InfoflowAndroidConfiguration.CallbackConfiguration callbackConfig, AbstractCallbackAnalyzer analyzer)
      Creates the timeout watcher for aborting the callback analysis in case it runs out of time. This method also starts the watchdog thread. Derived classes can implement their own timeout handling if necessary.
      Parameters:
      callbackConfig - The configuration for the callback analysis
      analyzer - The callback analyzer
      Returns:
      The timeout watcher that keeps track of the time spent in the callback analysis
    • releaseCallgraph

      protected void releaseCallgraph()
      Releases the callgraph and all intermediate objects associated with it
    • getSourceSinkManager

      public ISourceSinkManager getSourceSinkManager()
      Gets the source/sink manager constructed for FlowDroid. Make sure to call constructCallgraph() first, or you will get a null result.
      Returns:
      FlowDroid's source/sink manager
    • getLibraryClassPatcher

      protected LibraryClassPatcher getLibraryClassPatcher()
    • configureCallgraph

      protected void configureCallgraph()
      Configures the callgraph options for Soot according to FlowDroid's settings
    • constructCallgraph

      public void constructCallgraph()
      Constructs a callgraph only without running the actual data flow analysis. If you want to run a data flow analysis, do not call this method. Instead, call runInfoflow() directly, which will take care all necessary prerequisites.
    • runInfoflow

      public InfoflowResults runInfoflow(Set<AndroidMethod> sources, Set<AndroidMethod> sinks) throws IOException
      Runs the data flow analysis.
      Parameters:
      sources - The methods that shall be considered as sources
      sinks - The methods that shall be considered as sinks
      Throws:
      IOException - Thrown if the given source/sink file could not be read.
    • runInfoflow

      public InfoflowResults runInfoflow(File sourceSinkFile) throws IOException
      Runs the data flow analysis.
      Parameters:
      sourceSinkFile - The full path and file name of the file containing the sources and sinks
      Throws:
      IOException - Thrown if the given source/sink file could not be read.
    • runInfoflow

      public InfoflowResults runInfoflow() throws IOException
      Runs the data flow analysis.
      Throws:
      IOException - Thrown if the given source/sink file could not be read.
    • runInfoflow

      public InfoflowResults runInfoflow(ISourceSinkDefinitionProvider sourcesAndSinks)
      Runs the data flow analysis.
      Parameters:
      sourcesAndSinks - The sources and sinks of the data flow analysis
      Returns:
      The results of the data flow analysis
    • processEntryPoint

      protected void processEntryPoint(ISourceSinkDefinitionProvider sourcesAndSinks, soot.jimple.infoflow.android.SetupApplication.MultiRunResultAggregator resultAggregator, int numEntryPoints, soot.SootClass entrypoint)
      Runs the data flow analysis on the given entry point class
      Parameters:
      sourcesAndSinks - The sources and sinks on which to run the data flow analysis
      resultAggregator - An object for aggregating the results from the individual data flow runs
      numEntryPoints - The total number of runs (for logging)
      entrypoint - The current entry point to analyze
    • serializeResults

      protected void serializeResults(InfoflowResults results, IInfoflowCFG cfg)
      Writes the given data flow results into the configured output file
      Parameters:
      results - The data flow results to write out
      cfg - The control flow graph to use for writing out the results
    • createInfoflow

      protected SetupApplication.IInPlaceInfoflow createInfoflow()
      Instantiates and configures the data flow engine
      Returns:
      A properly configured instance of the Infoflow class
    • createInfoflowInternal

      protected SetupApplication.IInPlaceInfoflow createInfoflowInternal(Collection<soot.SootMethod> lifecycleMethods)
      Creates the data flow engine on which to run the analysis. Derived classes can override this method to use other data flow engines.
      Parameters:
      lifecycleMethods - The set of Android lifecycle methods to consider
      Returns:
      The data flow engine
    • createEntryPointCreator

      protected AndroidEntryPointCreator createEntryPointCreator(Set<soot.SootClass> components)
      Creates a new instance of the entry point creator
      Parameters:
      components - The components for which the entry point creator shallk be responsible
      Returns:
      The new instance of the entry point creator
    • getDummyMainMethod

      public soot.SootMethod getDummyMainMethod()
      Gets the dummy main method that was used for the last callgraph construction. You need to run a data flow analysis or call constructCallgraph() first, otherwise you will get a null result.
      Returns:
      The dummy main method
    • getSootConfig

      public IInfoflowConfig getSootConfig()
      Gets the extra Soot configuration options to be used when running the analysis
      Returns:
      The extra Soot configuration options to be used when running the analysis, null if the defaults shall be used
    • setSootConfig

      public void setSootConfig(IInfoflowConfig config)
      Sets the extra Soot configuration options to be used when running the analysis
      Parameters:
      config - The extra Soot configuration options to be used when running the analysis, null if the defaults shall be used
    • setIcfgFactory

      public void setIcfgFactory(BiDirICFGFactory factory)
      Sets the factory class to be used for constructing interprocedural control flow graphs
      Parameters:
      factory - The factory to be used. If null is passed, the default factory is used.
    • getConfig

      public InfoflowAndroidConfiguration getConfig()
      Gets the data flow configuration
      Returns:
      The current data flow configuration
    • setCallbackFile

      public void setCallbackFile(String callbackFile)
    • addPreprocessor

      public void addPreprocessor(PreAnalysisHandler preprocessor)
      Adds custom code to be executed before the taint propagation starts
      Parameters:
      preprocessor - The callback to invoke before starting the taint propagation
    • addResultsAvailableHandler

      public void addResultsAvailableHandler(ResultsAvailableHandler handler)
      Adds a new handler that shall be executed when the results of the data flow analysis are available
      Parameters:
      handler - The callback to invoke when the data flow results are available
    • clearResultsAvailableHandlers

      public void clearResultsAvailableHandlers()
      Clears the list of handlers that shall be executed when the data flow results are available
    • abortAnalysis

      public void abortAnalysis()
      Aborts the data flow analysis. This is useful when the analysis controller is running in a different thread and the main thread (e.g., a GUI) wants to abort the analysis
    • setIpcManager

      public void setIpcManager(IIPCManager ipcManager)
      Sets the IPC manager for modeling inter-component and inter-application data flows
      Parameters:
      ipcManager - The IPC manager to use for modeling inter-component and inter-application data flows
    • setTaintPropagationHandler

      public void setTaintPropagationHandler(TaintPropagationHandler taintPropagationHandler)
      Sets the taint propagation handler, which will be notified when the data flow analysis processes an edge. Use this callback if you need a hook into the low-level data flow analysis.
      Parameters:
      taintPropagationHandler - The propagation handler to register
    • setAliasPropagationHandler

      public void setAliasPropagationHandler(TaintPropagationHandler aliasPropagationHandler)
      Sets the alias propagation handler, which will be notified when the alias analysis processes an edge. Use this callback if you need a hook into the low-level alias analysis.
      Parameters:
      aliasPropagationHandler - The propagation handler to register
    • setValueProvider

      public void setValueProvider(IValueProvider valueProvider)
      Sets the value provider that extracts constants from the Jimple code
      Parameters:
      valueProvider - The value provider for extracting constants from the code
    • removeSimulatedCodeElements

      public void removeSimulatedCodeElements()
      Removes all simulated code elements generated during entry point creation and ICC instrumentation from the Soot Scene
    • setUsageContextProvider

      public void setUsageContextProvider(IUsageContextProvider usageContextProvider)
    • tagUserCodeClasses

      protected void tagUserCodeClasses()
      Some apps, especially malware, use namespaces like "com.google.myapp", which are also namespaces of system packages. To distinguish bad namespaces from actual system packages, we tag user classes that also match system packages as with FlowDroidUserClass.