diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index e788bf37..5e4e214e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -4,7 +4,10 @@ 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.LauncherGuardInterface; import pro.gravit.launcher.guard.LauncherGuardManager; +import pro.gravit.launcher.guard.LauncherNoGuard; +import pro.gravit.launcher.guard.LauncherWrapperGuard; import pro.gravit.launcher.gui.NoRuntimeProvider; import pro.gravit.launcher.gui.RuntimeProvider; import pro.gravit.launcher.managers.ClientGsonManager; @@ -40,6 +43,7 @@ public static X509Certificate[] getCertificates(Class clazz) { public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); public static ClientLauncherProcess.ClientParams clientParams; + public static LauncherGuardInterface guard; public static void checkClass(Class clazz) throws SecurityException { LauncherTrustManager trustManager = Launcher.getConfig().trustManager; @@ -146,6 +150,7 @@ private LauncherEngine() { public void start(String... args) throws Throwable { //Launcher.modulesManager = new ClientModuleManager(this); + LauncherEngine.guard = tryGetStdGuard(); ClientPreGuiPhase event = new ClientPreGuiPhase(null); LauncherEngine.modulesManager.invokeEvent(event); runtimeProvider = event.runtimeProvider; @@ -186,6 +191,18 @@ public void start(String... args) throws Throwable { runtimeProvider.run(args); } + public static LauncherGuardInterface tryGetStdGuard() + { + switch (Launcher.getConfig().guardType) + { + case "no": + return new LauncherNoGuard(); + case "wrapper": + return new LauncherWrapperGuard(); + } + return null; + } + public static LauncherEngine clientInstance() { return new LauncherEngine(); } 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 8e9a4593..57f2b321 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -41,14 +41,9 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; - +@Deprecated public final class ClientLauncher { - - public static int getClientJVMBits() { - return LauncherGuardManager.guard.getClientJVMBits(); - } - private static final class ClassPathFileVisitor extends SimpleFileVisitor { private final Stream.Builder result; @@ -336,7 +331,7 @@ public static Process launch( container.write(new ParamContainer(params, profile, assetHDir, clientHDir)); checkJVMBitsAndVersion(); LogHelper.debug("Resolving JVM binary"); - Path javaBin = LauncherGuardManager.getGuardJavaBinPath(); + Path javaBin = null; context.javaBin = javaBin; context.clientProfile = profile; context.playerProfile = params.pp; @@ -369,7 +364,6 @@ public static Process launch( context.args.add("-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path //context.args.add("-javaagent:".concat(pathLauncher)); ClientHookManager.clientLaunchHook.hook(context); - LauncherGuardManager.guard.addCustomParams(context); context.args.add(ClientLauncher.class.getName()); ClientHookManager.clientLaunchFinallyHook.hook(context); @@ -380,7 +374,6 @@ public static Process launch( LogHelper.debug("Launching client instance"); ProcessBuilder builder = new ProcessBuilder(context.args); context.builder = builder; - LauncherGuardManager.guard.addCustomEnv(context); //else //builder.environment().put("CLASSPATH", classPathString.toString()); EnvHelper.addEnv(builder); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java index a618e529..5147d150 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java @@ -6,7 +6,7 @@ import java.nio.file.Path; import java.util.LinkedList; import java.util.List; - +@Deprecated public class ClientLauncherContext { public Path javaBin; public final List args = new LinkedList<>(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index 1a7bb5ba..f883fe40 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -1,6 +1,8 @@ package pro.gravit.launcher.client; import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.guard.LauncherGuardInterface; import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; @@ -24,9 +26,9 @@ public class ClientLauncherProcess { private transient Process process; private final transient Boolean[] waitWriteParams = new Boolean[] {false}; - public final Path executeFile; - public final Path workDir; - public final Path javaDir; + public Path executeFile; + public Path workDir; + public Path javaDir; public final ClientParams params = new ClientParams(); public final List jvmArgs = new LinkedList<>(); public final List systemClientArgs = new LinkedList<>(); @@ -42,18 +44,24 @@ public ClientLauncherProcess(Path executeFile, Path workDir, Path javaDir, Strin this.mainClass = mainClass; } + public ClientLauncherProcess(Path clientDir, Path assetDir, Path javaDir, + ClientProfile profile, PlayerProfile playerProfile, String accessToken, + HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { + this(clientDir, assetDir, javaDir, clientDir.resolve("resourcepacks"), profile, playerProfile, accessToken, clientHDir, assetHDir, jvmHDir); + } + public ClientLauncherProcess(Path clientDir, Path assetDir, ClientProfile profile, PlayerProfile playerProfile, String accessToken, HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { - this(clientDir, assetDir, clientDir.resolve("resourcepacks"), profile, playerProfile, accessToken, clientHDir, assetHDir, jvmHDir); + this(clientDir, assetDir, Paths.get(System.getProperty("java.home")), clientDir.resolve("resourcepacks"), profile, playerProfile, accessToken, clientHDir, assetHDir, jvmHDir); } - public ClientLauncherProcess(Path clientDir, Path assetDir, Path resourcePackDir, + public ClientLauncherProcess(Path clientDir, Path assetDir, Path javaDir, Path resourcePackDir, ClientProfile profile, PlayerProfile playerProfile, String accessToken, HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { - this.executeFile = LauncherGuardManager.getGuardJavaBinPath(); this.workDir = clientDir.toAbsolutePath(); - this.javaDir = Paths.get(System.getProperty("java.home")); + this.javaDir = javaDir; + this.executeFile = IOHelper.resolveJavaBin(this.javaDir); this.mainClass = ClientLauncherEntryPoint.class.getName(); this.params.clientDir = this.workDir.toString(); this.params.resourcePackDir = resourcePackDir.toAbsolutePath().toString(); @@ -193,6 +201,7 @@ private void addModernClientArgs(Collection args) { } public void start(boolean pipeOutput) throws IOException, InterruptedException { if(isStarted) throw new IllegalStateException("Process already started"); + if(LauncherEngine.guard != null) LauncherEngine.guard.applyGuardParams(this); List processArgs = new LinkedList<>(); processArgs.add(executeFile.toString()); processArgs.addAll(jvmArgs); @@ -212,6 +221,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { LogHelper.debug("Commandline: %s", Arrays.toString(processArgs.toArray())); ProcessBuilder processBuilder = new ProcessBuilder(processArgs); EnvHelper.addEnv(processBuilder); + processBuilder.environment().put("JAVA_HOME", javaDir.toAbsolutePath().toString()); processBuilder.environment().putAll(systemEnv); processBuilder.directory(workDir.toFile()); processBuilder.inheritIO(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java index e0be7852..b277d656 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java @@ -1,21 +1,9 @@ package pro.gravit.launcher.guard; -import pro.gravit.launcher.client.ClientLauncherContext; - -import java.nio.file.Path; +import pro.gravit.launcher.client.ClientLauncherProcess; public interface LauncherGuardInterface { String getName(); - Path getJavaBinPath(); - - int getClientJVMBits(); - - void init(boolean clientInstance); - - void addCustomParams(ClientLauncherContext context); - - void addCustomEnv(ClientLauncherContext context); - - void setProtectToken(String token); + void applyGuardParams(ClientLauncherProcess process); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java index 6b4e763b..65dc653a 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java @@ -9,31 +9,5 @@ public class LauncherGuardManager { public static LauncherGuardInterface guard; public static void initGuard(boolean clientInstance) { - if(guard == null) - { - LauncherConfig config = Launcher.getConfig(); - switch (config.guardType) { - case "stdguard": { - guard = new LauncherStdGuard(); - break; - } - case "wrapper": { - guard = new LauncherWrapperGuard(); - break; - } - case "java": { - guard = new LauncherJavaGuard(); - break; - } - default: { - guard = new LauncherNoGuard(); - } - } - } - guard.init(clientInstance); - } - - public static Path getGuardJavaBinPath() { - return guard.getJavaBinPath(); } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherJavaGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherJavaGuard.java deleted file mode 100644 index 8b4a013e..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherJavaGuard.java +++ /dev/null @@ -1,51 +0,0 @@ -package pro.gravit.launcher.guard; - -import pro.gravit.launcher.client.ClientLauncher; -import pro.gravit.launcher.client.ClientLauncherContext; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; - -public class LauncherJavaGuard implements LauncherGuardInterface { - @Override - public String getName() { - return "java"; - } - - @Override - public Path getJavaBinPath() { - if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) - return IOHelper.resolveJavaBin(ClientLauncher.getJavaBinPath()); - else - return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); - } - - @Override - public int getClientJVMBits() { - return JVMHelper.OS_BITS; - } - - @Override - public void init(boolean clientInstance) { - - } - - @Override - public void addCustomParams(ClientLauncherContext context) { - Collections.addAll(context.args, "-cp"); - Collections.addAll(context.args, context.pathLauncher); - } - - @Override - public void addCustomEnv(ClientLauncherContext context) { - - } - - @Override - public void setProtectToken(String token) { - //Skip - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java index 2ca267a9..94f96f01 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java @@ -1,6 +1,7 @@ package pro.gravit.launcher.guard; import pro.gravit.launcher.client.ClientLauncherContext; +import pro.gravit.launcher.client.ClientLauncherProcess; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @@ -16,33 +17,7 @@ public String getName() { } @Override - public Path getJavaBinPath() { - return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); - } - - @Override - public int getClientJVMBits() { - return JVMHelper.JVM_BITS; - } - - @Override - public void init(boolean clientInstance) { - LogHelper.warning("Using noGuard interface"); - } - - @Override - public void addCustomParams(ClientLauncherContext context) { - Collections.addAll(context.args, "-cp"); - Collections.addAll(context.args, context.pathLauncher); - } - - @Override - public void addCustomEnv(ClientLauncherContext context) { - - } - - @Override - public void setProtectToken(String token) { - //Skip + public void applyGuardParams(ClientLauncherProcess process) { + //IGNORED } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java deleted file mode 100644 index 96d17677..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java +++ /dev/null @@ -1,85 +0,0 @@ -package pro.gravit.launcher.guard; - -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.client.ClientLauncher; -import pro.gravit.launcher.client.ClientLauncherContext; -import pro.gravit.launcher.client.DirBridge; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.UnpackHelper; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.Map; - -//Стандартный интерфейс для всех AntiInject -public class LauncherStdGuard implements LauncherGuardInterface { - public String protectToken; - public Path javaBinPath; - - @Override - public String getName() { - return "stdguard"; - } - - @Override - public Path getJavaBinPath() { - if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { - javaBinPath = ClientLauncher.getJavaBinPath(); - String projectName = Launcher.getConfig().projectName; - String wrapperUnpackName = (javaBinPath == null ? JVMHelper.JVM_BITS : JVMHelper.OS_BITS) == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe"); - return DirBridge.getGuardDir().resolve(wrapperUnpackName); - } else - return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); - } - - @Override - public int getClientJVMBits() { - //При использовании GravitGuard без своей джавы - //Если при запуске лаунчера используется 32 бит джава, а ОС 64бит - //То в окне настроек будет отображаться >1.5Гб доступной памяти - //Однако при выставлении >1.5Гб JVM x32 работать откажеться - return JVMHelper.OS_BITS; - } - - @Override - public void init(boolean clientInstance) { - try { - String projectName = Launcher.getConfig().projectName; - UnpackHelper.unpack(Launcher.getResourceURL("wrapper64.exe", "guard"), DirBridge.getGuardDir().resolve(projectName.concat("64.exe"))); - UnpackHelper.unpack(Launcher.getResourceURL("AntiInject64.dll", "guard"), DirBridge.getGuardDir().resolve("AntiInject64.dll")); - - UnpackHelper.unpack(Launcher.getResourceURL("wrapper32.exe", "guard"), DirBridge.getGuardDir().resolve(projectName.concat("32.exe"))); - UnpackHelper.unpack(Launcher.getResourceURL("AntiInject32.dll", "guard"), DirBridge.getGuardDir().resolve("AntiInject32.dll")); - } catch (IOException e) { - throw new SecurityException(e); - } - } - - @Override - public void addCustomParams(ClientLauncherContext context) { - Collections.addAll(context.args, "-Djava.class.path=".concat(context.pathLauncher)); - } - - @Override - public void addCustomEnv(ClientLauncherContext context) { - Map env = context.builder.environment(); - if (javaBinPath == null) - env.put("JAVA_HOME", System.getProperty("java.home")); - else - env.put("JAVA_HOME", javaBinPath.toAbsolutePath().toString()); - LauncherConfig config = Launcher.getConfig(); - env.put("GUARD_USERNAME", context.playerProfile.username); - env.put("GUARD_PROJECTNAME", config.projectName); - if (protectToken != null) - env.put("GUARD_TOKEN", protectToken); - } - - @Override - public void setProtectToken(String token) { - protectToken = token; - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java index fe841e79..d6f2aaf7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java @@ -3,6 +3,7 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.client.ClientLauncherContext; +import pro.gravit.launcher.client.ClientLauncherProcess; import pro.gravit.launcher.client.DirBridge; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; @@ -16,30 +17,21 @@ public class LauncherWrapperGuard implements LauncherGuardInterface { - public String protectToken; - @Override public String getName() { return "wrapper"; } @Override - public Path getJavaBinPath() { + public void applyGuardParams(ClientLauncherProcess process) { if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { String projectName = Launcher.getConfig().projectName; String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe"); - return DirBridge.getGuardDir().resolve(wrapperUnpackName); - } else - return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + process.executeFile = DirBridge.getGuardDir().resolve(wrapperUnpackName); + } } - @Override - public int getClientJVMBits() { - return JVMHelper.JVM_BITS; - } - - @Override - public void init(boolean clientInstance) { + public LauncherWrapperGuard() { try { String wrapperName = JVMHelper.JVM_BITS == 64 ? "wrapper64.exe" : "wrapper32.exe"; String projectName = Launcher.getConfig().projectName; @@ -51,25 +43,4 @@ public void init(boolean clientInstance) { throw new SecurityException(e); } } - - @Override - public void addCustomParams(ClientLauncherContext context) { - Collections.addAll(context.args, "-Djava.class.path=".concat(context.pathLauncher)); - } - - @Override - public void addCustomEnv(ClientLauncherContext context) { - Map env = context.builder.environment(); - env.put("JAVA_HOME", System.getProperty("java.home")); - LauncherConfig config = Launcher.getConfig(); - env.put("GUARD_USERNAME", context.playerProfile.username); - env.put("GUARD_PROJECTNAME", config.projectName); - if (protectToken != null) - env.put("GUARD_TOKEN", protectToken); - } - - @Override - public void setProtectToken(String token) { - protectToken = token; - } }