Skip to content

Instrumenter

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

Instrumenter 🔧

Instrumenter is a singleton class designed to facilitate the addition of log statements to SootMethods, which is part of the AndroSpecter library.

Table of Contents

Overview

Instrumenter helps in adding log statements at specific points within methods or across multiple methods within an application. This allows tracking the flow and behavior of the application.

Singleton Access

v()

Accesses the singleton instance of the Instrumenter class.

Usage:

Instrumenter instrumenter = Instrumenter.v();

Logging Methods

addLogToAllMethods(String tagToLog, String phaseName)

Adds log statements to all methods of application classes.

addLogStatement(Chain<Unit> units, Unit insertionPoint, String tagToLog, String messageToLog, Body b)

Inserts a log statement at a specified location within the body of a method.

addLogToAllMethodCalls(String tagToLog, String phaseName)

Modifies all method calls within a body to include a log statement that logs the signatures of the calling and called methods.

addLogToMethod(SootMethod sm, String tagToLog, String messageToLog)

Inserts a log statement right after all identity statements in the given method.

Example Usages

Example 1: Logging All Method Calls

Instrumenter instrumenter = Instrumenter.v();
Transform transform = instrumenter.addLogToAllMethodCalls("DEBUG_TAG", "jbop");
PackManager.v().getPack("jbop").add(transform);

Example 2: Adding Log to Specific Method

Instrumenter instrumenter = Instrumenter.v();
SootMethod method = ...; // Obtain a SootMethod reference
instrumenter.addLogToMethod(method, "INFO_TAG", "Method called");

Example 3: Adding Log at Specific Unit

Instrumenter instrumenter = Instrumenter.v();
Chain<Unit> units = ...; // Obtain the chain of units
Unit insertionPoint = ...; // Obtain the insertion point
String tagToLog = "DEBUG";
String messageToLog = "Log Message";
Body body = ...; // Obtain the body
instrumenter.addLogStatement(units, insertionPoint, tagToLog, messageToLog, body);

These examples showcase how to use Instrumenter to insert customized log statements within methods of an Android application.