mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Refactor: migrate config to v2 format across examples and libagent
- examples: update config.toml to the v2 schema ([JarLoader] with Mode / InjectionDir / JarPath / EntryClass / EntryMethod) for inject-via-java-api, load-via-injector-exe and retransform-class - libagent: read JarLoader.* instead of JuiceAgent.Modules.JarLoader.*, use Config::isValid() and the new get()/getPath() accessors - libagent: rename call_java_impl to call_static_java_method
This commit is contained in:
1 parent
eb7fd31817
commit
f38a28e8b3
5 files changed
+47
-57
No files matched your search
@@ -1,14 +1,18 @@
|
||||
[JuiceAgent]
|
||||
Version = 1
|
||||
# See config.md for more information https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/config.md
|
||||
|
||||
[JuiceAgent.Loader]
|
||||
[JuiceAgent]
|
||||
Version = 2
|
||||
JuiceAgentNativeLibraryPath = ""
|
||||
|
||||
[JuiceAgent.Modules]
|
||||
[JarLoader]
|
||||
# Mode: BuiltIn, CustomJar
|
||||
# BuiltIn: Use the built-in jar loader (recommended, support JuiceAgent-API ( https://github.com/xiaozhou233/JuiceAgent#juiceagent-api ))
|
||||
# CustomJar: Load the Jar directly, without using JuiceAgent-API
|
||||
# For more information, please refer to the documentation: https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/advanced.md#load-custom-api--directly-load-jar
|
||||
Mode = "BuiltIn"
|
||||
|
||||
[JuiceAgent.Modules.JarLoader]
|
||||
Enabled = true
|
||||
# InjectionDir only works when Mode is BuiltIn
|
||||
InjectionDir = "./injection"
|
||||
JarPath = "./demo.jar"
|
||||
EntryClass = "Example.Main"
|
||||
EntryMethod = "run"
|
||||
EntryMethod = "run"
|
||||
@@ -1,21 +1,18 @@
|
||||
[JuiceAgent]
|
||||
Version = 1
|
||||
# See config.md for more information https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/config.md
|
||||
|
||||
[JuiceAgent.Loader]
|
||||
# Path to JuiceAgent-API jar, leave empty to use the built-in API
|
||||
JuiceAgentAPIJarPath = ""
|
||||
# Path to libagent.dll, default is "./libagent.dll"
|
||||
[JuiceAgent]
|
||||
Version = 2
|
||||
JuiceAgentNativeLibraryPath = ""
|
||||
|
||||
[JuiceAgent.Modules]
|
||||
[JarLoader]
|
||||
# Mode: BuiltIn, CustomJar
|
||||
# BuiltIn: Use the built-in jar loader (recommended, support JuiceAgent-API ( https://github.com/xiaozhou233/JuiceAgent#juiceagent-api ))
|
||||
# CustomJar: Load the Jar directly, without using JuiceAgent-API
|
||||
# For more information, please refer to the documentation: https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/advanced.md#load-custom-api--directly-load-jar
|
||||
Mode = "BuiltIn"
|
||||
|
||||
[JuiceAgent.Modules.JarLoader]
|
||||
Enabled = true
|
||||
# Directory containing dependency JARs to load into the JVM (put your deps here)
|
||||
# InjectionDir only works when Mode is BuiltIn
|
||||
InjectionDir = "./injection"
|
||||
# Path to the injection JAR to be loaded
|
||||
JarPath = "./demo.jar"
|
||||
# Entry class to be executed after loading the JAR
|
||||
EntryClass = "Example.Main"
|
||||
# Entry method, must be: public static void run()
|
||||
EntryMethod = "run"
|
||||
@@ -1,21 +1,18 @@
|
||||
[JuiceAgent]
|
||||
Version = 1
|
||||
# See config.md for more information https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/config.md
|
||||
|
||||
[JuiceAgent.Loader]
|
||||
# Path to JuiceAgent-API jar, leave empty to use the built-in API
|
||||
JuiceAgentAPIJarPath = ""
|
||||
# Path to libagent.dll, default is "./libagent.dll"
|
||||
[JuiceAgent]
|
||||
Version = 2
|
||||
JuiceAgentNativeLibraryPath = ""
|
||||
|
||||
[JuiceAgent.Modules]
|
||||
[JarLoader]
|
||||
# Mode: BuiltIn, CustomJar
|
||||
# BuiltIn: Use the built-in jar loader (recommended, support JuiceAgent-API ( https://github.com/xiaozhou233/JuiceAgent#juiceagent-api ))
|
||||
# CustomJar: Load the Jar directly, without using JuiceAgent-API
|
||||
# For more information, please refer to the documentation: https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/advanced.md#load-custom-api--directly-load-jar
|
||||
Mode = "BuiltIn"
|
||||
|
||||
[JuiceAgent.Modules.JarLoader]
|
||||
Enabled = true
|
||||
# Directory containing dependency JARs to load into the JVM (put your deps here)
|
||||
# InjectionDir only works when Mode is BuiltIn
|
||||
InjectionDir = "./injection"
|
||||
# Path to the injection JAR to be loaded
|
||||
JarPath = "./playload.jar"
|
||||
# Entry class to be executed after loading the JAR
|
||||
EntryClass = "playload"
|
||||
# Entry method, must be: public static void run()
|
||||
EntryMethod = "entry"
|
||||
@@ -38,7 +38,7 @@ namespace JuiceAgent {
|
||||
} else {
|
||||
JuiceAgent::Config::Config cfg(runtime_dir);
|
||||
setConfig(cfg);
|
||||
if(!getConfig().is_valid()) {
|
||||
if(!getConfig().isValid()) {
|
||||
spdlog::warn("[JuiceAgent] Config is not valid!");
|
||||
spdlog::warn("[JuiceAgent] No config provided, Modules will not be loaded!");
|
||||
}
|
||||
|
||||
@@ -35,33 +35,25 @@ private:
|
||||
auto& agent = Agent::getInstance();
|
||||
auto& cfg = agent.getConfig();
|
||||
|
||||
const bool enabled = cfg.get<bool>(
|
||||
"JuiceAgent.Modules.JarLoader.Enabled", false);
|
||||
const std::string injection_dir = cfg.getPath(
|
||||
"JarLoader.InjectionDir",
|
||||
(cfg.getRuntimeDir() / "injection").string()
|
||||
);
|
||||
|
||||
if (!enabled) {
|
||||
spdlog::info("[JarLoaderService] Disabled by config");
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string injection_dir = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.InjectionDir",
|
||||
(cfg.runtime_dir() / "injection").string(),
|
||||
true);
|
||||
|
||||
const std::string jar_path = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.JarPath",
|
||||
(cfg.runtime_dir() / "Entry.jar").string(),
|
||||
true);
|
||||
const std::string jar_path = cfg.getPath(
|
||||
"JarLoader.JarPath",
|
||||
(cfg.getRuntimeDir() / "Entry.jar").string()
|
||||
);
|
||||
|
||||
const std::string entry_class = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.EntryClass",
|
||||
"Example.Main",
|
||||
false);
|
||||
"JarLoader.EntryClass",
|
||||
"Example.Main"
|
||||
);
|
||||
|
||||
const std::string entry_method = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.EntryMethod",
|
||||
"start",
|
||||
false);
|
||||
"JarLoader.EntryMethod",
|
||||
"start"
|
||||
);
|
||||
|
||||
JuiceAgent::Utils::Serializer ser;
|
||||
ser.add_kv("InjectionDir", injection_dir);
|
||||
@@ -78,7 +70,7 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
bool result = JuiceAgent::Utils::call_java_impl(
|
||||
bool result = JuiceAgent::Utils::call_static_java_method(
|
||||
env, MODULE_CLASS, MODULE_METHOD, data.c_str());
|
||||
|
||||
if (!result) {
|
||||
|
||||
Reference in new issue
Block a user