Impl: Invoke JuiceAgentAPI start

This commit is contained in:
xiaozhou233 committed 2026-03-30 14:14:40 +08:00
1 parent 15d7f0295a
commit 0a4ec5e97a
2 files changed
+70

No files matched your search

+62
View File
@@ -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