4ra1n
6 小时 11 分钟前
我发现不能对 ClassFile 做操作,有时候取到的 name 是 null
callbacks.ClassFileLoadHook = &ClassLoadHook;
使用 ClassLoad 会更靠谱
callbacks.ClassLoad = &ClassLoadHook;
void JNICALL ClassLoadHook(
jvmtiEnv *jvmti_env,
JNIEnv *jni_env,
jthread thread,
const jclass klass) {
char *classSignature;
char *genericPtr;
const jvmtiError err = (*jvmti_env)->GetClassSignature(
jvmti_env, klass, &classSignature, &genericPtr);
if (err != JVMTI_ERROR_NONE) {
LOG_JVM(jni_env,"ERROR GET CLASS SIGNATURE");
return;
}
DoAnalyze(jni_env,classSignature);
(*jvmti_env)->Deallocate(jvmti_env, (unsigned char *) classSignature);
if (genericPtr != NULL) {
(*jvmti_env)->Deallocate(jvmti_env, (unsigned char *) genericPtr);
}
}