mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
WIP: ClassFileLoadHook
This commit is contained in:
1 parent
b0d8b5901f
commit
faeaf052b9
3 files changed
+45
No files matched your search
@@ -0,0 +1,16 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <iostream>
|
||||
|
||||
void JNICALL ClassFileLoadHook(
|
||||
jvmtiEnv* jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jclass class_being_redefined,
|
||||
jobject loader,
|
||||
const char* name,
|
||||
jobject protection_domain,
|
||||
jint class_data_len,
|
||||
const unsigned char* classbytes,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_classbytes) {
|
||||
std::cout << "ClassFileLoadHook: " << name << std::endl;
|
||||
}
|
||||
@@ -8,3 +8,17 @@
|
||||
|
||||
// Generated by JuiceAgent-API
|
||||
#include <cn_xiaozhou233_juiceagent_api_JuiceAgent.h>
|
||||
|
||||
// Event callbacks
|
||||
// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#ClassFileLoadHook
|
||||
void JNICALL ClassFileLoadHook(
|
||||
jvmtiEnv* jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jclass class_being_redefined,
|
||||
jobject loader,
|
||||
const char* name,
|
||||
jobject protection_domain,
|
||||
jint class_data_len,
|
||||
const unsigned char* classbytes,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_classbytes);
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <libagent.hpp>
|
||||
#include <jni_impl.hpp>
|
||||
|
||||
namespace JuiceAgent {
|
||||
// ===== Singleton =====
|
||||
@@ -45,6 +46,20 @@ namespace JuiceAgent {
|
||||
|
||||
PLOGI << "Abilities added successfully";
|
||||
|
||||
// ======== Register callbacks ========
|
||||
jvmtiEventCallbacks callbacks{};
|
||||
callbacks.ClassFileLoadHook = &ClassFileLoadHook;
|
||||
result = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (result != JNI_OK) {
|
||||
PLOGE << "Failed to set event callbacks: " << result;
|
||||
}
|
||||
|
||||
// Enable events
|
||||
result = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
|
||||
if (result != JNI_OK) {
|
||||
PLOGE << "Failed to enable event notification: " << result;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user