diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..038e92b --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,17 @@ +# Compiled Java / build outputs +load-via-injector-exe/demo.jar +load-via-injector-exe/target.jar +load-via-injector-exe/injection/out/* +load-via-injector-exe/target/out/* +**/out/* +**/*.class + +# JuiceAgent runtime binaries copied into examples +load-via-injector-exe/injector.exe +load-via-injector-exe/libagent.dll +load-via-injector-exe/libinject.dll +load-via-injector-exe/libloader.dll +**/injector.exe +**/libagent.dll +**/libinject.dll +**/libloader.dll diff --git a/examples/config_empty.toml b/examples/config_empty.toml deleted file mode 100644 index 05c8e8a..0000000 --- a/examples/config_empty.toml +++ /dev/null @@ -1,22 +0,0 @@ -[JuiceAgent] -Version = 1 - -[JuiceAgent.Loader] -JuiceAgentNativeLibraryPath = "" - -[JuiceAgent.Modules] - -[JuiceAgent.Modules.JarLoader] -Enabled = true -InjectionDir = "" -JarPath = "" -EntryClass = "" -EntryMethod = "" - -[JuiceAgent.Modules.Dumper] -Enabled = false -DumpDir = "" - -[JuiceAgent.Modules.Remapper] -Enabled = false -JuiceRemapperJarPath = "" \ No newline at end of file diff --git a/examples/load-via-injector-exe/HowToUse.txt b/examples/load-via-injector-exe/HowToUse.txt new file mode 100644 index 0000000..6de34fe --- /dev/null +++ b/examples/load-via-injector-exe/HowToUse.txt @@ -0,0 +1,65 @@ +============================================ + HowToUse +============================================ + +Prerequisites: Java 8+ (javac/jar for building, jps for injection) + +Directory Files: + injector.exe libagent.dll libinject.dll libloader.dll - JuiceAgent runtime + config.toml - injection config + demo.jar - JAR to inject (built by build.bat) + target.jar - target JVM program (built by build.bat) + injection/ - injection source + target/ - target source + build.bat - rebuild demo.jar / target.jar + run.bat - run target JVM (target.jar) + +============================================ + Usage Steps +============================================ + +1. Build (optional) + demo.jar and target.jar are already included by default. + If you modified injection/Main.java or target/target.java, run: + build.bat + to regenerate demo.jar and target.jar in this directory. + +2. Run the target JVM + Double-click run.bat (or run: java -jar target.jar). A black window + appears and prints: + [Target] I am the target JVM (PID: ) + ...... (once per second) + +3. Inject + Double-click injector.exe, type the target PID and press Enter: + 6644 target.jar + 10504 jdk.jcmd/sun.tools.jps.Jps + Input PID: 6644 + +4. Verify + Go back to the target window. Injection succeeded if you see: + [Demo] Injection succeeded! Hello from JuiceAgent. + [Demo] Current thread: Thread-0 + +============================================ + Config / config.toml +============================================ + + JarPath - JAR path to inject (default: ./demo.jar) + EntryClass - Entry class (default: Example.Main) + EntryMethod - Entry method, must be public static void run() + InjectionDir - Dependency JAR directory (only *.jar is loaded) + +============================================ + Troubleshooting +============================================ + +- "java/javac/jar is not recognized": + Install a JDK and add its bin directory to PATH. +- injector.exe reports injection failure: + Make sure the target JVM is running and the PID is correct. +- No [Demo] output appears: + The target window prints many log lines which may affect reading. + Check the [JuiceAgent JarLoader] lines to locate the cause. + If it still fails, copy the full log and submit an Issue, or paste + it directly to an AI. diff --git a/examples/load-via-injector-exe/build.bat b/examples/load-via-injector-exe/build.bat new file mode 100644 index 0000000..43c3545 --- /dev/null +++ b/examples/load-via-injector-exe/build.bat @@ -0,0 +1,23 @@ +@echo off +echo === Building injection jar === +pushd injection +call build.bat +popd +if errorlevel 1 goto :error + +echo. +echo === Building target jar === +pushd target +call build.bat +popd +if errorlevel 1 goto :error + +echo. +echo Build finished: demo.jar and target.jar are in this directory. +goto :end + +:error +echo Build failed. +exit /b 1 + +:end diff --git a/examples/load-via-injector-exe/config.toml b/examples/load-via-injector-exe/config.toml new file mode 100644 index 0000000..e2f3f1d --- /dev/null +++ b/examples/load-via-injector-exe/config.toml @@ -0,0 +1,21 @@ +[JuiceAgent] +Version = 1 + +[JuiceAgent.Loader] +# Path to JuiceAgent-API jar, leave empty to use the built-in API +JuiceAgentAPIJarPath = "" +# Path to libagent.dll, default is "./libagent.dll" +JuiceAgentNativeLibraryPath = "" + +[JuiceAgent.Modules] + +[JuiceAgent.Modules.JarLoader] +Enabled = true +# Directory containing dependency JARs to load into the JVM (put your deps here) +InjectionDir = "./injection" +# Path to the injection JAR to be loaded +JarPath = "./demo.jar" +# Entry class to be executed after loading the JAR +EntryClass = "Example.Main" +# Entry method, must be: public static void run() +EntryMethod = "run" diff --git a/examples/load-via-injector-exe/injection/Main.java b/examples/load-via-injector-exe/injection/Main.java new file mode 100644 index 0000000..900a764 --- /dev/null +++ b/examples/load-via-injector-exe/injection/Main.java @@ -0,0 +1,8 @@ +package Example; + +public class Main { + public static void run() { + System.out.println("[Demo] Injection succeeded! Hello from JuiceAgent."); + System.out.println("[Demo] Current thread: " + Thread.currentThread().getName()); + } +} diff --git a/examples/load-via-injector-exe/injection/build.bat b/examples/load-via-injector-exe/injection/build.bat new file mode 100644 index 0000000..b37344e --- /dev/null +++ b/examples/load-via-injector-exe/injection/build.bat @@ -0,0 +1,28 @@ +@echo off +setlocal + +set "SRC=Main.java" +set "OUT=out" +set "JAR=..\demo.jar" + +if exist "%OUT%" rmdir /s /q "%OUT%" +if exist "%JAR%" del /q "%JAR%" + +mkdir "%OUT%" +javac -encoding UTF-8 --release 8 -d "%OUT%" "%SRC%" +if errorlevel 1 goto :error + +jar --create --file "%JAR%" -C "%OUT%" . +if errorlevel 1 goto :error + +rmdir /s /q "%OUT%" + +echo Build succeeded: demo.jar +goto :end + +:error +echo Build failed. +exit /b 1 + +:end +endlocal diff --git a/examples/load-via-injector-exe/run.bat b/examples/load-via-injector-exe/run.bat new file mode 100644 index 0000000..6bb5d0c --- /dev/null +++ b/examples/load-via-injector-exe/run.bat @@ -0,0 +1,4 @@ +@echo off +cd /d "%~dp0" +java -jar target.jar +pause diff --git a/examples/load-via-injector-exe/target/build.bat b/examples/load-via-injector-exe/target/build.bat new file mode 100644 index 0000000..7774c90 --- /dev/null +++ b/examples/load-via-injector-exe/target/build.bat @@ -0,0 +1,28 @@ +@echo off +setlocal + +set "SRC=target.java" +set "OUT=out" +set "JAR=..\target.jar" + +if exist "%OUT%" rmdir /s /q "%OUT%" +if exist "%JAR%" del /q "%JAR%" + +mkdir "%OUT%" +javac -encoding UTF-8 --release 8 -d "%OUT%" "%SRC%" +if errorlevel 1 goto :error + +jar --create --file "%JAR%" --main-class target -C "%OUT%" . +if errorlevel 1 goto :error + +rmdir /s /q "%OUT%" + +echo Build succeeded: target.jar +goto :end + +:error +echo Build failed. +exit /b 1 + +:end +endlocal diff --git a/examples/load-via-injector-exe/target/target.java b/examples/load-via-injector-exe/target/target.java new file mode 100644 index 0000000..1c60ba6 --- /dev/null +++ b/examples/load-via-injector-exe/target/target.java @@ -0,0 +1,15 @@ +import java.lang.management.ManagementFactory; + +public class target { + public static void main(String[] args) { + String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; + try { + while (true) { + System.out.println("[Target] I am the target JVM (PID: " + pid + ")"); + Thread.sleep(1000); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/examples/load-via-injector-exe/如何使用.txt b/examples/load-via-injector-exe/如何使用.txt new file mode 100644 index 0000000..8ce75b3 --- /dev/null +++ b/examples/load-via-injector-exe/如何使用.txt @@ -0,0 +1,63 @@ +============================================ + 使用说明 / HOW TO USE +============================================ + +前提条件:已安装 Java 8+(需要 javac/jar 构建,jps 用于注入) + +目录文件说明: + injector.exe libagent.dll libinject.dll libloader.dll - JuiceAgent 运行时 + config.toml - 注入配置 + demo.jar - 待注入的 JAR(build.bat 生成) + target.jar - 目标 JVM 程序(build.bat 生成) + injection/ - 注入代码源码 + target/ - 目标程序源码 + build.bat - 重新生成 demo.jar / target.jar + run.bat - 运行目标 JVM(target.jar) + +============================================ + 使用步骤 / Usage Steps +============================================ + +1. 构建(可选) + 默认已包含 demo.jar 和 target.jar。 + 若修改了 injection/Main.java 或 target/target.java,请运行: + build.bat + 生成 demo.jar 和 target.jar 到本目录。 + +2. 运行目标 JVM + 双击 run.bat(或执行 java -jar target.jar),出现黑色窗口并输出: + [Target] I am the target JVM (PID: ) + ......(每秒输出一次) + +3. 注入 + 双击 injector.exe,出现黑色窗口,输入目标 PID 并回车: + 6644 target.jar + 10504 jdk.jcmd/sun.tools.jps.Jps + Input PID: 6644 + +4. 验证 + 回到目标窗口,看到以下输出即注入成功: + [Demo] Injection succeeded! Hello from JuiceAgent. + [Demo] Current thread: Thread-0 + +============================================ + 配置说明 / config.toml +============================================ + + JarPath - 待注入的 JAR 路径(默认 ./demo.jar) + EntryClass - 入口类(默认 Example.Main) + EntryMethod - 入口方法,需为 public static void run() + InjectionDir - 依赖 JAR 目录(仅加载 *.jar) + +============================================ + 常见问题 / Troubleshooting +============================================ + +- "java/javac/jar 不是内部或外部命令": + 安装 JDK 并将其 bin 目录加入 PATH。 +- injector.exe 提示注入失败: + 确认目标 JVM 正在运行,且输入的 PID 正确。 +- 没有出现 [Demo] 输出: + 目标窗口会有大量日志,可能影响阅读;请查看其中的 + [JuiceAgent JarLoader] 日志定位原因。 + 如仍无法解决,请复制完整日志提交 Issue,或直接丢给 AI。 diff --git a/examples/loop/MANIFEST.MF b/examples/loop/MANIFEST.MF deleted file mode 100644 index 7520cbe..0000000 --- a/examples/loop/MANIFEST.MF +++ /dev/null @@ -1 +0,0 @@ -Main-Class: loop diff --git a/examples/loop/build.bat b/examples/loop/build.bat deleted file mode 100644 index a0c08dc..0000000 --- a/examples/loop/build.bat +++ /dev/null @@ -1,3 +0,0 @@ -javac loop.java -jar cvfm loop.jar MANIFEST.MF loop.class -pause diff --git a/examples/loop/loop.jar b/examples/loop/loop.jar deleted file mode 100644 index 50e711d..0000000 Binary files a/examples/loop/loop.jar and /dev/null differ diff --git a/examples/loop/loop.java b/examples/loop/loop.java deleted file mode 100644 index ab3fc0b..0000000 --- a/examples/loop/loop.java +++ /dev/null @@ -1,12 +0,0 @@ -public class loop { - public static void main(String[] args) { - try { - while(true) { - System.out.println("Loop!"); - Thread.sleep(1000); - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/examples/loop/run.bat b/examples/loop/run.bat deleted file mode 100644 index 424984a..0000000 --- a/examples/loop/run.bat +++ /dev/null @@ -1,2 +0,0 @@ -java -jar loop.jar -pause