Unlike languages such as Objective-C (where all code is loaded and all classes are available the second an image is loaded), Java slowly loads code over time into various "class loaders". This means that to use APIs such as MSJavaHookMethod, you first need to know when the class is available.
Substrate therefore provides an API that allows you to receive a callback notification (along with associated opaque data value) when a class is loaded, giving you a pointer to the JNI environment in which the class was loaded, in addition to a reference to the now-loaded JNI class.
Parameter | Description |
---|---|
jni |
JNI environment to filter for class. This parameter may be NULL , in which case all JNI environments are checked. (Currently, this parameter must be set to NULL .) |
name |
The name of the class, using JNI's slash notation. |
callback |
Address of a function to call when class is loaded. This will be passed data , the JNI environment in which the class was loaded, and a JNI reference to the class. |
data |
Opaque argument passed through to callback function. |
static void onLoad(JNIEnv *jni, jclass _class, void *data) { /* do something with _class argument */ } MSJavaHookClassLoad( NULL, // any JNI environment "java/net/HttpURLConnection", &onLoad, NULL // no custom argument );