Skip to content

SourcesSinksManager

Jordan Samhi edited this page Aug 22, 2023 · 1 revision

SourcesSinksManager 🔒

SourcesSinksManager is a singleton manager class for managing source and sink methods in an Android application. It extends the FileLoader class and loads, stores, and provides access to source and sink methods, represented as sets of AndroidMethod objects.

Table of Contents

Overview

SourcesSinksManager deals with source and sink methods within an Android application. It loads the sources and sinks from a file, processes their signatures, and categorizes them into corresponding sets.

Singleton Design

This class follows the Singleton pattern, ensuring only one instance during the execution of the application. The instance can be accessed via the v() method.

Methods

v()

Returns the singleton instance of SourcesSinksManager.

loadSourcesSinksFromFile(File file)

Loads source and sink methods from a given file.

  • Parameters: file - The file containing the source and sink methods' signatures.

getSources()

Returns the set of source methods.

  • Return Value: The set of AndroidMethod objects representing source methods.

getSinks()

Returns the set of sink methods.

  • Return Value: The set of AndroidMethod objects representing sink methods.

getFile()

Override of the abstract method from FileLoader. Returns the file path for sources and sinks.

Usage

Example 1: Getting Instance

SourcesSinksManager manager = SourcesSinksManager.v();

Example 2: Loading from File

Given a file with the following content:

SOURCE|<android.telephony.TelephonyManager: java.lang.String getLine1Number()>
SINK|<android.util.Log: int d(java.lang.String,java.lang.String)>

You can load the sources and sinks as follows:

File file = new File("path/to/sources_and_sinks.txt");
manager.loadSourcesSinksFromFile(file);

Example 3: Retrieving Sources and Sinks

Set<AndroidMethod> sources = manager.getSources();
Set<AndroidMethod> sinks = manager.getSinks();

Example 4: Exploring Loaded Sources and Sinks

Based on the loaded file, the sources set will include a method related to getting the line number from TelephonyManager, and the sinks set will include a method related to logging from the Log class:

for (AndroidMethod source : sources) {
    System.out.println("Source: " + source.getSignature());
}
for (AndroidMethod sink : sinks) {
    System.out.println("Sink: " + sink.getSignature());
}

Output:

Source: <android.telephony.TelephonyManager: java.lang.String getLine1Number()>
Sink: <android.util.Log: int d(java.lang.String,java.lang.String)>

These examples demonstrate how to use the SourcesSinksManager class to manage and utilize source and sink methods in an Android application.