Skip to content

Commit d6fc20c

Browse files
Revert "load and decrypt class file (#30)"
This reverts commit 3381dd2.
1 parent 3381dd2 commit d6fc20c

1 file changed

Lines changed: 0 additions & 43 deletions

File tree

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,9 @@
11
package club.shengsheng;
22

33

4-
import java.io.ByteArrayOutputStream;
5-
import java.io.FileInputStream;
6-
import java.io.IOException;
7-
84
/**
95
* @author gongxuanzhangmelt@gmail.com
106
**/
117
public class MyClassLoader extends ClassLoader {
128

13-
private static final String classFile = "加密.class";
14-
15-
@Override
16-
public Class<?> loadClass(String name) throws ClassNotFoundException {
17-
if (name != null && name.startsWith("java.")) {
18-
return super.loadClass(name);
19-
}
20-
return findClass(name);
21-
}
22-
23-
@Override
24-
protected Class<?> findClass(String name) throws ClassNotFoundException {
25-
byte[] classData = null;
26-
try {
27-
classData = readClassFile();
28-
} catch (IOException e) {
29-
throw new ClassNotFoundException("Could not read class file: " + classFile);
30-
}
31-
return defineClass(name, classData, 0, classData.length);
32-
}
33-
34-
private byte[] readClassFile() throws IOException {
35-
try (FileInputStream fis = new FileInputStream(classFile);
36-
ByteArrayOutputStream byteArrStream = new ByteArrayOutputStream()) {
37-
38-
byte[] buffer = new byte[1024];
39-
int bytesRead;
40-
41-
while ((bytesRead = fis.read(buffer)) != -1) {
42-
byteArrStream.write(buffer, 0, bytesRead);
43-
}
44-
45-
byte[] byteArray = byteArrStream.toByteArray();
46-
for (int i = 0; i < byteArray.length; i++) {
47-
byteArray[i] = (byte)(byteArray[i] - 1);
48-
}
49-
return byteArray;
50-
}
51-
}
529
}

0 commit comments

Comments
 (0)