[FEATURE] byte[] в конфиге.

This commit is contained in:
Zaxar163 2019-10-18 16:27:33 +02:00
parent 96d8883ecb
commit fd23ba555b
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B

View file

@ -1,5 +1,7 @@
package pro.gravit.launchserver.asm;
import java.util.Base64;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@ -14,6 +16,8 @@
public class ConfigGenerator {
protected static final String stringDesc = Type.getDescriptor(String.class);
protected static final String byteArrDesc = Type.getDescriptor(byte[].class);
protected static final String base64DecDesc = "(" + stringDesc + ")" + byteArrDesc;
protected final ClassNode configclass;
protected final MethodNode constructor;
@ -43,6 +47,15 @@ public void setStringField(String name, String value)
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc));
}
public void setByteArrayField(String name, byte[] value)
{
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false));
constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value)));
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false));
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc));
}
public void setIntegerField(String name, int value)
{
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));