From e002d1a7e9f67f0c104ee7056df228ee6685db0e Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 22 Oct 2019 01:12:08 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A2=D0=B5=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B9=20SecurityManager=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=D0=BB=D0=B8=20System.exit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientLauncher.java | 1 + .../client/ClientSecurityManager.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 79959151..dee3cd85 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -442,6 +442,7 @@ public static void main(String... args) throws Throwable { EnvHelper.checkDangerousParams(); JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); + System.setSecurityManager(new ClientSecurityManager()); engine.readKeys(); HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java new file mode 100644 index 00000000..28b4ab01 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java @@ -0,0 +1,29 @@ +package pro.gravit.launcher.client; + +import java.security.Permission; + +public class ClientSecurityManager extends SecurityManager { + @Override + public void checkPermission(Permission perm) + { + String permName = perm.getName(); + if(permName == null) return; + if (permName.startsWith("exitVM")) + { + Class[] classContexts = getClassContext(); + String callingClass = classContexts.length > 3 ? classContexts[4].getName() : "none"; + if (!(callingClass.startsWith("pro.gravit."))) + { + throw new ExitTrappedException(); + } + } + } + + @Override + public void checkPermission(Permission perm, Object context) { + } + + public static class ExitTrappedException extends SecurityException { + + } +}