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+
48/**
59 * @author gongxuanzhangmelt@gmail.com
610 **/
711public 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}
You can’t perform that action at this time.
0 commit comments