diff --git a/tests/.gitignore b/tests/.gitignore
index 17ac124..09b96e8 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,5 +1,35 @@
-*.class
+### IntelliJ IDEA ###
+.idea/
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
+
*.log
-*.dll
-*.exe
-build/
+
+### JuiceAgent ###
+resources/
\ No newline at end of file
diff --git a/tests/copy-bin.bat b/tests/copy-bin.bat
new file mode 100644
index 0000000..e69a1ec
--- /dev/null
+++ b/tests/copy-bin.bat
@@ -0,0 +1,4 @@
+@ECHO OFF
+
+cp ../build/bin/*.dll ./resources
+cp ../build/bin/*.exe ./resources
\ No newline at end of file
diff --git a/tests/injection.jar b/tests/injection.jar
new file mode 100644
index 0000000..5d63b73
Binary files /dev/null and b/tests/injection.jar differ
diff --git a/tests/injection/injection.iml b/tests/injection/injection.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/tests/injection/injection.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/injection/src/Injection.java b/tests/injection/src/Injection.java
new file mode 100644
index 0000000..bd53f25
--- /dev/null
+++ b/tests/injection/src/Injection.java
@@ -0,0 +1,5 @@
+public class Injection {
+ public static void test() {
+ System.out.println("Injection Invoked!");
+ }
+}
\ No newline at end of file
diff --git a/tests/injection/src/Target.java b/tests/injection/src/Target.java
new file mode 100644
index 0000000..729bb7d
--- /dev/null
+++ b/tests/injection/src/Target.java
@@ -0,0 +1,6 @@
+public class Target {
+ public static void targetTest() {
+ System.out.println("Target test!");
+ System.out.println("Modified!");
+ }
+}
diff --git a/tests/java-loop/build.bat b/tests/java-loop/build.bat
deleted file mode 100644
index f9fe04c..0000000
--- a/tests/java-loop/build.bat
+++ /dev/null
@@ -1,14 +0,0 @@
-@echo off
-setlocal
-cd /d "%~dp0"
-
-if not exist build mkdir build
-
-javac -d build loop.java
-if errorlevel 1 (
- echo [ERROR] Build failed.
- exit /b 1
-)
-
-echo [OK] Build succeeded: build\loop.class
-endlocal
diff --git a/tests/java-loop/loop.java b/tests/java-loop/loop.java
deleted file mode 100644
index 6219ac1..0000000
--- a/tests/java-loop/loop.java
+++ /dev/null
@@ -1,12 +0,0 @@
-public class loop {
- public static void main(String[] args) {
- while (true) {
- try {
- System.out.println("Hello, World!");
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-}
\ No newline at end of file
diff --git a/tests/java-loop/run.bat b/tests/java-loop/run.bat
deleted file mode 100644
index 9f32482..0000000
--- a/tests/java-loop/run.bat
+++ /dev/null
@@ -1,16 +0,0 @@
-@echo off
-setlocal
-cd /d "%~dp0"
-
-if not exist build\loop.class (
- echo [ERROR] Build output not found. Run build.bat first.
- exit /b 1
-)
-
-java -cp build loop
-if errorlevel 1 (
- echo [ERROR] Run failed.
- exit /b 1
-)
-
-endlocal
diff --git a/tests/java-system-load/Loader.java b/tests/java-system-load/Loader.java
deleted file mode 100644
index a842bdf..0000000
--- a/tests/java-system-load/Loader.java
+++ /dev/null
@@ -1,16 +0,0 @@
-import java.io.File;
-import java.io.IOException;
-
-public class Loader {
- public static void main(String[] args) {
- System.load(new File("./libinject.dll").getAbsolutePath());
- System.out.println("Loaded libinject.dll");
- System.out.println("====================================");
- System.load(new File("./libloader.dll").getAbsolutePath());
- System.out.println("Loaded libloader.dll");
- System.out.println("====================================");
- System.load(new File("./libagent.dll").getAbsolutePath());
- System.out.println("Loaded libagent.dll");
-
- }
-}
\ No newline at end of file
diff --git a/tests/java-system-load/copy-and-build.bat b/tests/java-system-load/copy-and-build.bat
deleted file mode 100644
index 0e3b2b8..0000000
--- a/tests/java-system-load/copy-and-build.bat
+++ /dev/null
@@ -1,23 +0,0 @@
-@echo off
-setlocal
-cd /d "%~dp0"
-
-set "SRC=..\..\build\bin"
-
-echo [INFO] Copying build artifacts from "%SRC%" ...
-xcopy /Y "%SRC%\libagent.dll" .\ >nul
-xcopy /Y "%SRC%\libinject.dll" .\ >nul
-xcopy /Y "%SRC%\libloader.dll" .\ >nul
-echo [OK] Artifacts copied.
-
-if not exist build mkdir build
-
-javac -d build Loader.java
-if errorlevel 1 (
- echo [ERROR] Build failed.
- exit /b 1
-)
-
-echo [OK] Build succeeded: build\Loader.class
-
-endlocal
\ No newline at end of file
diff --git a/tests/java-system-load/run.bat b/tests/java-system-load/run.bat
deleted file mode 100644
index ef3f095..0000000
--- a/tests/java-system-load/run.bat
+++ /dev/null
@@ -1,12 +0,0 @@
-@echo off
-setlocal
-cd /d "%~dp0"
-
-java -cp build Loader
-if errorlevel 1 (
- echo [ERROR] Run failed.
- exit /b 1
-)
-
-pause
-endlocal
\ No newline at end of file
diff --git a/tests/lib/JuiceAgent-API-1.4.1+build.1.jar b/tests/lib/JuiceAgent-API-1.4.1+build.1.jar
new file mode 100644
index 0000000..72d96d3
Binary files /dev/null and b/tests/lib/JuiceAgent-API-1.4.1+build.1.jar differ
diff --git a/tests/src/AddToBootstrapClassLoaderSearch.java b/tests/src/AddToBootstrapClassLoaderSearch.java
new file mode 100644
index 0000000..8ebec1e
--- /dev/null
+++ b/tests/src/AddToBootstrapClassLoaderSearch.java
@@ -0,0 +1,34 @@
+import java.io.File;
+import cn.xiaozhou233.juiceagent.api.JuiceAgent;
+
+public class AddToBootstrapClassLoaderSearch {
+ public static void main(String[] args) {
+ System.load(new File("resources/libagent.dll").getAbsolutePath());
+ JuiceAgent.init("");
+
+ System.out.println("========= Before =========");
+ invokeTest();
+ System.out.println("========= After =========");
+ JuiceAgent.addToBootstrapClassLoaderSearch(new File("Injection.jar").getAbsolutePath());
+ invokeTest();
+ System.out.println("========= Done =========");
+
+ }
+
+ public static void invokeTest() {
+ try {
+ Class> clazz = Class.forName("Injection");
+ ClassLoader loader = clazz.getClassLoader();
+ System.out.println("ClassLoader: " + (loader == null ? "BootstrapClassLoader" : loader));
+ clazz.getMethod("test").invoke(null);
+ } catch (ClassNotFoundException e) {
+ System.err.println("Injection class not found: " + e.getMessage());
+
+ } catch (ReflectiveOperationException e) {
+ System.err.println("Invoke failed: " + e.getMessage());
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/tests/src/AddToClassLoader.java b/tests/src/AddToClassLoader.java
new file mode 100644
index 0000000..f99a947
--- /dev/null
+++ b/tests/src/AddToClassLoader.java
@@ -0,0 +1,30 @@
+import cn.xiaozhou233.juiceagent.api.JuiceAgent;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+
+public class AddToClassLoader {
+ public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ System.load(new File("resources/libagent.dll").getAbsolutePath());
+ JuiceAgent.init("");
+
+ ClassLoader cl = new ClassLoader(){};
+
+ invokeTest(cl);
+
+ JuiceAgent.addToClassLoader(new File("Injection.jar").getAbsolutePath(), cl);
+
+ invokeTest(cl);
+
+ }
+
+ public static void invokeTest(ClassLoader cl) {
+ try {
+ Class> clz = cl.loadClass("Injection");
+ System.out.println("ClassLoader: " + clz.getClassLoader().toString());
+ clz.getMethod("test").invoke(null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/tests/src/AddToSystemClassLoaderSearch.java b/tests/src/AddToSystemClassLoaderSearch.java
new file mode 100644
index 0000000..bb0433b
--- /dev/null
+++ b/tests/src/AddToSystemClassLoaderSearch.java
@@ -0,0 +1,34 @@
+import java.io.File;
+import cn.xiaozhou233.juiceagent.api.JuiceAgent;
+
+public class AddToSystemClassLoaderSearch {
+ public static void main(String[] args) {
+ System.load(new File("resources/libagent.dll").getAbsolutePath());
+ JuiceAgent.init("");
+
+ System.out.println("========= Before =========");
+ invokeTest();
+ System.out.println("========= After =========");
+ JuiceAgent.addToSystemClassLoaderSearch(new File("Injection.jar").getAbsolutePath());
+ invokeTest();
+ System.out.println("========= Done =========");
+
+ }
+
+ public static void invokeTest() {
+ try {
+ Class> clazz = Class.forName("Injection");
+ ClassLoader loader = clazz.getClassLoader();
+ System.out.println("ClassLoader: " + loader);
+ clazz.getMethod("test").invoke(null);
+ } catch (ClassNotFoundException e) {
+ System.err.println("Injection class not found: " + e.getMessage());
+
+ } catch (ReflectiveOperationException e) {
+ System.err.println("Invoke failed: " + e.getMessage());
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/tests/src/GetClassByName.java b/tests/src/GetClassByName.java
new file mode 100644
index 0000000..d10c894
--- /dev/null
+++ b/tests/src/GetClassByName.java
@@ -0,0 +1,17 @@
+import cn.xiaozhou233.juiceagent.api.JuiceAgent;
+
+import java.io.File;
+import java.util.Arrays;
+
+public class GetClassByName {
+ public static void main(String[] args) {
+ System.load(new File("resources/libagent.dll").getAbsolutePath());
+ JuiceAgent.init("");
+
+ Class> clazz = JuiceAgent.getClassByName("java.lang.String");
+
+ System.out.println(clazz);
+ System.out.println(clazz.getName());
+ System.out.println(Arrays.toString(clazz.getDeclaredMethods()));
+ }
+}
diff --git a/tests/src/GetLoadedClasses.java b/tests/src/GetLoadedClasses.java
new file mode 100644
index 0000000..bf06276
--- /dev/null
+++ b/tests/src/GetLoadedClasses.java
@@ -0,0 +1,13 @@
+import cn.xiaozhou233.juiceagent.api.JuiceAgent;
+
+import java.io.File;
+import java.util.Arrays;
+
+public class GetLoadedClasses {
+ public static void main(String[] args) {
+ System.load(new File("resources/libagent.dll").getAbsolutePath());
+ JuiceAgent.init("");
+
+ System.out.println(Arrays.toString(JuiceAgent.getLoadedClasses()));
+ }
+}
diff --git a/tests/src/Loop.java b/tests/src/Loop.java
new file mode 100644
index 0000000..950e40f
--- /dev/null
+++ b/tests/src/Loop.java
@@ -0,0 +1,12 @@
+public class Loop {
+ public static void echo() {
+ System.out.println("Loop!");
+ }
+
+ public static void main(String[] args) throws InterruptedException {
+ while(true) {
+ echo();
+ Thread.sleep(1000);
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/src/Target.java b/tests/src/Target.java
new file mode 100644
index 0000000..c0b6264
--- /dev/null
+++ b/tests/src/Target.java
@@ -0,0 +1,5 @@
+public class Target {
+ public static void targetTest() {
+ System.out.println("Target test!");
+ }
+}
diff --git a/tests/tests.iml b/tests/tests.iml
new file mode 100644
index 0000000..3dcec7d
--- /dev/null
+++ b/tests/tests.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file