diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JAConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JAConfigurator.java index 0451767e..5f96705d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JAConfigurator.java @@ -22,32 +22,32 @@ import pro.gravit.launchserver.asm.SafeClassWriter; public class JAConfigurator { - private static final String modulesManagerName = Type.getInternalName(ModulesManager.class); - private static final String registerModDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Module.class)); - private static final String autoGenConfigName = Type.getInternalName(AutogenConfig.class); - private static final String stringName = Type.getInternalName(String.class); - private final ClassNode configclass; - private final MethodNode constructor; - private final MethodNode initModuleMethod; + private static final String modulesManagerName = Type.getInternalName(ModulesManager.class); + private static final String registerModDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Module.class)); + private static final String autoGenConfigName = Type.getInternalName(AutogenConfig.class); + private static final String stringDesc = Type.getDescriptor(String.class); + private final ClassNode configclass; + private final MethodNode constructor; + private final MethodNode initModuleMethod; public JAConfigurator(ClassNode configclass) { - this.configclass = configclass; - constructor = configclass.methods.stream().filter(e -> "".equals(e.name)).findFirst().get(); - constructor.instructions = new InsnList(); + this.configclass = configclass; + constructor = configclass.methods.stream().filter(e -> "".equals(e.name)).findFirst().get(); + constructor.instructions = new InsnList(); initModuleMethod = configclass.methods.stream().filter(e -> "initModules".equals(e.name)).findFirst().get(); initModuleMethod.instructions = new InsnList(); } public void addModuleClass(String fullName) { - initModuleMethod.instructions.insert(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "registerModule", registerModDesc)); - initModuleMethod.instructions.insert(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); - initModuleMethod.instructions.insert(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); + initModuleMethod.instructions.insert(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "registerModule", registerModDesc)); + initModuleMethod.instructions.insert(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); + initModuleMethod.instructions.insert(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); } public byte[] getBytecode(ClassMetadataReader reader) { ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES); configclass.accept(cw); - return cw.toByteArray(); + return cw.toByteArray(); } public String getZipEntryPath() { @@ -55,41 +55,41 @@ public String getZipEntryPath() { } public void setAddress(String address) { - constructor.instructions.add(new LdcInsnNode(address)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "address", stringName)); + constructor.instructions.add(new LdcInsnNode(address)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "address", stringDesc)); } public void setProjectName(String name) { - constructor.instructions.add(new LdcInsnNode(name)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "projectname", stringName)); + constructor.instructions.add(new LdcInsnNode(name)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "projectname", stringDesc)); } public void setSecretKey(String key) { - constructor.instructions.add(new LdcInsnNode(key)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "secretKeyClient", stringName)); + constructor.instructions.add(new LdcInsnNode(key)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "secretKeyClient", stringDesc)); } public void setOemUnlockKey(String key) { constructor.instructions.add(new LdcInsnNode(key)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "oemUnlockKey", stringName)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "oemUnlockKey", stringDesc)); } public void setGuardType(String key) { constructor.instructions.add(new LdcInsnNode(key)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardType", stringName)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardType", stringDesc)); } - public void push(final int value) { - if (value >= -1 && value <= 5) - constructor.instructions.add(new InsnNode(Opcodes.ICONST_0 + value)); - else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) - constructor.instructions.add(new IntInsnNode(Opcodes.BIPUSH, value)); - else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) - constructor.instructions.add(new IntInsnNode(Opcodes.SIPUSH, value)); - else - constructor.instructions.add(new LdcInsnNode(value)); - } + public void push(final int value) { + if (value >= -1 && value <= 5) + constructor.instructions.add(new InsnNode(Opcodes.ICONST_0 + value)); + else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) + constructor.instructions.add(new IntInsnNode(Opcodes.BIPUSH, value)); + else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) + constructor.instructions.add(new IntInsnNode(Opcodes.SIPUSH, value)); + else + constructor.instructions.add(new LdcInsnNode(value)); + } public void setEnv(LauncherConfig.LauncherEnvironment env) { int i = 2; @@ -124,19 +124,19 @@ public void setWarningMissArchJava(boolean b) { public void setGuardLicense(String name, String key, String encryptKey) { constructor.instructions.add(new LdcInsnNode(name)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseName", stringName)); - constructor.instructions.add(new LdcInsnNode(key)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseKey", stringName)); - constructor.instructions.add(new LdcInsnNode(encryptKey)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseEncryptKey", stringName)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseName", stringDesc)); + constructor.instructions.add(new LdcInsnNode(key)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseKey", stringDesc)); + constructor.instructions.add(new LdcInsnNode(encryptKey)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseEncryptKey", stringDesc)); } public void nullGuardLicense() { constructor.instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseName", stringName)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseName", stringDesc)); constructor.instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseKey", stringName)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseKey", stringDesc)); constructor.instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseEncryptKey", stringName)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseEncryptKey", stringDesc)); } }