Skip to content

SootUtils

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

SootUtils 🧰

SootUtils is a utility class designed to provide assistance in working with Soot classes, methods, and call graphs, specifically for Android application analysis. It offers a variety of methods and fields to facilitate tasks such as analyzing class hierarchy, method invocations, and control flow.

Table of Contents

Overview

SootUtils is a class that centralizes various tasks and analyses related to the Soot framework for Android applications.

Methods

General

  • getMethodRef(String className, String methodName): Retrieves SootMethodRef.
  • getAllSuperClasses(SootClass sootClass): Returns all superclasses.
  • getAllInterfaces(SootClass sootClass): Returns all interfaces.
  • getClassNames(Collection<SootClass> classes): Converts to class names.

Statements

  • getNumberOfStmt(SootMethod sm): Counts statements in SootMethod.
  • getNumberOfStmtInApp(): Total statements in application.
  • getNumberOfStmtInAppWithoutLibraries(): Total statements excluding libraries.
  • getNumberOfStmt(Collection<SootMethod> methods): Statements in SootMethods.

Call Graph

  • countEdgesInCallGraph(CallGraph cg): Counts edges in call graph.
  • countEdgesWithNonLibraryTargets(CallGraph cg): Counts non-library targets.
  • getCountOfNodes(CallGraph cg): Counts nodes in call graph.
  • isInCallGraph(SootMethod method, CallGraph cg): Checks method in call graph.
  • isCalledInCallGraph(SootMethod method, CallGraph cg): Checks method called in call graph.

Android Components

  • getComponentType(SootClass sc): Identifies Android component type.

Soot Setup

  • setupSoot(String platformPath, String apkPath, boolean wholeAnalysis): Configures Soot.
  • setupSootWithOutput(String platformPath, String apkPath, String outputPath, boolean wholeAnalysis): Configures Soot with output.

Others

Various methods to retrieve or exclude methods and classes according to criteria.

Usage

Use SootUtils to efficiently perform static analysis on Android applications with the Soot framework. It simplifies handling of common tasks.

Example 1: Retrieving Superclasses of a SootClass

SootClass sootClass = Scene.v().getSootClass("com.example.MyClass");
Set<SootClass> superClasses = SootUtils.getAllSuperClasses(sootClass);
for (SootClass superClass : superClasses) {
    System.out.println("Superclass: " + superClass.getName());
}

Example 2: Counting Statements in a Method

SootMethod method = Scene.v().getSootClass("com.example.MyClass").getMethodByName("myMethod");
int numberOfStatements = SootUtils.getNumberOfStmt(method);
System.out.println("Number of statements: " + numberOfStatements);

Example 3: Setting up Soot

String platformPath = "/path/to/android/platforms";
String apkPath = "/path/to/app.apk";
boolean wholeAnalysis = true;
SootUtils.setupSoot(platformPath, apkPath, wholeAnalysis);

Example 4: Analyzing Call Graph for Specific Method

SootMethod method = Scene.v().getSootClass("com.example.MyClass").getMethodByName("targetMethod");
CallGraph cg = Scene.v().getCallGraph();
boolean isInCallGraph = SootUtils.isInCallGraph(method, cg);
System.out.println("Is method in call graph? " + isInCallGraph);

Example 5: Identifying Android Component Type

SootClass sootClass = Scene.v().getSootClass("com.example.MyActivity");
String componentType = SootUtils.getComponentType(sootClass);
System.out.println("Component Type: " + componentType);

These examples showcase the diverse functionalities provided by the SootUtils class. It offers a simplified interface to work with Soot classes, methods, statements, and call graphs in the context of Android application analysis.

The SootUtils class is essential for developers working with Soot to analyze Android applications. It offers a structured way to perform various analyses and simplifies many common tasks.