mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
feat: remove JuiceAgentAPIJarPath from LoaderConfig and update loader logic to use temporary file
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
1 parent
75062b805c
commit
e2d6dcaa25
3 files changed
+13
-12
No files matched your search
@@ -130,7 +130,6 @@ namespace Utils {
|
|||||||
auto cfg = config.get_config().at("JuiceAgent").at("Loader");
|
auto cfg = config.get_config().at("JuiceAgent").at("Loader");
|
||||||
|
|
||||||
LoaderConfig loader_config = LoaderConfig();
|
LoaderConfig loader_config = LoaderConfig();
|
||||||
loader_config.JuiceAgentAPIJarPath = cfg.at("JuiceAgentAPIJarPath").as_string();
|
|
||||||
loader_config.JuiceAgentNativeLibraryPath = cfg.at("JuiceAgentNativeLibraryPath").as_string();
|
loader_config.JuiceAgentNativeLibraryPath = cfg.at("JuiceAgentNativeLibraryPath").as_string();
|
||||||
loader_config.RuntimeDir = config.runtime_dir().string();
|
loader_config.RuntimeDir = config.runtime_dir().string();
|
||||||
|
|
||||||
@@ -138,7 +137,6 @@ namespace Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void print_loader_config(const LoaderConfig& config) {
|
inline void print_loader_config(const LoaderConfig& config) {
|
||||||
PLOGI << "JuiceAgentAPIJarPath: " << config.JuiceAgentAPIJarPath;
|
|
||||||
PLOGI << "JuiceAgentNativeLibraryPath: " << config.JuiceAgentNativeLibraryPath;
|
PLOGI << "JuiceAgentNativeLibraryPath: " << config.JuiceAgentNativeLibraryPath;
|
||||||
PLOGI << "RuntimeDir: " << config.RuntimeDir;
|
PLOGI << "RuntimeDir: " << config.RuntimeDir;
|
||||||
}
|
}
|
||||||
@@ -153,7 +151,6 @@ namespace Utils {
|
|||||||
|
|
||||||
JuiceAgent::Utils::Serializer ser;
|
JuiceAgent::Utils::Serializer ser;
|
||||||
ser.add_kv("Version", 2);
|
ser.add_kv("Version", 2);
|
||||||
ser.add_kv("JuiceAgentAPIJarPath", config.JuiceAgentAPIJarPath);
|
|
||||||
ser.add_kv("JuiceAgentNativeLibraryPath", config.JuiceAgentNativeLibraryPath);
|
ser.add_kv("JuiceAgentNativeLibraryPath", config.JuiceAgentNativeLibraryPath);
|
||||||
ser.add_kv("RuntimeDir", config.RuntimeDir);
|
ser.add_kv("RuntimeDir", config.RuntimeDir);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct LoaderConfig {
|
struct LoaderConfig {
|
||||||
std::string JuiceAgentAPIJarPath;
|
|
||||||
std::string JuiceAgentNativeLibraryPath;
|
std::string JuiceAgentNativeLibraryPath;
|
||||||
|
|
||||||
std::string RuntimeDir;
|
std::string RuntimeDir;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <JuiceAgent/Config.hpp>
|
#include <JuiceAgent/Config.hpp>
|
||||||
#include <JvmManager.hpp>
|
#include <JvmManager.hpp>
|
||||||
#include <JuiceAgent/Utils.hpp>
|
#include <JuiceAgent/Utils.hpp>
|
||||||
|
#include <JuiceAgent/JuiceAgent-API-1.4.1+build.1.hpp>
|
||||||
|
|
||||||
namespace JuiceAgent::Loader {
|
namespace JuiceAgent::Loader {
|
||||||
|
|
||||||
@@ -69,12 +70,16 @@ void entrypoint(const char* runtime_dir) {
|
|||||||
LoaderConfig config = JuiceAgent::Config::Utils::get_loader_config(cfg);
|
LoaderConfig config = JuiceAgent::Config::Utils::get_loader_config(cfg);
|
||||||
JuiceAgent::Config::Utils::print_loader_config(config);
|
JuiceAgent::Config::Utils::print_loader_config(config);
|
||||||
|
|
||||||
// Validate essential paths
|
// Save bytes to file
|
||||||
if (config.JuiceAgentAPIJarPath.empty()) {
|
std::string juiceagent_api_path = JuiceAgent::Utils::File::write_to_tempfile(
|
||||||
PLOGE << "JuiceAgentAPIJarPath is empty, abort injection";
|
JuiceAgent::Resource::juiceagent_api_bytes,
|
||||||
return;
|
JuiceAgent::Resource::juiceagent_api_bytes_len,
|
||||||
}
|
JuiceAgent::Resource::juiceagent_api_bytes_name
|
||||||
|
);
|
||||||
|
PLOGD << "Saved JuiceAgent-API to: " << juiceagent_api_path;
|
||||||
|
PLOGD << "JuiceAgent-API size: " << JuiceAgent::Resource::juiceagent_api_bytes_len;
|
||||||
|
PLOGD << "JuiceAgent-API SHA256: " << JuiceAgent::Resource::juiceagent_api_bytes_sha256;
|
||||||
|
|
||||||
// Attach to JVM
|
// Attach to JVM
|
||||||
JuiceAgent::Loader::JvmManager::Jvm jvm;
|
JuiceAgent::Loader::JvmManager::Jvm jvm;
|
||||||
if (!jvm.attach()) {
|
if (!jvm.attach()) {
|
||||||
@@ -91,13 +96,13 @@ void entrypoint(const char* runtime_dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inject JuiceAgent jar into system class loader
|
// Inject JuiceAgent jar into system class loader
|
||||||
jint status = jvmti->AddToSystemClassLoaderSearch(config.JuiceAgentAPIJarPath.c_str());
|
jint status = jvmti->AddToSystemClassLoaderSearch(juiceagent_api_path.c_str());
|
||||||
if (status != JNI_OK) {
|
if (status != JNI_OK) {
|
||||||
PLOGE << "AddToSystemClassLoaderSearch failed: " << status;
|
PLOGE << "AddToSystemClassLoaderSearch failed: " << status;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PLOGI << "Jar injected successfully: " << config.JuiceAgentAPIJarPath;
|
PLOGI << "Jar injected successfully: " << juiceagent_api_path;
|
||||||
|
|
||||||
// Invoke JuiceAgent initialization
|
// Invoke JuiceAgent initialization
|
||||||
if (!invoke_juiceagent_init(env, config)) {
|
if (!invoke_juiceagent_init(env, config)) {
|
||||||
|
|||||||
Reference in new issue
Block a user