Skip to content

Commit 447c58f

Browse files
authored
commit (#40)
merge
1 parent 56acff5 commit 447c58f

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
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) throws ClassNotFoundException {
15+
Class<?> c = findLoadedClass(name);
16+
if (c == null) {
17+
if (name.startsWith("tech.insight.")) {
18+
c = findClass(name);
19+
}else {
20+
c = loadClass(name,false);
21+
}
22+
}
23+
return c;
24+
}
25+
26+
@Override
27+
protected Class<?> findClass(String name) throws ClassNotFoundException {
28+
// tech.insight.ShengSheng
29+
String path = "加密.class";
30+
File file = new File(path);
31+
try {
32+
byte[] bytes = Files.readAllBytes(file.toPath());
33+
decoderBytes(bytes);
34+
Files.write(new File("shengsheng.class").toPath(), bytes);
35+
return defineClass(name, bytes, 0, bytes.length);
36+
} catch (IOException e) {
37+
throw new ClassNotFoundException(name);
38+
}
39+
}
40+
41+
private void decoderBytes(byte[] bytes) {
42+
for (int i = 0; i < bytes.length; i++) {
43+
byte b = bytes[i];
44+
bytes[i] = (byte) (b-1);
45+
}
46+
}
947
}

0 commit comments

Comments
 (0)