From 35862d7c11c4fb26c01086f308869ad7493a6a5e Mon Sep 17 00:00:00 2001 From: Yaroslavik Date: Thu, 18 Oct 2018 18:20:04 +0200 Subject: [PATCH 1/6] Disable resizable button Why this button if there is not a scalable design? --- Launcher/runtime/init.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Launcher/runtime/init.js b/Launcher/runtime/init.js index 0e0e236b..caa2214d 100644 --- a/Launcher/runtime/init.js +++ b/Launcher/runtime/init.js @@ -14,6 +14,9 @@ var LauncherApp = Java.extend(JSApplication, { }, start: function(primaryStage) { stage = primaryStage; stage.setTitle(config.title); + + // Disable resizable button + stage.setResizable(false); // Set icons for each (var icon in config.icons) { From 4e75894438d099411ea60c4db62be604805159ad Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 22 Oct 2018 14:15:44 +0700 Subject: [PATCH 2/6] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=87=D0=B8?= =?UTF-8?q?=D1=82=D0=B0=20=D0=BD=D0=B0=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=20=D0=B3=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/utils/helper/EnvHelper.java | 63 ++++--------------- 1 file changed, 11 insertions(+), 52 deletions(-) diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java index 9e6d20a9..a64b466a 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java @@ -7,68 +7,27 @@ import java.util.regex.Pattern; public class EnvHelper { - private static final boolean TST; - private static final boolean HASXW; public static final String[] toTest; - public static final Pattern[] test; static { toTest = new String[] { "_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS" }; - test = new Pattern[] { Pattern.compile("-xm.*\\d+[KMG]") }; - TST = check0(); - HASXW = check1(); } public static void addEnv(ProcessBuilder builder) { - if (hasOptsEnv()) { - Map repl = new HashMap<>(); - for (String str : toTest) { - repl.put(str, ""); - repl.put(str.toLowerCase(Locale.US), ""); - } - JVMHelper.appendVars(builder, repl); + Map repl = builder.environment(); + for (String str : toTest) { + repl.put(str, ""); + repl.put(str.toLowerCase(Locale.US), ""); } } - private static boolean check0() { - for (String test : toTest) - if (System.getProperty(test) != null) - return true; - return false; - } - - /** - * Вынужденное решение ибо тест на наличие -Xm* этакой нужен. - */ - private static boolean check1() { - if (hasOptsEnv()) - for (String testStr : toTest) - if (System.getenv(testStr) != null) { - String str = System.getenv(testStr).toLowerCase(Locale.US); - StringTokenizer st = new StringTokenizer(str); - while (st.hasMoreTokens()) - if (CommonHelper.multiMatches(test, st.nextToken())) - return true; - } - return false; - } - public static void checkDangerousParametrs() { - if (hasOptsEnv()) - for (String t : toTest) - if (System.getenv(t) != null) { - String env = System.getenv(t).toLowerCase(Locale.US); - if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent") - || env.contains("-agentpath") || env.contains("-agentlib")) - throw new SecurityException("JavaAgent in global optings not allow"); - } - } - - public static boolean hasOptsEnv() { - return TST; - } - - public static boolean hasWarnPreDef() { - return HASXW; + for (String t : toTest) + if (System.getenv(t) != null) { + String env = System.getenv(t).toLowerCase(Locale.US); + if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent") + || env.contains("-agentpath") || env.contains("-agentlib")) + throw new SecurityException("JavaAgent in global optings not allow"); + } } } From 761ddc3087c122fbab90e178b7079c820592d06c Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 22 Oct 2018 18:05:10 +0700 Subject: [PATCH 3/6] =?UTF-8?q?=D0=AD=D0=BA=D1=81=D0=BF=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D0=B0=20=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D0=B5=20StackTrace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ru/gravit/launchserver/LaunchServer.java | 1 + .../src/main/java/ru/gravit/launcher/LauncherEngine.java | 1 + .../java/ru/gravit/launcher/client/ClientLauncher.java | 1 + .../src/main/java/ru/gravit/utils/helper/JVMHelper.java | 9 +++++++++ 4 files changed, 12 insertions(+) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 9e458841..d9cb4933 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -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"); diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 40a033bd..e541007b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -148,6 +148,7 @@ public static void addLauncherClassBindings(Map bindings) { } public static void main(String... args) throws Throwable { + JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.verifySystemProperties(Launcher.class, true); EnvHelper.checkDangerousParametrs(); LogHelper.printVersion("Launcher"); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index d00431ac..1cc236e2 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -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"); diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index 446183ae..3e88ab7d 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -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() { From 300e8cfcec55d878fb7f78363b8cd91bec6e2fd2 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 22 Oct 2018 18:38:01 +0700 Subject: [PATCH 4/6] =?UTF-8?q?=D0=AD=D0=BA=D1=81=D0=BF=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20ClientLauncherWrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/build.gradle | 2 +- .../launcher/ClientLauncherWrapper.java | 48 +++++++++++++++++++ .../ru/gravit/launcher/LauncherEngine.java | 4 +- .../ru/gravit/utils/helper/JVMHelper.java | 2 +- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 0990074d..0103a307 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -1,4 +1,4 @@ -String mainClassName = "ru.gravit.launcher.LauncherEngine" +String mainClassName = "ru.gravit.launcher.ClientLauncherWrapper" String mainAgentName = "ru.gravit.launcher.LauncherAgent" diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java new file mode 100644 index 00000000..dbea8921 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -0,0 +1,48 @@ +package ru.gravit.launcher; + +import ru.gravit.launcher.client.ClientLauncher; +import ru.gravit.utils.helper.EnvHelper; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; +import ru.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class ClientLauncherWrapper { + @LauncherAPI + public static void main(String[] arguments) throws IOException, InterruptedException { + LogHelper.printVersion("Launcher"); + JVMHelper.checkStackTrace(ClientLauncherWrapper.class); + JVMHelper.verifySystemProperties(Launcher.class, true); + EnvHelper.checkDangerousParametrs(); + LogHelper.debug("Restart Launcher"); + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.inheritIO(); + Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + List args = new LinkedList<>(); + args.add(javaBin.toString()); + String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); + Collections.addAll(args, "-javaagent:".concat(pathLauncher)); + Collections.addAll(args, LauncherEngine.class.getName()); + EnvHelper.addEnv(processBuilder); + processBuilder.command(args); + Process process = processBuilder.start(); + if(!LogHelper.isDebugEnabled()) { + Thread.sleep(3000); + if (!process.isAlive()) { + LogHelper.error("Process error code: %d", process.exitValue()); + } else { + LogHelper.debug("Process started success"); + } + } + else + { + process.waitFor(); + } + } +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index e541007b..7d1ad60f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -4,10 +4,10 @@ import java.io.IOException; import java.net.URL; import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.time.Instant; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import javax.script.Bindings; diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index 3e88ab7d..a23f8c67 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -140,7 +140,7 @@ public static void checkStackTrace(Class mainClass) StackTraceElement[] list = e.getStackTrace(); if(!list[list.length - 1].getClassName().equals(mainClass.getName())) { - throw new SecurityException(String.format("Invalid StackTraceElement: %s",list[0].getClassName())); + throw new SecurityException(String.format("Invalid StackTraceElement: %s",list[list.length - 1].getClassName())); } } From ec3a1d9bb07303187787ff79772d8b02805a2d1a Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 22 Oct 2018 18:47:26 +0700 Subject: [PATCH 5/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D0=B0=20launcher.debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index dbea8921..053e334f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -29,6 +29,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, LauncherEngine.class.getName()); + args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); EnvHelper.addEnv(processBuilder); processBuilder.command(args); Process process = processBuilder.start(); From 4c629fb930f84dd3706abf76a0a9bbfce2fed383 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 22 Oct 2018 18:53:01 +0700 Subject: [PATCH 6/6] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?=20=D1=83=D1=81=D1=82=D0=B0=D1=80=D0=B5=D0=B2=D1=88=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/LauncherEngine.java | 1 + .../java/ru/gravit/launcher/LauncherAgent.java | 4 ++++ .../java/ru/gravit/utils/helper/JVMHelper.java | 18 ------------------ 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 7d1ad60f..b35f5e40 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -151,6 +151,7 @@ public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.verifySystemProperties(Launcher.class, true); EnvHelper.checkDangerousParametrs(); + if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); LogHelper.printVersion("Launcher"); // Start Launcher Instant start = Instant.now(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java index 6a80b2d3..9786c9c8 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java @@ -50,4 +50,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation } } } + public static boolean isStarted() + { + return isAgentStarted; + } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index a23f8c67..2165d916 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -71,18 +71,6 @@ public static OS byName(String name) { } } - @Deprecated - - public static void addClassPath(URL url) { - throw new IllegalArgumentException("Method Deprecated"); - } - - @Deprecated - - public static void addNativePath(Path path) { - throw new IllegalArgumentException("Method Deprecated"); - } - public static void appendVars(ProcessBuilder builder, Map vars) { builder.environment().putAll(vars); @@ -106,12 +94,6 @@ public static void fullGC() { LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20); } - @Deprecated - - public static Certificate[] getCertificates(String resource) { - throw new IllegalArgumentException("Method Deprecated"); - } - public static String[] getClassPath() { return System.getProperty("java.class.path").split(File.pathSeparator);