-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloClassLoader.java
More file actions
39 lines (28 loc) · 1.58 KB
/
HelloClassLoader.java
File metadata and controls
39 lines (28 loc) · 1.58 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
import java.util.Base64;
import java.lang.reflect.Method;
public class HelloClassLoader extends ClassLoader {
public static void main(String[] args) throws Exception {
Class<?> clazz=new HelloClassLoader().findClass("Hello");
// 创建对象
Object instance=clazz.getDeclaredConstructor().newInstance();
for (Method m : clazz.getDeclaredMethods()) {
System.out.println(clazz.getSimpleName() + "." + m.getName());
// 调用实例方法
m.invoke(instance);
}
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
// Linux 命令行获取base64
// cat Hello.xlass |base64|perl -e 'while(<>){chomp;print}print "\n"'
String helloBase64 = "NQFFQf///8v/4/X/+f/x9v/w/+/3/+71/+3/7Pj/6/j/6v7/+cOWkZaLwf7//NfWqf7/+7yQm5r+//CzlpGasYqSnZqNq56dk5r+//qXmpOTkP7/9ayQio2cmrmWk5r+//W3mpOTkNGVnome8//4//f4/+nz/+j/5/7/7Leak5OQ09+ck56MjLOQnpuajd74/+bz/+X/5P7/+reak5OQ/v/vlZ6JntCTnpGY0LCdlZqci/7/75WeiZ7Qk56RmNCshoyLmpL+//yQiov+/+qzlZ6JntCWkNCvjZaRi6yLjZqeksT+/+yVnome0JaQ0K+NlpGLrIuNmp6S/v/4j42WkYuTkf7/6tezlZ6JntCTnpGY0KyLjZaRmMTWqf/e//r/+f///////f/+//j/9//+//b////i//7//v////rVSP/+Tv////7/9f////n//v////7//v/0//f//v/2////2v/9//7////2Tf/97fxJ//tO/////v/1////9f/9////+//3//r//v/z/////f/y";
byte[] bytes = decode(helloBase64);
for(int i=0;i<bytes.length;i++){
bytes[i]=(byte)(255-bytes[i]);
}
return defineClass(name,bytes,0,bytes.length);
}
public byte[] decode(String base64) {
return Base64.getDecoder().decode(base64);
}
}