From 3bfed5c3c7152645446c93e7391f7421b8262dfd Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 17 Dec 2019 11:37:21 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A1=D0=BE=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0,=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B8=D1=81=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B8=20exit/setSecurityManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherEngine.java | 18 ++++++++++++- .../pro/gravit/launcher/api/AuthService.java | 2 ++ .../gravit/launcher/api/SystemService.java | 25 +++++++++++++++++++ .../launcher/client/ClientLauncher.java | 1 + .../client/events/ClientExitPhase.java | 11 ++++++++ .../launcher/profiles/ClientProfile.java | 12 +++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index d8070087..f2c2421e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,7 +1,9 @@ package pro.gravit.launcher; +import pro.gravit.launcher.api.SystemService; import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.events.ClientEngineInitPhase; +import pro.gravit.launcher.client.events.ClientExitPhase; import pro.gravit.launcher.client.events.ClientPreGuiPhase; import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.gui.NoRuntimeProvider; @@ -10,11 +12,13 @@ import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ConsoleManager; +import pro.gravit.launcher.modules.events.ClosePhase; import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.auth.RestoreSessionRequest; import pro.gravit.launcher.request.websockets.StdWebSocketService; +import pro.gravit.launcher.utils.NativeJVMHalt; import pro.gravit.utils.helper.*; import java.io.IOException; @@ -53,6 +57,18 @@ public static void checkClass(Class clazz) throws SecurityException { } } + public static void exitLauncher(int code) + { + modulesManager.invokeEvent(new ClientExitPhase(code)); + try { + System.exit(code); + } catch (Exception e) //Forge Security Manager? + { + NativeJVMHalt.haltA(code); + } + + } + public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.verifySystemProperties(Launcher.class, true); @@ -84,7 +100,7 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Launcher started in %dms", endTime - startTime); //Request.service.close(); //FunctionalBridge.close(); - System.exit(0); + SystemService.exit(0); } public static void initGson(ClientModuleManager modulesManager) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java b/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java index 009b99cf..b6e08d02 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java +++ b/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java @@ -1,6 +1,7 @@ package pro.gravit.launcher.api; import pro.gravit.launcher.ClientPermissions; +import pro.gravit.launcher.profiles.ClientProfile; import java.util.UUID; @@ -8,6 +9,7 @@ public class AuthService { public static String username; public static ClientPermissions permissions = new ClientPermissions(); public static UUID uuid; + public static ClientProfile profile; public static boolean isAdmin() { return permissions.canAdmin; diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java new file mode 100644 index 00000000..170cfaf4 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java @@ -0,0 +1,25 @@ +package pro.gravit.launcher.api; + +import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.utils.helper.LogHelper; + +public class SystemService { + private SystemService() { + throw new UnsupportedOperationException(); + } + public static void exit(int code) + { + LauncherEngine.exitLauncher(code); + } + public static void setSecurityManager(SecurityManager s) + { + LogHelper.debug("Try set security manager %s", s == null ? "null" : s.getClass().getName()); + if(AuthService.profile == null || AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.NONE) return; + if(AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.CLIENT) + { + System.setSecurityManager(s); + } + //TODO NEXT + } +} 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 046ebf9c..9fe5a32e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -463,6 +463,7 @@ public static void main(String... args) throws Throwable { HashedDir assetHDir = p.assetHDir, clientHDir = p.clientHDir; ClientLaunchContext context = new ClientLaunchContext(params, profile, assetHDir, clientHDir); Launcher.profile = profile; + AuthService.profile = profile; playerProfile = params.pp; Request.setSession(params.session); checkJVMBitsAndVersion(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java new file mode 100644 index 00000000..230ea6d8 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.client.events; + +import pro.gravit.launcher.modules.events.ClosePhase; + +public class ClientExitPhase extends ClosePhase { + public final int code; + + public ClientExitPhase(int code) { + this.code = code; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 92435b5a..b5200379 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -69,6 +69,14 @@ public String toString() { } public static final boolean profileCaseSensitive = Boolean.getBoolean("launcher.clientProfile.caseSensitive"); + public enum SecurityManagerConfig + { + NONE, CLIENT, LAUNCHER, MIXED + } + public enum ClassLoaderConfig + { + AGENT, LAUNCHER + } private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); @@ -122,6 +130,10 @@ public String toString() { private final List clientArgs = new ArrayList<>(); @LauncherNetworkAPI private final List whitelist = new ArrayList<>(); + @LauncherNetworkAPI + public SecurityManagerConfig securityManagerConfig = SecurityManagerConfig.CLIENT; + @LauncherNetworkAPI + public ClassLoaderConfig classLoaderConfig = ClassLoaderConfig.LAUNCHER; @Override public int compareTo(ClientProfile o) {