Procházet zdrojové kódy

[core] Service alert

Karlatemp před 2 roky
rodič
revize
804cb8b12d

+ 24 - 1
mirai-core/src/commonMain/kotlin/spi/EncryptService.kt

@@ -86,8 +86,31 @@ public interface EncryptService : BaseService {
     public companion object {
         private val loader = SpiServiceLoader(EncryptService::class)
 
+        private val warningAlert: Unit by lazy {
+            val log = MiraiLogger.Factory.create(EncryptService::class, "EncryptService.alert")
+
+            val serviceUsed = loader.service
+
+            if (serviceUsed != null) {
+                val serviceClass = serviceUsed.javaClass
+                log.warning { "Encrypt service was loaded: $serviceUsed" }
+                log.warning { "All outgoing message may be leaked by this service." }
+                log.warning { "Use this service if and only if you trusted this service and the service provider." }
+                log.warning { "Service details:" }
+                log.warning { "  `- Jvm Class: $serviceClass" }
+                log.warning { "  `- ClassLoader: " + serviceClass.classLoader }
+                log.warning { "  `- Source: " + serviceClass.protectionDomain?.codeSource?.location }
+                log.warning { "  `- Protected Domain: " + serviceClass.protectionDomain }
+            }
+
+        }
+
         @GlobalEncryptServiceUsage
-        internal val instance: EncryptService? get() = loader.service
+        internal val instance: EncryptService?
+            get() {
+                warningAlert
+                return loader.service
+            }
     }
 
 }