mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] Тестовый SecurityManager для ловли System.exit
This commit is contained in:
parent
fb21aeb888
commit
e002d1a7e9
2 changed files with 30 additions and 0 deletions
|
@ -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);
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue