Skip to content

Instantly share code, notes, and snippets.

/Test.java Secret

Created January 5, 2017 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e1b9971d3079575066dcf060327bb323 to your computer and use it in GitHub Desktop.
Save anonymous/e1b9971d3079575066dcf060327bb323 to your computer and use it in GitHub Desktop.
$ 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 :)()]
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