package demo;
import java.util.Base64;
public class MarbleClassLoader extends ClassLoader {
public static void main(String[] args) {
try {
new MarbleClassLoader().findClass("jvm.Hello").newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
String helloBase64 = "yv66vgAAADQAHAoABgAOCQAPABAIABEKABIAEwcAFAcAFQEABjxpbml0PgEAAygpVgEABENvZGUB" +
"AA9MaW5lTnVtYmVyVGFibGUBAAg8Y2xpbml0PgEAClNvdXJjZUZpbGUBAApIZWxsby5qYXZhDAAH" +
"AAgHABYMABcAGAEALkhlbGxvIENsYXNzIEluaXRpYWxpemVkIHdpdGggTWFyYmxlQ2xhc3Nsb2Fk" +
"ZXIHABkMABoAGwEACWp2bS9IZWxsbwEAEGphdmEvbGFuZy9PYmplY3QBABBqYXZhL2xhbmcvU3lz" +
"dGVtAQADb3V0AQAVTGphdmEvaW8vUHJpbnRTdHJlYW07AQATamF2YS9pby9QcmludFN0cmVhbQEA" +
"B3ByaW50bG4BABUoTGphdmEvbGFuZy9TdHJpbmc7KVYAIQAFAAYAAAAAAAIAAQAHAAgAAQAJAAAA" +
"HQABAAEAAAAFKrcAAbEAAAABAAoAAAAGAAEAAAADAAgACwAIAAEACQAAACUAAgAAAAAACbIAAhID" +
"tgAEsQAAAAEACgAAAAoAAgAAAAUACAAGAAEADAAAAAIADQ==";
byte[] bytes = decode(helloBase64);
return defineClass(name, bytes, 0, bytes.length);
}
public byte[] decode(String base64) {
return Base64.getDecoder().decode(base64);
}
}