-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.java
More file actions
54 lines (53 loc) · 2.35 KB
/
functions.java
File metadata and controls
54 lines (53 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package dynamic;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import java.util.ArrayList;
import java.util.Map;
public class functions {
public static String asmType(String DataType){
if (DataType.equals("int")) {
return Type.INT_TYPE.getDescriptor();
} else if (DataType.equals("float")) {
return Type.FLOAT_TYPE.getDescriptor();
} else if (DataType.equals("double")) {
return Type.DOUBLE_TYPE.getDescriptor();
} else if (DataType.equals("String")) {
return Type.getType(String.class).getDescriptor();
} else if (DataType.equals("ArrayList")) {
return Type.getType(ArrayList.class).getDescriptor();
} else if (DataType.equals("Map")) {
return Type.getType(Map.class).getDescriptor();
} else if (DataType.equals("Object")) {
return Type.getType(Object.class).getDescriptor();
} else if (DataType.equals("boolean")) {
return Type.BOOLEAN_TYPE.getDescriptor();
} else if (DataType.equals("byte")) {
return Type.BYTE_TYPE.getDescriptor();
} else if (DataType.equals("char")) {
return Type.CHAR_TYPE.getDescriptor();
} else if (DataType.equals("short")) {
return Type.SHORT_TYPE.getDescriptor();
} else if (DataType.equals("long")) {
return Type.LONG_TYPE.getDescriptor();
} else if (DataType.equals("void")) {
return Type.VOID_TYPE.getDescriptor();
}
return null;
}
public static class ClassLoad extends ClassLoader {
public Class<?> defineClass(String name, byte[] b) {
return defineClass(name, b, 0, b.length);
}
}
public static void voidConstructor(ClassWriter cw) {
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 0); // Carga "this"
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); // Invoca al constructor de la superclase (java.lang.Object)
mv.visitInsn(Opcodes.RETURN); // Retorna desde el constructor
mv.visitMaxs(1, 1); // Define los valores máximos de stack y variables locales
mv.visitEnd();
}
}