I wanted to know how would I communicate with the jvmti agent I attached on a running JVM using attach API. When I say communicate ,here's what I meant : I want to call native functions located on my jvmti agent , theses function will return me data (like field values) of the running JVM that I "infected" earlier with the agent.
Here's the agent; I did not add the native functions yet:
#include <jvmti.h>
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM* vm, char* options, void* reserved);
jvmtiEnv* create_jvmti_env(JavaVM* vm);
JNIEnv* create_jni_env(JavaVM* vm);
void init_jvmti_capabilities(jvmtiEnv* env);
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
jvmtiEnv* jvmti = create_jvmti_env(vm);
init_jvmti_capabilities(jvmti);
JNIEnv* jni = create_jni_env(vm);
return JNI_OK;
}
jvmtiEnv* create_jvmti_env(JavaVM* vm) {
jvmtiEnv* env;
vm->GetEnv((void **) &env, JVMTI_VERSION_1_2);
return env;
}
JNIEnv* create_jni_env(JavaVM* vm) {
JNIEnv* env;
vm->GetEnv( (void **) &env, JNI_VERSION_1_8);
return env;
}
void init_jvmti_capabilities(jvmtiEnv* env) {
jvmtiCapabilities capabilities;
env->GetPotentialCapabilities( &capabilities);
env->AddCapabilities( &capabilities);
}