Skip to content

Commit 8b3ca86

Browse files
lin的提交 (#12)
merge
1 parent 9901c53 commit 8b3ca86

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
11
package club.shengsheng;
22

33

4+
import java.io.File;
5+
import java.io.IOException;
6+
import java.nio.file.Files;
7+
48
/**
59
* @author gongxuanzhangmelt@gmail.com
610
**/
711
public class MyClassLoader extends ClassLoader {
812

13+
@Override
14+
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
15+
synchronized (getClassLoadingLock(name)) {
16+
Class<?> c = findLoadedClass(name);
17+
if (c == null) {
18+
if (name.equals("tech.insight.ShengSheng")) {
19+
c = findClass(name);
20+
} else {
21+
c = getParent().loadClass(name);
22+
}
23+
}
24+
if (resolve) {
25+
resolveClass(c);
26+
}
27+
return c;
28+
}
29+
}
30+
31+
@Override
32+
protected Class<?> findClass(String name) throws ClassNotFoundException {
33+
String path = "加密.class";
34+
File classFile = new File(path);
35+
try {
36+
byte[] bytes = Files.readAllBytes(classFile.toPath());
37+
for (int i = 0; i < bytes.length; i++) {
38+
bytes[i] = (byte) (bytes[i] - 1);
39+
}
40+
return defineClass(name, bytes, 0, bytes.length);
41+
} catch (IOException e) {
42+
throw new RuntimeException(name);
43+
}
44+
}
945
}

0 commit comments

Comments
 (0)