diff --git a/src/libloader/common/libloader.cpp b/src/libloader/common/libloader.cpp index 06240a5..6991870 100644 --- a/src/libloader/common/libloader.cpp +++ b/src/libloader/common/libloader.cpp @@ -5,6 +5,66 @@ namespace libloader { + // 累了,这几把的代码扔给AI算了 气死了 + bool invoke_juiceagent_init(JNIEnv* env, const InjectionInfo& info) { + std::string bootstrap_class = "cn/xiaozhou233/juiceagent/api/JuiceAgentBootstrap"; + std::string method_name = "start"; + std::string method_desc = "([Ljava/lang/String;)V"; + + // Find Class + jclass bootstrap_class_obj = env->FindClass(bootstrap_class.c_str()); + if (!bootstrap_class_obj) { + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + PLOGE << "Failed to find JuiceAgentBootstrap class: " << bootstrap_class; + return false; + } + + // Find Method + jmethodID method_id = env->GetStaticMethodID(bootstrap_class_obj, method_name.c_str(), method_desc.c_str()); + if (!method_id) { + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + PLOGE << "Failed to find method: " << method_name; + return false; + } + + // Prepare arguments (order matters) + const char* args[] = { + info.EntryJarPath.c_str(), + info.EntryClass.c_str(), + info.EntryMethod.c_str(), + info.InjectionDir.c_str(), + info.JuiceAgentNativePath.c_str() + }; + int argCount = sizeof(args) / sizeof(args[0]); + + jclass stringCls = env->FindClass("java/lang/String"); + jobjectArray jArgs = env->NewObjectArray(argCount, stringCls, nullptr); + for (int i = 0; i < argCount; i++) { + env->SetObjectArrayElement(jArgs, i, env->NewStringUTF(args[i])); + } + + // Invoke the method + env->CallStaticVoidMethod(bootstrap_class_obj, method_id, jArgs); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + + // Cleanup + env->DeleteLocalRef(jArgs); + env->DeleteLocalRef(stringCls); + + PLOGI << "JuiceAgentBootstrap.start invoked successfully"; + return true; + } + + void entrypoint(const char* runtime_dir) { if (runtime_dir == nullptr) { @@ -49,5 +109,7 @@ namespace libloader } PLOGI << "Jar injected successfully: " << jar_path; + + invoke_juiceagent_init(jvm.get_env(), info); } } // namespace libloader \ No newline at end of file diff --git a/src/libloader/includes/libloader.hpp b/src/libloader/includes/libloader.hpp index 091d41d..7521fe0 100644 --- a/src/libloader/includes/libloader.hpp +++ b/src/libloader/includes/libloader.hpp @@ -1,6 +1,14 @@ #pragma once +#include +#include +#include +#include +#include + namespace libloader { void entrypoint(const char* runtime_dir); + + bool invoke_juiceagent_init(JNIEnv* env, const InjectionInfo& info); } // namespace libloader