From 56a1c32f49b13865d2eb51e8b3c763593e9495a2 Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Wed, 14 Oct 2026 21:46:18 +0800 Subject: [PATCH] Feat: add Enabled flag for JarLoader module - libagent: gate JarLoaderService::onLoaded on the JarLoader.Enabled key (default false) so the module can be turned off from config - examples: set Enabled = true in inject-via-java-api, load-via-injector-exe and retransform-class config.toml --- examples/inject-via-java-api/config.toml | 1 + examples/load-via-injector-exe/config.toml | 1 + examples/retransform-class/config.toml | 1 + src/libagent/services/JarLoaderService.cpp | 8 ++++++++ 4 files changed, 11 insertions(+) diff --git a/examples/inject-via-java-api/config.toml b/examples/inject-via-java-api/config.toml index 107c392..7b02b71 100644 --- a/examples/inject-via-java-api/config.toml +++ b/examples/inject-via-java-api/config.toml @@ -9,6 +9,7 @@ JuiceAgentNativeLibraryPath = "" # 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 +Enabled = true Mode = "BuiltIn" # InjectionDir only works when Mode is BuiltIn diff --git a/examples/load-via-injector-exe/config.toml b/examples/load-via-injector-exe/config.toml index 107c392..7b02b71 100644 --- a/examples/load-via-injector-exe/config.toml +++ b/examples/load-via-injector-exe/config.toml @@ -9,6 +9,7 @@ JuiceAgentNativeLibraryPath = "" # 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 +Enabled = true Mode = "BuiltIn" # InjectionDir only works when Mode is BuiltIn diff --git a/examples/retransform-class/config.toml b/examples/retransform-class/config.toml index 131436b..b5213ff 100644 --- a/examples/retransform-class/config.toml +++ b/examples/retransform-class/config.toml @@ -9,6 +9,7 @@ JuiceAgentNativeLibraryPath = "" # 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 +Enabled = true Mode = "BuiltIn" # InjectionDir only works when Mode is BuiltIn diff --git a/src/libagent/services/JarLoaderService.cpp b/src/libagent/services/JarLoaderService.cpp index 804f4c4..76fdbdc 100644 --- a/src/libagent/services/JarLoaderService.cpp +++ b/src/libagent/services/JarLoaderService.cpp @@ -35,6 +35,14 @@ private: auto& agent = Agent::getInstance(); auto& cfg = agent.getConfig(); + const bool enabled = cfg.get( + "JarLoader.Enabled", false); + + if (!enabled) { + spdlog::info("[JarLoaderService] Disabled by config"); + return; + } + const std::string injection_dir = cfg.getPath( "JarLoader.InjectionDir", (cfg.getRuntimeDir() / "injection").string()