Feat: Event of preload & loaded

This commit is contained in:
xiaozhou233 committed 2026-04-04 21:51:12 +08:00
1 parent eb3a76769d
commit f8be8cb795
2 files changed
+29

No files matched your search

@@ -14,4 +14,17 @@ struct EventClassFileLoadHook {
const unsigned char* classbytes; const unsigned char* classbytes;
jint* new_class_data_len; jint* new_class_data_len;
unsigned char** new_classbytes; unsigned char** new_classbytes;
};
// JuiceAgent PreLoad/PostLoad
struct EventPreLoad {
JavaVM* jvm;
JNIEnv* env;
jvmtiEnv* jvmti;
};
struct EventLoaded {
JavaVM* jvm;
JNIEnv* env;
jvmtiEnv* jvmti;
}; };
+16
View File
@@ -1,6 +1,8 @@
#include <libagent.hpp> #include <libagent.hpp>
#include <jni_impl.hpp> #include <jni_impl.hpp>
#include <bytecodes_opt.hpp> #include <bytecodes_opt.hpp>
#include <event/event_type.hpp>
#include <event/eventbus.hpp>
namespace JuiceAgent { namespace JuiceAgent {
// ===== Singleton ===== // ===== Singleton =====
@@ -12,6 +14,13 @@ namespace JuiceAgent {
bool Agent::init(JavaVM* jvm, JNIEnv* env, jvmtiEnv* jvmti) { bool Agent::init(JavaVM* jvm, JNIEnv* env, jvmtiEnv* jvmti) {
PLOGI << "JuiceAgent Native EntryPoint Invoked!"; PLOGI << "JuiceAgent Native EntryPoint Invoked!";
// PreLoad Event
eventbus.post(EventPreLoad{
.jvm = jvm,
.env = env,
.jvmti = jvmti
});
// ======== neccessary environment check ======== // ======== neccessary environment check ========
if (jvm == nullptr) { if (jvm == nullptr) {
PLOGE << "Failed to initialize JuiceAgent: jvm is null"; PLOGE << "Failed to initialize JuiceAgent: jvm is null";
@@ -64,6 +73,13 @@ namespace JuiceAgent {
// register bytecodes_opt // register bytecodes_opt
JuiceAgent::Bytecodes::register_bytecodes(); JuiceAgent::Bytecodes::register_bytecodes();
// Loaded Event
eventbus.post(EventLoaded{
.jvm = jvm,
.env = env,
.jvmti = jvmti
});
return true; return true;
} }
} }