|
1 | 1 | package club.shengsheng; |
2 | 2 |
|
3 | | -import java.io.File; |
4 | | -import java.io.IOException; |
5 | | -import java.nio.file.Files; |
6 | | -import java.nio.file.Path; |
7 | 3 |
|
8 | 4 | /** |
9 | 5 | |
10 | 6 | **/ |
11 | 7 | public class MyClassLoader extends ClassLoader { |
12 | 8 |
|
13 | | - public MyClassLoader() { |
14 | | - super(); |
15 | | - } |
16 | | - |
17 | | - @Override |
18 | | - protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { |
19 | | - synchronized (getClassLoadingLock(name)) { |
20 | | - // First, check if the class has already been loaded |
21 | | - Class<?> c = findLoadedClass(name); |
22 | | - if (c == null) { |
23 | | - if (name.startsWith("tech.insight")) { |
24 | | - c = findClass(name); |
25 | | - } else { |
26 | | - c = getParent().loadClass(name); |
27 | | - } |
28 | | - } |
29 | | - if (resolve) { |
30 | | - resolveClass(c); |
31 | | - } |
32 | | - return c; |
33 | | - } |
34 | | - } |
35 | | - |
36 | | - @Override |
37 | | - protected Class<?> findClass(String name) throws ClassNotFoundException { |
38 | | - String path = name.replace(".", "/").concat(".class"); |
39 | | - String fileName = "加密" + ".class"; |
40 | | - File file = new File("./", fileName); |
41 | | - Path filePath = file.toPath(); |
42 | | - System.out.println(filePath); |
43 | | - try { |
44 | | - byte[] bytes = Files.readAllBytes(filePath); |
45 | | - for (int i = 0; i < bytes.length; i++) { |
46 | | - bytes[i] = (byte) (bytes[i] - 1); |
47 | | - } |
48 | | - return defineClass(name, bytes, 0, bytes.length); |
49 | | - } catch (IOException e) { |
50 | | - throw new RuntimeException(e); |
51 | | - } |
52 | | - } |
53 | | - |
54 | 9 | } |
0 commit comments