mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
Feat: migrate libagent from JuiceAgent and port to spdlog
This commit is contained in:
1 parent
bcc1ecbf0e
commit
1d3755952f
22 files changed
+1727
-12
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <JuiceAgent.hpp>
|
||||
|
||||
// This function is called by Java to initialize the agent.
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_init
|
||||
(JNIEnv *env, jclass , jstring j_runtime_dir) {
|
||||
Logger::init("libagent.log");
|
||||
|
||||
spdlog::info("Initializing JuiceAgent...");
|
||||
|
||||
// Get runtime directory
|
||||
const char* c_runtime_dir = env->GetStringUTFChars(j_runtime_dir, nullptr);
|
||||
std::string runtime_dir(c_runtime_dir);
|
||||
env->ReleaseStringUTFChars(j_runtime_dir, c_runtime_dir);
|
||||
|
||||
if (runtime_dir.empty()) {
|
||||
spdlog::error("Failed to get runtime directory from argument, runtime_dir is empty");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
spdlog::info("JuiceAgent got runtime directory: {}", runtime_dir);
|
||||
|
||||
JavaVM* jvm = nullptr;
|
||||
jvmtiEnv* jvmti = nullptr;
|
||||
|
||||
// Get Java VM
|
||||
env->GetJavaVM(&jvm);
|
||||
if (jvm == nullptr) {
|
||||
spdlog::error("Failed to get JavaVM instance");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Get JVMTI
|
||||
jvmtiError err = static_cast<jvmtiError>(jvm->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_2));
|
||||
if (err != JVMTI_ERROR_NONE || jvmti == nullptr) {
|
||||
spdlog::error("Failed to get JVMTI environment, error: {}", static_cast<int>(err));
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Invoke EntryPoint
|
||||
JuiceAgent::Agent& agent = JuiceAgent::Agent::instance();
|
||||
agent.init(jvm, env, jvmti, runtime_dir);
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
Reference in new issue
Block a user