Экспериментальная защита на основе StackTrace

This commit is contained in:
Gravit 2018-10-22 18:05:10 +07:00
parent 4e75894438
commit 761ddc3087
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 12 additions and 0 deletions

View file

@ -263,6 +263,7 @@ private SignConf(BlockConfigEntry block, Path coredir) {
}
public static void main(String... args) throws Throwable {
JVMHelper.checkStackTrace(LaunchServer.class);
JVMHelper.verifySystemProperties(LaunchServer.class, true);
LogHelper.addOutput(IOHelper.WORKING_DIR.resolve("LaunchServer.log"));
LogHelper.printVersion("LaunchServer");

View file

@ -148,6 +148,7 @@ public static void addLauncherClassBindings(Map<String, Object> bindings) {
}
public static void main(String... args) throws Throwable {
JVMHelper.checkStackTrace(LauncherEngine.class);
JVMHelper.verifySystemProperties(Launcher.class, true);
EnvHelper.checkDangerousParametrs();
LogHelper.printVersion("Launcher");

View file

@ -416,6 +416,7 @@ public static void main(String... args) throws Throwable {
checkJVMBitsAndVersion();
JVMHelper.verifySystemProperties(ClientLauncher.class, true);
EnvHelper.checkDangerousParametrs();
JVMHelper.checkStackTrace(ClientLauncher.class);
LogHelper.printVersion("Client Launcher");
// Read and delete params file
LogHelper.debug("Reading ClientLauncher params");

View file

@ -134,6 +134,15 @@ public static URL[] getClassPathURL() {
}
return list;
}
public static void checkStackTrace(Class mainClass)
{
Exception e = new Exception("Testing stacktrace");
StackTraceElement[] list = e.getStackTrace();
if(!list[list.length - 1].getClassName().equals(mainClass.getName()))
{
throw new SecurityException(String.format("Invalid StackTraceElement: %s",list[0].getClassName()));
}
}
@SuppressWarnings("CallToSystemGetenv")
private static int getCorrectOSArch() {