public abstract class

MethodBundle

extends Object
java.lang.Object
   ↳ org.probedroid.support.MethodBundle

Class Overview

The interface of method instrumentation gadget. Analysts should inherit this class to craft their own instrumentation logic. For example, determining how to utilize the intercepted input arguments or the return value.

 public class MyMethodBundle extends MethodBundle {
     public MyMethodBundle(boolean interceptBefore,
             boolean interceptAfter) {
         super(interceptBefore, interceptAfter);
     }
 
     @Override
     public void beforeMethodExecute(Object[] objects) {
         // Determine how to utilize the intercepted input arguments.
     }
 
     @Override
     public void afterMethodExecute(Object o) {
         // Determine how to utilize the intercepted return value if any.
     }
 }
 

Summary

Public Constructors
MethodBundle(boolean interceptBefore, boolean interceptAfter)
Public Methods
abstract void afterMethodExecute(Object output)
The callback to intercept the return value after the target method is executed.
abstract void beforeMethodExecute(Object[] inputs)
The callback to intercept the input arguments before the target method is executed.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MethodBundle (boolean interceptBefore, boolean interceptAfter)

Parameters
interceptBefore The flag indicating whether to intercept the target method when it is called but not executed yet.
interceptAfter The flag indicating whether to intercept the target method when it is executed but not returned yet.

Public Methods

public abstract void afterMethodExecute (Object output)

The callback to intercept the return value after the target method is executed. Note that the return value is boxed as java.lang.Object type. Analyst can cast the boxed object to its original type for manipulation. Also, modifying the value content or replacing the value with the one instantiated from this callback are both allowed. Therefore, simple data profiling and dynamic behavior modification are possible.

 // Suppose we plan to instrument StringBuffer StringBuffer.append(String)
 @Override
 public void afterMethodExecute(Object object) {
     StringBuffer sb = (StringBuffer) object;
     sb.append(" Hack Again");
 }
 

Parameters
output The boxed return value of the target method or null if the target method returns void.

public abstract void beforeMethodExecute (Object[] inputs)

The callback to intercept the input arguments before the target method is executed. Note that all the arguments are boxed as java.lang.Object type. Analyst can cast each boxed object to its original type for manipulation. Also, modifying the argument content or replacing the argument with the one instantiated from this callback are both allowed. Therefore, simple data profiling and dynamic behavior modification are possible.

 // Suppose we plan to instrument StringBuffer StringBuffer.append(String)
 @Override
 public void beforeMethodExecute(Object[] objects) {
     String str = (String) objects[0];
     Log.d("My Instrument", str);
     objects[0] = new String("Hack");
 }
 

Parameters
inputs The array of boxed input arguments of the target method.