Patch: AI Fix

This commit is contained in:
xiaozhou233 committed 2026-03-30 13:49:47 +08:00
1 parent c5817a3b06
commit 15d7f0295a
1 file changed
+32 -13
+32 -13
View File
@@ -5,30 +5,49 @@
namespace libloader
{
void entrypoint(const char* runtime_dir) {
void entrypoint(const char* runtime_dir)
{
if (runtime_dir == nullptr) {
PLOGE << "runtime_dir is null, fallback may fail";
}
// Load Config
// Load Config (allow fallback)
config::Config cfg(runtime_dir);
if (!cfg.is_valid()) {
PLOGE << "Invalid config";
PLOGW << "Invalid config, using default values";
}
InjectionInfo info = cfg.get_injection_info();
config::print_injection_info(info);
// Attach to JVM
jvm::Jvm jvm;
if (!jvm.attach()) {
PLOGE << "Attach failed";
// Validate injection path early
if (info.JuiceAgentAPIJarPath.empty()) {
PLOGE << "JuiceAgentAPIJarPath is empty, abort injection";
return;
}
// Inject JuiceLoaderAPI.jar
jint status = jvm.get_jvmti()->AddToSystemClassLoaderSearch(info.JuiceAgentAPIJarPath.c_str());
if (status != JNI_OK) {
PLOGE << "AddToSystemClassLoaderSearch failed: " << status;
// Attach to JVM
jvm::Jvm jvm;
if (!jvm.attach()) {
PLOGE << "Attach to JVM failed";
return;
}
auto* jvmti = jvm.get_jvmti();
if (jvmti == nullptr) {
PLOGE << "JVMTI is null";
return;
}
// Inject JuiceAgentAPI.jar
const char* jar_path = info.JuiceAgentAPIJarPath.c_str();
jint status = jvmti->AddToSystemClassLoaderSearch(jar_path);
if (status != JNI_OK) {
PLOGE << "AddToSystemClassLoaderSearch failed: " << status;
return;
}
PLOGI << "Jar injected successfully: " << jar_path;
}
} // namespace libloader
} // namespace libloader