|
1 | | -/* |
2 | | - * Copyright 2025 Nippaku_Zanmu |
3 | | - * SPDX-License-Identifier: gplv3 |
4 | | - */ |
5 | | - |
6 | | -package com.kijinseija.seija_printer.loader; |
7 | | - |
8 | | -import com.kijinseija.seija_printer.Addon; |
9 | | -import meteordevelopment.meteorclient.systems.modules.Modules; |
10 | | - |
11 | | -import java.io.*; |
12 | | -import java.net.Socket; |
13 | | -import java.nio.charset.StandardCharsets; |
14 | | -import java.util.HashMap; |
15 | | -import java.util.zip.ZipEntry; |
16 | | -import java.util.zip.ZipInputStream; |
17 | | - |
18 | | - |
19 | | -public class DiskClassLoader extends ClassLoader { |
20 | | - private final HashMap<String, byte[]> classMap = new HashMap<>(); |
21 | | - // private String mLibPath; |
22 | | - |
23 | | - |
24 | | - public final void downloadClass() { |
25 | | - |
26 | | - Socket socket = null; |
27 | | - try { |
28 | | - socket = new Socket("127.0.0.1", 7766); |
29 | | - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)); |
30 | | - bw.write(new VerifyUtil().getHWID()); |
31 | | - bw.newLine(); |
32 | | - bw.flush(); |
33 | | - ZipInputStream zis = new ZipInputStream(new BufferedInputStream(socket.getInputStream())); |
34 | | - ZipEntry entry; |
35 | | - while ((entry = zis.getNextEntry()) != null) { |
36 | | - if (entry.isDirectory()) continue; |
37 | | - ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
38 | | - int len = 0; |
39 | | - |
40 | | - while ((len = zis.read()) != -1) { |
41 | | - bos.write(len); |
42 | | - } |
43 | | - Addon.LOG.info("Download"+entry.getName()); |
44 | | - byte[] classByte = bos.toByteArray();//new byte[(int) entry.getSize()]; |
45 | | -// zis.read(classByte); |
46 | | - |
47 | | - classMap.put(entry.getName(), classByte); |
48 | | - } |
49 | | - Addon.LOG.info("Downloaded"); |
50 | | - |
51 | | - } catch (IOException e) { |
52 | | - //throw new RuntimeException(e); |
53 | | - } finally { |
54 | | - try { |
55 | | - Thread.sleep(500); |
56 | | - if (socket != null) { |
57 | | - socket.close(); |
58 | | - } |
59 | | - } catch (IOException | InterruptedException e) { |
60 | | - // throw new RuntimeException(e); |
61 | | - } |
62 | | - Addon.LOG.info("Downloaded1"); |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - |
67 | | - public DiskClassLoader() { |
68 | | - super(Modules.get().getClass().getClassLoader()); |
69 | | - //使用依赖mod的classLoader 避免加载类的问题 |
70 | | - // TODO Auto-generated constructor stub |
71 | | - //mLibPath = path; |
72 | | - } |
73 | | - |
74 | | -// @Override |
75 | | -// protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { |
| 1 | +///* |
| 2 | +// * Copyright 2025 Nippaku_Zanmu |
| 3 | +// * SPDX-License-Identifier: gplv3 |
| 4 | +// */ |
| 5 | +// |
| 6 | +//package com.kijinseija.seija_printer.loader; |
| 7 | +// |
| 8 | +//import com.kijinseija.seija_printer.Addon; |
| 9 | +//import meteordevelopment.meteorclient.systems.modules.Modules; |
| 10 | +// |
| 11 | +//import java.io.*; |
| 12 | +//import java.net.Socket; |
| 13 | +//import java.nio.charset.StandardCharsets; |
| 14 | +//import java.util.HashMap; |
| 15 | +//import java.util.zip.ZipEntry; |
| 16 | +//import java.util.zip.ZipInputStream; |
| 17 | +// |
| 18 | +// |
| 19 | +//public class DiskClassLoader extends ClassLoader { |
| 20 | +// private final HashMap<String, byte[]> classMap = new HashMap<>(); |
| 21 | +// // private String mLibPath; |
| 22 | +// |
| 23 | +// |
| 24 | +// public final void downloadClass() { |
| 25 | +// |
| 26 | +// Socket socket = null; |
76 | 27 | // try { |
77 | | -// return super.loadClass(name, resolve); |
78 | | -// }catch (ClassNotFoundException) |
| 28 | +// socket = new Socket("127.0.0.1", 7766); |
| 29 | +// BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)); |
| 30 | +// bw.write(new VerifyUtil().getHWID()); |
| 31 | +// bw.newLine(); |
| 32 | +// bw.flush(); |
| 33 | +// ZipInputStream zis = new ZipInputStream(new BufferedInputStream(socket.getInputStream())); |
| 34 | +// ZipEntry entry; |
| 35 | +// while ((entry = zis.getNextEntry()) != null) { |
| 36 | +// if (entry.isDirectory()) continue; |
| 37 | +// ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 38 | +// int len = 0; |
79 | 39 | // |
80 | | -// } |
81 | | - |
82 | | - |
83 | | - @Override |
84 | | - protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { |
85 | | - Addon.LOG.info("Try Load Class 1111 " + name); |
86 | | - return super.loadClass(name, resolve); |
87 | | - } |
88 | | - |
89 | | - @Override |
90 | | - protected Class<?> findClass(String name) { |
91 | | - // TODO Auto-generated method stub |
92 | | - |
93 | | - String fileName = getFileName(name); |
94 | | - Addon.LOG.info("Loading "+name); |
95 | | - //File file = new File(mLibPath, fileName); |
96 | | - |
97 | | - // try { |
98 | | - |
99 | | -// FileInputStream is = new FileInputStream(file); |
100 | | -// |
101 | | -// |
102 | | -// ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
103 | | -// int len = 0; |
104 | | -// try { |
105 | | -// while ((len = is.read()) != -1) { |
| 40 | +// while ((len = zis.read()) != -1) { |
106 | 41 | // bos.write(len); |
107 | 42 | // } |
108 | | -// } catch (IOException e) { |
109 | | -// e.printStackTrace(); |
| 43 | +// Addon.LOG.info("Download"+entry.getName()); |
| 44 | +// byte[] classByte = bos.toByteArray();//new byte[(int) entry.getSize()]; |
| 45 | +//// zis.read(classByte); |
| 46 | +// |
| 47 | +// classMap.put(entry.getName(), classByte); |
110 | 48 | // } |
| 49 | +// Addon.LOG.info("Downloaded"); |
| 50 | +// |
| 51 | +// } catch (IOException e) { |
| 52 | +// //throw new RuntimeException(e); |
| 53 | +// } finally { |
| 54 | +// try { |
| 55 | +// Thread.sleep(500); |
| 56 | +// if (socket != null) { |
| 57 | +// socket.close(); |
| 58 | +// } |
| 59 | +// } catch (IOException | InterruptedException e) { |
| 60 | +// // throw new RuntimeException(e); |
| 61 | +// } |
| 62 | +// Addon.LOG.info("Downloaded1"); |
| 63 | +// } |
| 64 | +// } |
| 65 | +// |
| 66 | +// |
| 67 | +// public DiskClassLoader() { |
| 68 | +// super(Modules.get().getClass().getClassLoader()); |
| 69 | +// //使用依赖mod的classLoader 避免加载类的问题 |
| 70 | +// // TODO Auto-generated constructor stub |
| 71 | +// //mLibPath = path; |
| 72 | +// } |
| 73 | +// |
| 74 | +//// @Override |
| 75 | +//// protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { |
| 76 | +//// try { |
| 77 | +//// return super.loadClass(name, resolve); |
| 78 | +//// }catch (ClassNotFoundException) |
| 79 | +//// |
| 80 | +//// } |
| 81 | +// |
| 82 | +// |
| 83 | +// @Override |
| 84 | +// protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { |
| 85 | +// Addon.LOG.info("Try Load Class 1111 " + name); |
| 86 | +// return super.loadClass(name, resolve); |
| 87 | +// } |
| 88 | +// |
| 89 | +// @Override |
| 90 | +// protected Class<?> findClass(String name) { |
| 91 | +// // TODO Auto-generated method stub |
| 92 | +// |
| 93 | +// String fileName = getFileName(name); |
| 94 | +// Addon.LOG.info("Loading "+name); |
| 95 | +// //File file = new File(mLibPath, fileName); |
| 96 | +// |
| 97 | +// // try { |
| 98 | +// |
| 99 | +//// FileInputStream is = new FileInputStream(file); |
| 100 | +//// |
| 101 | +//// |
| 102 | +//// ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 103 | +//// int len = 0; |
| 104 | +//// try { |
| 105 | +//// while ((len = is.read()) != -1) { |
| 106 | +//// bos.write(len); |
| 107 | +//// } |
| 108 | +//// } catch (IOException e) { |
| 109 | +//// e.printStackTrace(); |
| 110 | +//// } |
| 111 | +//// |
| 112 | +// byte[] data = classMap.get(fileName); |
| 113 | +// if (data == null) { |
| 114 | +// Addon.LOG.info(fileName + " Is Null"); |
| 115 | +// classMap.forEach((s, bytes) -> Addon.LOG.info("Class: " + s)); |
| 116 | +// } |
| 117 | +// //bos.toByteArray(); |
| 118 | +// //System.out.println(Arrays.toString(data)); |
| 119 | +//// is.close(); |
| 120 | +//// bos.close(); |
| 121 | +// |
| 122 | +// return defineClass(name, data, 0, data.length); |
| 123 | +// |
| 124 | +// //} catch (IOException e) { |
| 125 | +// // TODO Auto-generated catch block |
| 126 | +// // e.printStackTrace(); |
| 127 | +// // } |
| 128 | +// |
| 129 | +// // return super.findClass(name); |
| 130 | +// } |
| 131 | +// |
| 132 | +// //获取要加载 的class文件名 |
| 133 | +// private String getFileName(String name) { |
| 134 | +// return name.replaceAll("\\.", "/") + ".class"; |
| 135 | +// // TODO Auto-generated method stub |
| 136 | +//// int index = name.lastIndexOf('.'); |
| 137 | +//// if(index == -1){ |
| 138 | +//// System.out.println(name+".class"); |
| 139 | +//// return name+".class"; |
| 140 | +//// }else{ |
| 141 | +//// String s = name.substring(index + 1) + ".class"; |
| 142 | +////// System.out.println(222); |
| 143 | +////// System.out.println(name.substring(index + 1)); |
| 144 | +////// System.out.println(s); |
| 145 | +//// return s; |
| 146 | +//// } |
| 147 | +// } |
111 | 148 | // |
112 | | - byte[] data = classMap.get(fileName); |
113 | | - if (data == null) { |
114 | | - Addon.LOG.info(fileName + " Is Null"); |
115 | | - classMap.forEach((s, bytes) -> Addon.LOG.info("Class: " + s)); |
116 | | - } |
117 | | - //bos.toByteArray(); |
118 | | - //System.out.println(Arrays.toString(data)); |
119 | | -// is.close(); |
120 | | -// bos.close(); |
121 | | - |
122 | | - return defineClass(name, data, 0, data.length); |
123 | | - |
124 | | - //} catch (IOException e) { |
125 | | - // TODO Auto-generated catch block |
126 | | - // e.printStackTrace(); |
127 | | - // } |
128 | | - |
129 | | - // return super.findClass(name); |
130 | | - } |
131 | | - |
132 | | - //获取要加载 的class文件名 |
133 | | - private String getFileName(String name) { |
134 | | - return name.replaceAll("\\.", "/") + ".class"; |
135 | | - // TODO Auto-generated method stub |
136 | | -// int index = name.lastIndexOf('.'); |
137 | | -// if(index == -1){ |
138 | | -// System.out.println(name+".class"); |
139 | | -// return name+".class"; |
140 | | -// }else{ |
141 | | -// String s = name.substring(index + 1) + ".class"; |
142 | | -//// System.out.println(222); |
143 | | -//// System.out.println(name.substring(index + 1)); |
144 | | -//// System.out.println(s); |
145 | | -// return s; |
146 | | -// } |
147 | | - } |
148 | | - |
149 | | -} |
| 149 | +//} |
0 commit comments