-
-
Save anonymous/e1b9971d3079575066dcf060327bb323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ javac -XDignore.symbol.file Test.java | |
Note: Test.java uses or overrides a deprecated API. | |
Note: Recompile with -Xlint:deprecation for details. | |
$ java Test | |
Hey y'all 👍@135fbaa4 | |
[public void Hey y'all 👍.call "this" method :)()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jdk.internal.org.objectweb.asm.ClassWriter; | |
import jdk.internal.org.objectweb.asm.MethodVisitor; | |
import jdk.internal.org.objectweb.asm.Opcodes; | |
import java.util.Arrays; | |
public class Test { | |
public static void main(String[] args) throws Throwable { | |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); | |
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Hey y'all \uD83D\uDC4D", null, "java/lang/Object", null); | |
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); | |
mv.visitCode(); | |
mv.visitVarInsn(Opcodes.ALOAD, 0); | |
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); | |
mv.visitInsn(Opcodes.RETURN); | |
mv.visitMaxs(1, 1); | |
mv.visitEnd(); | |
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "call \"this\" method :)", "()V", null, null); | |
mv.visitCode(); | |
mv.visitInsn(Opcodes.RETURN); | |
mv.visitMaxs(1, 1); | |
mv.visitEnd(); | |
cw.visitEnd(); | |
byte[] bytes = cw.toByteArray(); | |
new ClassLoader() {{ | |
Class<?> klass = defineClass(bytes, 0, bytes.length); | |
System.out.println(klass.newInstance()); | |
System.out.println(Arrays.toString(klass.getDeclaredMethods())); | |
}}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment