[FEATURE] Тестовый SecurityManager для ловли System.exit

This commit is contained in:
Gravit 2019-10-22 01:12:08 +07:00
parent fb21aeb888
commit e002d1a7e9
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 30 additions and 0 deletions

View file

@ -442,6 +442,7 @@ public static void main(String... args) throws Throwable {
EnvHelper.checkDangerousParams(); EnvHelper.checkDangerousParams();
JVMHelper.checkStackTrace(ClientLauncher.class); JVMHelper.checkStackTrace(ClientLauncher.class);
LogHelper.printVersion("Client Launcher"); LogHelper.printVersion("Client Launcher");
System.setSecurityManager(new ClientSecurityManager());
engine.readKeys(); engine.readKeys();
HWIDProvider.registerHWIDs(); HWIDProvider.registerHWIDs();
LauncherGuardManager.initGuard(true); LauncherGuardManager.initGuard(true);

View file

@ -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 {
}
}