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- import java .util .ArrayList ;
8- import java .util .Arrays ;
9- import java .util .List ;
10-
114/**
125 * @author gongxuanzhangmelt@gmail.com
136 **/
147public class MyClassLoader extends ClassLoader {
158
16-
17- @ Override
18- protected Class <?> loadClass (String name , boolean resolve ) throws ClassNotFoundException {
19- synchronized (getClassLoadingLock (name )) {
20- Class <?> c = findLoadedClass (name );
21- if (c == null ) {
22- if (name .startsWith ("tech.insight.ShengSheng" )){
23- c = this .findClass (name );
24- }
25- else {
26- c = getParent ().loadClass (name );
27- }
28- }
29- return c ;
30- }
31- }
32-
33- @ Override
34- protected Class <?> findClass (String name ) throws ClassNotFoundException {
35-
36-
37- File classFile = new File ("./加密.class" );
38-
39- try {
40- byte [] bytes = Files .readAllBytes (classFile .toPath ());
41- byte [] newBytes = new byte [bytes .length ];
42- for (int i = 0 ; i < bytes .length ; i ++) {
43- byte aByte = bytes [i ];
44- aByte = (byte ) (aByte - 1 );
45- newBytes [i ] = aByte ;
46- }
47- return defineClass (name , newBytes , 0 , bytes .length );
48- }catch (Exception e ) {
49- throw new ClassNotFoundException (name );
50- }
51- }
529}
You can’t perform that action at this time.
0 commit comments