Merge branch 'patch-1' into 'master'

Fix type signatures

See merge request gravitlauncherteam/Launcher!283
This commit is contained in:
Gravit S 2019-08-22 11:13:09 +00:00
commit 185ee359e1

View file

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