need to refactor [bug] cannot parse toml config [todo] jni name
JuiceAgent
JuiceAgent — a JVMTI-based injection library for loading external JARs and transforming Java bytecode, even when DisableAttachMechanism is enabled.
NOTICE: Currently only supports Windows, and plans to support Linux in the future.
WARNING: This project is still in the experimental stage and is not recommended for production use. Disclaimer: This project is for learning and research in controlled environments only. The author is not responsible for any illegal or unauthorized use. Users must ensure their actions are legal. (See Full Disclaimer below) 免责声明: 本项目仅供受控环境下的学习和研究使用。作者不对任何非法或未授权的使用承担责任。使用者应确保自己的行为合法。(在下方查看完整免责声明)
Summary
JuiceAgent is a JVMTI-native injection framework that injects native code into a target JVM to dynamically load external JARs and perform bytecode redefinition/transformations without requiring a javaagent (works when DisableAttachMechanism=true).
Features
Injector (src/injector)
Reflective injector, can be invoke in java (java/InjectorNative.java)
- Inject Dlls. (with no params)
- Inject JuiceAgent library. (with params)
JuiceAgent (src/agent)
Minimize loading, inject to target jvm.
- Get JVM / JNI / JVMTI
- Inject bootstrap-api.jar
- Inject JuiceLoader.jar
- Invoke Java Function JuiceLoader init
JuiceLoader Native (src/juiceloader)
Native library for JuiceLoader , Inject Jars/ Redefine class Low-level implementation.
- Get JVM / JNI / JVMTI
- Inject Custom Jars
- Redefine class
- Get Loaded Classes
- JNI Function (Can be invoke in java)
How To Use
TODO: Update How to Use Notice: Tutorial for Version 1.0
1. Download Files
- Download
libagent,libinjector, andlibjuiceloaderfrom the Release to the same directory. - Download JARs
bootstrap-api.jar,JuiceLoader.jar, andEntry.jar(or your own JAR) to the same directory.
2. Write Config File
Create a config file named AgentConfig.toml in the same directory. Example:
[Injection]
BootstrapAPIPath = "<YourDir>/bootstrap-api.jar"
JuiceLoaderJarPath = "<YourDir>/JuiceLoader.jar"
# Leave empty to use the DLL directory (Normal Inject) or the directory passed as parameter (Reflective Inject)
JuiceLoaderLibPath = ""
EntryJarPath = "<YourDir>/Entry.jar"
EntryClass = "entry.class"
EntryMethod = "entryMethod"
| Method | Usage |
|---|---|
| Reflective Inject | Uses libinjector. Pass the config directory as a parameter. Example: config file at <YourDir>/AgentConfig.toml, pass <YourDir> as parameter. If a key is empty (e.g., BootstrapAPIPath = ""), it defaults to <DirA>/default-name (e.g., <DirA>/bootstrap-api.jar). |
| Normal Inject | Uses LoadLibraryA + CreateRemoteThread. Keep AgentConfig.toml and all DLLs/JARs in the same directory. |
3. Invoke Inject Function
C/C++ Use libinjector and invoke inject(int pid, char* path, InjectParameters *params)
Java Use Injecor.jar: java -jar Injecor.jar or
package cn.xiaozhou233.juiceagent.injector;
public class InjectorNative {
/*
* @param pid target process id
*/
public native boolean inject(int pid, String path);
/*
* @param pid target process id
* @param path injection dll path
* @param configPath config file path
*/
public native boolean inject(int pid, String path, String configPath);
}
// Your class
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
System.load("<path-to-libinjector>");
InjectorNative injectorNative = new InjectorNative();
injectorNative.inject(<pid>, "<path-to-libagent>", "<path-to-toml-config-dir>");
4. Done!
If the injection is successful, EntryClass .EntryMethod() of will be executed.
Hot To Build
Environment
- Java 8+
- MinGW
- CMake
- Ninja
git clone https://github.com/xiaozhou233/JuiceAgent.git
cd JuiceAgent
mkdir -p build
cmake --build build --
dlls: build/bin/
jars: see JuiceLoader
Full Disclaimer/ 完整免责声明
Disclaimer: This project is intended for learning and research in controlled environments only. The author is not responsible for any consequences arising from unauthorized use, modification, cracking, or violation of any applicable agreements or laws. Users are responsible for ensuring their actions are legal and compliant.
免责声明: 本项目仅建议在受控环境中用于学习与研究。任何利用本项目实施破解、篡改、未经授权获取源码或其他违反目标协议或法律的行为所导致的一切后果,作者概不负责。使用者应自行确保其行为合法合规,并对相应后果承担全部责任。
Acknowledgements
- ReflectiveDLLInjection - DLL Inject
- log.c - A simple logger system
- tomlc17 - TOML parser in C17