From 6b7468e36634dc2fd67a0b1eba735cf6472b6a6f Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 31 Jan 2020 19:21:24 +0100 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9E=D0=BA=D0=BE=D0=BD=D1=87?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=83=D1=8E=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=83?= =?UTF-8?q?=20props=20(=D1=87=D0=B0=D1=81=D1=82=D1=8C=202).=20=D0=A1=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA=20props(=D1=82=D0=B5=D0=BA=D1=83=D1=89?= =?UTF-8?q?=D0=B8=D0=B9=20=D1=82=D0=B8=D0=BF=20=D0=B8=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5):=20String=20launcher.projectNam?= =?UTF-8?q?e;=20//=20=D0=9D=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20String=20launcher.?= =?UTF-8?q?address;=20//=20=D0=90=D0=B4=D1=80=D0=B5=D1=81=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20int=20launcher.port;=20//=20?= =?UTF-8?q?=D0=9F=D0=BE=D1=80=D1=82=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=20(=D1=80=D0=B0=D0=BD=D0=B4=D0=BE=D0=BC)=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0=20String=20?= =?UTF-8?q?launcher.guardType;=20//=20=D0=A2=D0=B8=D0=BF=20=D0=B7=D0=B0?= =?UTF-8?q?=D1=89=D0=B8=D1=82=D1=8B=20(java,=20wrapper,=20no=20=D0=B8=20?= =?UTF-8?q?=D1=82.=20=D0=B4.)=20String=20runtimeconfig.secretKeyClient;=20?= =?UTF-8?q?//=20=D0=A1=D0=B5=D0=BA=D1=80=D0=B5=D1=82=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=20String=20runtimeconfig.oemUnlockKey;?= =?UTF-8?q?=20//=20=D0=9A=D0=BB=D1=8E=D1=87=20=D1=80=D0=B0=D0=B7=D0=B1?= =?UTF-8?q?=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=20=D0=B2=20=D0=BB?= =?UTF-8?q?=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B5...=20String=20runtim?= =?UTF-8?q?econfig.secureCheckHash;=20//=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B8=20=D0=B1=D0=B5=D0=B7=D0=BE=D0=BF=D0=B0=D1=81?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=20(=D1=85=D0=B5=D1=88)=20String=20runtimecon?= =?UTF-8?q?fig.secureCheckSalt;=20//=20=D0=AD=D1=82=D0=BE=20=D0=B6=D0=B5?= =?UTF-8?q?=20=D0=BD=D0=BE=20=D1=81=D0=BE=D0=BB=D1=8C...=20String=20runtim?= =?UTF-8?q?econfig.passwordEncryptKey;=20//=20=D0=9A=D0=BB=D1=8E=D1=87=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=88=D0=B8=D1=84=D1=80=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8F...=20int=20launch?= =?UTF-8?q?ercore.env;=20//=20=D0=A1=D1=80=D0=B5=D0=B4=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B0=D1=83=D0=BD=D1=87=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=20(0=3DDEV,1=3DDEBUG,2=3DSTD,3=3DPROD,=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=3D=20=D1=82=D0=B0?= =?UTF-8?q?=D0=BA=20=D0=B6=D0=B5=20STD)=20boolean=20launcher.isWarningMiss?= =?UTF-8?q?ArchJava;=20//=20=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BB=D0=B8=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=20os.?= =?UTF-8?q?bits!=3D=20java.bits=20List=20launchercore.certificates?= =?UTF-8?q?;=20//=20EC-=D1=81=D0=B5=D1=80=D1=82=D0=B8=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=D1=82=D1=8B=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=20byte[]=20List>=20launcher.modules;=20?= =?UTF-8?q?//=20=D0=A1=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=BE=D0=B2=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 4 +-- .../launcher/ClientLauncherWrapper.java | 2 +- .../pro/gravit/launcher/LauncherEngine.java | 2 +- .../launcher/client/ClientLauncher.java | 2 +- .../pro/gravit/launcher/LauncherConfig.java | 30 +++++++++++-------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 81bba9cd..14c71088 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -2,6 +2,7 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; @@ -14,7 +15,6 @@ import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.utils.HookException; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -170,7 +170,7 @@ public Path process(Path inputJar) throws IOException { //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); - context.clientModules.forEach(launcherConfigurator::addModuleClass); + properties.put("launcher.modules", context.clientModules.stream().map(e -> Type.getObjectType(e.replace('.', '/'))).collect(Collectors.toList())); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { try { diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index dbe125ce..1ea56772 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -31,7 +31,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep EnvHelper.checkDangerousParams(); LauncherConfig config = Launcher.getConfig(); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); + LauncherConfig.initModules(LauncherEngine.modulesManager); LogHelper.info("Launcher for project %s", config.projectName); if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index e468542f..301cd7b1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -80,7 +80,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); + LauncherConfig.initModules(LauncherEngine.modulesManager); LauncherEngine.modulesManager.initModules(null); // Start Launcher initGson(LauncherEngine.modulesManager); 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 ecb96566..db685b77 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -443,7 +443,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); //INIT + LauncherConfig.initModules(LauncherEngine.modulesManager); //INIT LauncherEngine.modulesManager.initModules(null); initGson(LauncherEngine.modulesManager); LauncherEngine.verifyNoAgent(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 33219b4c..906fccb8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -1,12 +1,17 @@ package pro.gravit.launcher; +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.modules.LauncherModulesManager; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.security.cert.CertificateException; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; @@ -17,6 +22,8 @@ public final class LauncherConfig extends StreamObject { private static final int cenv = -1; @LauncherInject("launchercore.certificates") private static final List secureConfigCertificates = null; + @LauncherInject("launcher.modules") + private static final List> modulesClasses = null; @LauncherInject("launcher.address") public String address; @LauncherInject("launcher.projectName") @@ -118,17 +125,16 @@ public enum LauncherEnvironment { DEV, DEBUG, STD, PROD } - public static void initModules() { - // TODO Fill - /* - * Old filler - public void addModuleClass(String fullName) { - initModuleMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, launcherName, "modulesManager", modulesManagerDesc)); - initModuleMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); - initModuleMethod.instructions.add(new InsnNode(Opcodes.DUP)); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); - } - */ + private static final MethodType VOID_TYPE = MethodType.methodType(void.class); + + public static void initModules(LauncherModulesManager modulesManager) { + for (Class clazz : modulesClasses) + try { + modulesManager.loadModule((LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, VOID_TYPE).invokeWithArguments(Collections.emptyList())); + } catch (Throwable e) { + LogHelper.error(e); + } + // This method should be called once at exec time. + modulesClasses.clear(); } }