JNIEnv*
from JavaVM*
on Agent_OnLoad MethodJNIEXPORT void JNICALL Java_ClassName_MethodName(JNIEnv *env, jobject obj, jstring javaString)
{
const char *nativeString = env->GetStringUTFChars(javaString, 0);
// use your string
env->ReleaseStringUTFChars(javaString, nativeString);
}
JNIEnv *jni;
jclass clazz = jni->FindClass("java/lang/Integer");
jmethodID method = jni->GetMethodID(clazz, "<init>", "(Ljava/lang/String;)V");
jobject n = jni->NewObject(clazz, method, jni->NewStringUTF("123"));
printf("int created %s\n", n);
JNIEnv *jni;
jclass clazz = jni->FindClass("java/lang/String");
jmethodID method = jni->GetStaticMethodID(clazz, "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;");
if(method == NULL){
jni->FatalError("Class method not found\n");
}
jstring arg1 = jni->NewStringUTF("Hello World!!!");
jstring result = (jstring) jni->CallStaticObjectMethod(clazz, method, arg1);
jni->ReleaseStringUTFChars(arg1, NULL);
if (result == NULL) {
jni->FatalError("couldn't call method");
}
jboolean isCopy = (jboolean) false;
printf("result: %s\n", jni->GetStringUTFChars(result, &isCopy));
$ javap -v java.lang.Class | grep -A1 'forName('
public static java.lang.Class<?> forName(java.lang.Module, java.lang.String);
descriptor: (Ljava/lang/Module;Ljava/lang/String;)Ljava/lang/Class;
Add link options, cmake example
-Wl,--add-stdcall-alias -m32 -shared
jni commands, jni bookmarks, jvmti commands, jvmti bookmarks