File tree Expand file tree Collapse file tree
src/main/java/club/shengsheng Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package club .shengsheng ;
22
33
4- import java .io .File ;
5- import java .io .IOException ;
6- import java .nio .file .Files ;
7-
84/**
95 * @author gongxuanzhangmelt@gmail.com
106 **/
117public class MyClassLoader extends ClassLoader {
128
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- }
459}
You can’t perform that action at this time.
0 commit comments