diff --git a/examples/inject-via-java-api/config.toml b/examples/inject-via-java-api/config.toml index 1abf9cd..107c392 100644 --- a/examples/inject-via-java-api/config.toml +++ b/examples/inject-via-java-api/config.toml @@ -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" \ No newline at end of file +EntryMethod = "run" diff --git a/examples/load-via-injector-exe/config.toml b/examples/load-via-injector-exe/config.toml index e2f3f1d..107c392 100644 --- a/examples/load-via-injector-exe/config.toml +++ b/examples/load-via-injector-exe/config.toml @@ -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" diff --git a/examples/retransform-class/config.toml b/examples/retransform-class/config.toml index 064abf7..131436b 100644 --- a/examples/retransform-class/config.toml +++ b/examples/retransform-class/config.toml @@ -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" diff --git a/src/libagent/JuiceAgent.cpp b/src/libagent/JuiceAgent.cpp index a3f3180..5776db9 100644 --- a/src/libagent/JuiceAgent.cpp +++ b/src/libagent/JuiceAgent.cpp @@ -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!"); } diff --git a/src/libagent/services/JarLoaderService.cpp b/src/libagent/services/JarLoaderService.cpp index 19ce33a..804f4c4 100644 --- a/src/libagent/services/JarLoaderService.cpp +++ b/src/libagent/services/JarLoaderService.cpp @@ -35,33 +35,25 @@ private: auto& agent = Agent::getInstance(); auto& cfg = agent.getConfig(); - const bool enabled = cfg.get( - "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( - "JuiceAgent.Modules.JarLoader.InjectionDir", - (cfg.runtime_dir() / "injection").string(), - true); - - const std::string jar_path = cfg.get( - "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( - "JuiceAgent.Modules.JarLoader.EntryClass", - "Example.Main", - false); + "JarLoader.EntryClass", + "Example.Main" + ); const std::string entry_method = cfg.get( - "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) {