From 1ca6c9e2aab79743ab8cafae11612f98d4674532 Mon Sep 17 00:00:00 2001
From: hangqiii <145259555+jakelerke@users.noreply.github.com>
Date: Mon, 9 Jun 2025 20:29:36 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 16 +++++++++++--
.../java/club/shengsheng/MyClassLoader.java | 24 +++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index f8cfcc8..8fcfcd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,10 +7,22 @@
tech.insight
custom-classloader
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 11
+ 11
+
+
+
+
- 17
- 17
+ 11
+ 11
UTF-8
diff --git a/src/main/java/club/shengsheng/MyClassLoader.java b/src/main/java/club/shengsheng/MyClassLoader.java
index 21026cf..20b9631 100644
--- a/src/main/java/club/shengsheng/MyClassLoader.java
+++ b/src/main/java/club/shengsheng/MyClassLoader.java
@@ -1,9 +1,33 @@
package club.shengsheng;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
/**
* @author gongxuanzhangmelt@gmail.com
**/
public class MyClassLoader extends ClassLoader {
+
+ @Override
+ protected Class> findClass(String name) throws ClassNotFoundException {
+ String path = "加密.class";
+ File file = new File(".", path);
+ try {
+ byte[] bytes = Files.readAllBytes(file.toPath());
+ for(int i = 0; i < bytes.length; i++) {
+ bytes[i] = --bytes[i];
+ }
+ return defineClass(name, bytes, 0, bytes.length);
+
+ } catch (IOException e) {
+ throw new ClassNotFoundException(name);
+ }
+ }
+
+
+
+
}
From 30d2f544f45ce381084cd1fe3ac4299177f6049c Mon Sep 17 00:00:00 2001
From: hangqiii <145259555+jakelerke@users.noreply.github.com>
Date: Mon, 9 Jun 2025 20:44:10 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E6=81=A2=E5=A4=8Dpom?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8fcfcd0..2a6b2e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,25 +7,13 @@
tech.insight
custom-classloader
1.0-SNAPSHOT
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 11
- 11
-
-
-
-
11
11
UTF-8
-
+
org.junit.jupiter
@@ -34,4 +22,4 @@
-
+
\ No newline at end of file
From efebdf7907061d574125268a2b0f04c079b1a8d6 Mon Sep 17 00:00:00 2001
From: hangqiii <145259555+jakelerke@users.noreply.github.com>
Date: Mon, 9 Jun 2025 20:48:16 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E6=96=B0pr?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/club/shengsheng/MyClassLoader.java | 52 ++++++++++++-------
1 file changed, 34 insertions(+), 18 deletions(-)
diff --git a/src/main/java/club/shengsheng/MyClassLoader.java b/src/main/java/club/shengsheng/MyClassLoader.java
index 20b9631..ca57588 100644
--- a/src/main/java/club/shengsheng/MyClassLoader.java
+++ b/src/main/java/club/shengsheng/MyClassLoader.java
@@ -2,32 +2,48 @@
import java.io.File;
-import java.io.IOException;
import java.nio.file.Files;
-/**
- * @author gongxuanzhangmelt@gmail.com
- **/
public class MyClassLoader extends ClassLoader {
-
-
- @Override
- protected Class> findClass(String name) throws ClassNotFoundException {
- String path = "加密.class";
- File file = new File(".", path);
- try {
- byte[] bytes = Files.readAllBytes(file.toPath());
- for(int i = 0; i < bytes.length; i++) {
- bytes[i] = --bytes[i];
+ @Override
+ protected Class> loadClass(String name, boolean resolve)
+ throws ClassNotFoundException
+ {
+ synchronized (getClassLoadingLock(name)) {
+ // First, check if the class has already been loaded
+ Class> c = findLoadedClass(name);
+ if (c == null) {
+ if (name.startsWith("tech")) {
+ c = findClass(name);
+ } else {
+ c = getParent().loadClass(name);
+ }
+ }
+ if (resolve) {
+ resolveClass(c);
+ }
+ return c;
+ }
+ }
+ @Override
+ protected Class> findClass(String name) throws ClassNotFoundException {
+ String rootFile = System.getProperty("user.dir").concat(".加密".replace('.', File.separatorChar)).concat(".class");
+ File classFile = new File(rootFile);
+ byte[] classBytes;
+ try {
+ classBytes = Files.readAllBytes( classFile.toPath());
+ for (int i = 0; i < classBytes.length; i++) {
+ classBytes[i] -= 1;
+ }
+
+ } catch (Exception e) {
+ throw new ClassNotFoundException();
}
- return defineClass(name, bytes, 0, bytes.length);
+ return defineClass(name, classBytes, 0, classBytes.length);
- } catch (IOException e) {
- throw new ClassNotFoundException(name);
}
}
-}
From 750fe0697ff4ae937eb3f287da7ea4ab01733ddf Mon Sep 17 00:00:00 2001
From: hangqiii <145259555+jakelerke@users.noreply.github.com>
Date: Mon, 9 Jun 2025 20:49:38 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E6=81=A2=E5=A4=8Dpom?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2a6b2e2..d8d124c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,5 @@
-
+@ -0,0 +1,25 @@
+
@@ -9,8 +10,8 @@
1.0-SNAPSHOT
- 11
- 11
+ 17
+ 17
UTF-8