Files
JuiceAgent/examples/retransform-class/HowToUse.txt
T
xiaozhou233 6a43b3437a BugFix: fix playload typo in retransform-class example [skip ci]
- examples: rename playload to payload (directory, class, jar, config, docs)

- payload.jar: rebuild with payload.class
2026-10-17 13:21:42 +08:00

87 lines
3.3 KiB
Plaintext

============================================
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
build.bat - build script
run.bat - run target JVM
payload.jar - JAR to inject (built by build.bat)
target.jar - target JVM program (built by build.bat)
new_target.class - retransformed bytecode (built by build.bat)
payload/ - payload source
target/ - target source
new_target/ - modified copy of target source
============================================
What This Example Does
============================================
The target class "target" has a method say() that prints:
Hello!
new_target/target.java is a modified copy that also prints:
Retransformed!
This example injects payload.jar into a running JVM. The payload reads
new_target.class from its own JAR and calls
JuiceAgent.retransformClassByName("target", ...) to swap the already-loaded
"target" class on the fly. After that, say() starts printing the new message
without restarting the JVM.
============================================
Usage Steps
============================================
1. Build (optional)
payload.jar and target.jar are already included by default.
If you modified payload/, target/ or new_target/, run:
build.bat
to regenerate payload.jar, target.jar and new_target.class.
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: <PID>)
Hello!
...... (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:
Payload loaded!
Payload executed!
and the output of say() changes from "Hello!" to:
Hello!
Retransformed!
============================================
Config / config.toml
============================================
JarPath - JAR path to inject (default: ./payload.jar)
EntryClass - Entry class (default: payload)
EntryMethod - Entry method, must be public static void entry()
============================================
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 "Payload loaded!" output appears:
Check libagent.log and libloader.log in this directory for the cause.
- say() output does not change:
Make sure build.bat was run after editing new_target/, and that
new_target.class inside payload.jar is up to date.