Docs: Readme

This commit is contained in:
xiaozhou233 committed 2026-04-21 14:44:35 +08:00
1 parent b348757416
commit 92837c9597
6 files changed
+280 -2263

No files matched your search

+86 -66
View File
@@ -1,64 +1,113 @@
# JuiceAgent
[English](https://github.com/xiaozhou233/JuiceAgent/blob/main/README.md) | [中文](https://github.com/xiaozhou233/JuiceAgent/blob/main/README_zh.md)
JuiceAgent is a JVMTI-based injection library for loading external JARs and transforming Java bytecode, even when `DisableAttachMechanism` is enabled.
JuiceAgent is an advanced JVMTI-based injection framework designed for runtime JAR loading, bytecode transformation, and deep JVM instrumentation, even with DisableAttachMechanism enabled.
**Notice:** Currently, only **Windows** is supported. **Linux** support may be added in the future.
![License](https://img.shields.io/github/license/xiaozhou233/JuiceAgent)
![Release](https://img.shields.io/github/v/release/xiaozhou233/JuiceAgent)
![GitHub last commit](https://img.shields.io/github/last-commit/xiaozhou233/JuiceAgent)
![GitHub repo size](https://img.shields.io/github/repo-size/xiaozhou233/JuiceAgent)
**Notice:** The current repository version is **Version 3.3 Build 1**.
![Java](https://img.shields.io/badge/Java-8+-orange)
![C++](https://img.shields.io/badge/C++-20-blue)
![JNI](https://img.shields.io/badge/JNI-Native-green)
![CMake](https://img.shields.io/badge/CMake-Build-red)
![Platform](https://img.shields.io/badge/Platform-Windows-lightgrey)
**Warning:** This project is still experimental and is not recommended for production use. Use it at your own risk.
![JVMTI](https://img.shields.io/badge/JVMTI-Agent-success)
![Injection](https://img.shields.io/badge/Runtime-Injection-blueviolet)
![Bytecode](https://img.shields.io/badge/Bytecode-Transform-blue)
![Attach](https://img.shields.io/badge/DisableAttach-Bypass-important)
## 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 or retransformation without requiring a `javaagent`. It can still work when `DisableAttachMechanism=true`.
## Introduction
JuiceAgent is a JVMTI-native injection framework for loading external JARs and redefining or retransformation Java bytecode in a target JVM without requiring a javaagent. It also works when DisableAttachMechanism=true.
With JuiceAgent, developers can:
- Dynamically load external JARs into a running JVM process
- Execute custom Java code after injection
- Redefine already loaded classes at runtime
- Retransform bytecode for instrumentation or modification
- And more...
## Index
## Features
This project is the native implementation of JuiceAgent-API. For the API definition, see [JuiceAgent.java](https://github.com/xiaozhou233/JuiceAgent-API/blob/master/src/main/java/cn/xiaozhou233/juiceagent/api/JuiceAgent.java).
This project is the native implementation of JuiceAgent-API. See [JuiceAgent.java](https://github.com/xiaozhou233/JuiceAgent-API/blob/master/src/main/java/cn/xiaozhou233/juiceagent/api/JuiceAgent.java) for the API definition.
- `addToBootstrapClassLoaderSearch`
- `addToSystemClassLoaderSearch`
- `addToClassLoader`
- `defineClass`
- `redefineClass(ByName)`
- `retransformClass(ByName)`
- `getLoadedClasses`
- `getClassByName`
- `getClassBytes(ByName)`
- Load JARs into the Bootstrap or System ClassLoader
- Define classes dynamically
- Redefine classes by name or class reference
- Retransform classes by name or class reference
- Get all loaded classes
- Find classes by name
- Get class bytecode by name or class reference
## How To Use
## Quick Start
### 1. Download Release
Download `libagent.dll` `libinject.dll` `libloader.dll` and `injector.exe` from the [releases](https://github.com/xiaozhou233/JuiceAgent/releases) page.
### 1. Download Files
Download the following files from [Releases](https://github.com/xiaozhou233/JuiceAgent/releases) and place them in `YourDir`:
Download `JuiceAgent-API-x.x.x+build.x.jar` from the [JuiceAgent-API](https://github.com/xiaozhou233/JuiceAgent-API/releases) page.
- `libagent.dll`
- `libinject.dll`
- `libloader.dll`
- `injector.exe`
Put the downloaded files into the same directory.
- YourDir
- JuiceAgent-API-x.x.x+build.x.jar
- libagent.dll
- libinject.dll
- libloader.dll
- injector.exe
Download `JuiceAgent-API-X.X.X+build.X.jar` from [JuiceAgent-API Releases](https://github.com/xiaozhou233/JuiceAgent-API/releases) and place it in `YourDir`.
### 2. Copy your custom JAR/Dependencies to Directory
- YourDir
- JuiceAgent-API-x.x.x+build.x.jar
- libagent.dll
- libinject.dll
- libloader.dll
- injector.exe
- **MyCustonJar.jar**
- **injection**
- **Dependencies1.jar**
- **Dependencies2.jar**
### 2. Write the Config File
Create a file named `config.toml` in `YourDir`.
### 3. Write Config
```toml
[JuiceAgent]
Version = 1
[JuiceAgent.Loader]
JuiceAgentAPIJarPath = ""
# Path to JuiceAgent-API-x.x.x+build.x.jar
JuiceAgentAPIJarPath = "./JuiceAgent-API-x.x.x+build.x.jar"
# Path to libagent.dll, default is "./libagent.dll"
JuiceAgentNativeLibraryPath = ""
[JuiceAgent.Modules]
[JuiceAgent.Modules.JarLoader]
Enabled = true
InjectionDir = ""
JarPath = ""
EntryClass = ""
EntryMethod = ""
# Path to the Injection JAR files to be loaded
InjectionDir = "./injection"
# Path to the JAR file to be loaded
JarPath = "./MyCustonJar.jar"
# Entry class to be executed after loading the JAR
EntryClass = "Example.Main"
# Entry method to be executed after loading the JAR
EntryMethod = "run"
```
### 3. Run the Injector
Save the config file as `config.toml`.
- YourDir
- **config.toml**
- JuiceAgent-API-x.x.x+build.x.jar
- libagent.dll
- libinject.dll
- libloader.dll
- injector.exe
- MyCustonJar.jar
- injection
- Dependencies1.jar
- Dependencies2.jar
### 4. Run the Injector
#### Method A: Use `injector.exe`
Run `injector.exe` from `YourDir`.
@@ -71,40 +120,11 @@ Input PID:
Enter the PID of the target JVM process and press Enter.
#### Method B: Use JNI to call `inject`
Create `cn/xiaozhou233/juiceagent/injector/InjectorNative.java` in your project:
```java
package cn.xiaozhou233.juiceagent.injector;
See [Documents](https://github.com/xiaozhou233/JuiceAgent/blob/master/docs/Inject.md) for details.
public class InjectorNative {
/*
* @param pid target process id
* @param path injection DLL path
*/
public native boolean inject(int pid, String path);
/*
* @param pid target process id
* @param path injection DLL path
* @param configDir directory containing config.toml
*/
public native boolean inject(int pid, String path, String configDir);
}
```
Example:
```java
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
System.load("<path-to-libinject>");
InjectorNative injectorNative = new InjectorNative();
injectorNative.inject(<pid>, "<path-to-libloader>", "<path-to-config-directory>");
```
### 4. Done
If the injection succeeds, the target process will load `Entry.jar` (or the file specified by `EntryJarPath`) and invoke `EntryClass.EntryMethod` (default: `com.example.Entry.start`).
### 5. Done
The target JVM will load the specified JAR and execute the specified entry class and method.
## How To Build
@@ -142,5 +162,5 @@ This project is intended for learning and research in controlled environments on
## Acknowledgements
- [ReflectiveDLLInjection](https://github.com/stephenfewer/ReflectiveDLLInjection) - DLL injection implementation
- [plog](https://github.com/SergiusTheBest/plog) - Portable, simple, and extensible C++ logging library
- [tinytoml](https://github.com/mayah/tinytoml) - Header-only C++11 TOML parser
- [toml11](https://github.com/ToruNiina/toml11) - TOML for Modern C++
- [eventpp](https://github.com/wqking/eventpp) - C++ library for event dispatchers and callback lists
+146
View File
@@ -0,0 +1,146 @@
# JuiceAgent
[English](https://github.com/xiaozhou233/JuiceAgent/blob/main/README.md) | [中文](https://github.com/xiaozhou233/JuiceAgent/blob/main/README_zh.md)
JuiceAgent is a JVMTI-based injection library for loading external JARs and transforming Java bytecode, even when `DisableAttachMechanism` is enabled.
**Notice:** Currently, only **Windows** is supported. **Linux** support may be added in the future.
**Notice:** The current repository version is **Version 3.3 Build 1**.
**Warning:** This project is still experimental and is not recommended for production use. Use it at your own risk.
## 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 or retransformation without requiring a `javaagent`. It can still work when `DisableAttachMechanism=true`.
## Features
This project is the native implementation of JuiceAgent-API. For the API definition, see [JuiceAgent.java](https://github.com/xiaozhou233/JuiceAgent-API/blob/master/src/main/java/cn/xiaozhou233/juiceagent/api/JuiceAgent.java).
- `addToBootstrapClassLoaderSearch`
- `addToSystemClassLoaderSearch`
- `addToClassLoader`
- `defineClass`
- `redefineClass(ByName)`
- `retransformClass(ByName)`
- `getLoadedClasses`
- `getClassByName`
- `getClassBytes(ByName)`
## How To Use
### 1. Download Files
Download the following files from [Releases](https://github.com/xiaozhou233/JuiceAgent/releases) and place them in `YourDir`:
- `libagent.dll`
- `libinject.dll`
- `libloader.dll`
- `injector.exe`
Download `JuiceAgent-API-X.X.X+build.X.jar` from [JuiceAgent-API Releases](https://github.com/xiaozhou233/JuiceAgent-API/releases) and place it in `YourDir`.
### 2. Write the Config File
Create a file named `config.toml` in `YourDir`.
```toml
[JuiceAgent]
Version = 1
[JuiceAgent.Loader]
JuiceAgentAPIJarPath = ""
JuiceAgentNativeLibraryPath = ""
[JuiceAgent.Modules]
[JuiceAgent.Modules.JarLoader]
Enabled = true
InjectionDir = ""
JarPath = ""
EntryClass = ""
EntryMethod = ""
```
### 3. Run the Injector
#### Method A: Use `injector.exe`
Run `injector.exe` from `YourDir`.
```text
<jps output>
Input PID:
```
Enter the PID of the target JVM process and press Enter.
#### Method B: Use JNI to call `inject`
Create `cn/xiaozhou233/juiceagent/injector/InjectorNative.java` in your project:
```java
package cn.xiaozhou233.juiceagent.injector;
public class InjectorNative {
/*
* @param pid target process id
* @param path injection DLL path
*/
public native boolean inject(int pid, String path);
/*
* @param pid target process id
* @param path injection DLL path
* @param configDir directory containing config.toml
*/
public native boolean inject(int pid, String path, String configDir);
}
```
Example:
```java
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
System.load("<path-to-libinject>");
InjectorNative injectorNative = new InjectorNative();
injectorNative.inject(<pid>, "<path-to-libloader>", "<path-to-config-directory>");
```
### 4. Done
If the injection succeeds, the target process will load `Entry.jar` (or the file specified by `EntryJarPath`) and invoke `EntryClass.EntryMethod` (default: `com.example.Entry.start`).
## How To Build
### Requirements
- Java 8+
- MinGW
- CMake 3.15+
- Ninja
### Build with CMake Presets
```powershell
git clone https://github.com/xiaozhou233/JuiceAgent.git
cd JuiceAgent
cmake --preset ninja-release
cmake --build build
```
### Manual Build
```powershell
git clone https://github.com/xiaozhou233/JuiceAgent.git
cd JuiceAgent
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
```
The generated binaries will be placed in `build/bin`.
`JuiceAgent-API.jar` can be built from or downloaded from [JuiceAgent-API](https://github.com/xiaozhou233/JuiceAgent-API).
## Full 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 that their actions are legal and compliant.
## Acknowledgements
- [ReflectiveDLLInjection](https://github.com/stephenfewer/ReflectiveDLLInjection) - DLL injection implementation
- [plog](https://github.com/SergiusTheBest/plog) - Portable, simple, and extensible C++ logging library
- [tinytoml](https://github.com/mayah/tinytoml) - Header-only C++11 TOML parser
- [eventpp](https://github.com/wqking/eventpp) - C++ library for event dispatchers and callback lists
-146
View File
@@ -1,146 +0,0 @@
# JuiceAgent
[English](https://github.com/xiaozhou233/JuiceAgent/blob/main/README.md) | [中文](https://github.com/xiaozhou233/JuiceAgent/blob/main/README_zh.md)
JuiceAgent 是一个基于 JVMTI 的注入库,用于加载外部 JAR 并对 Java 字节码进行转换;即使启用了 `DisableAttachMechanism` 也可以使用。
**注意:** 当前仅支持 **Windows**,未来可能会支持 **Linux**。
**注意:** 当前仓库版本为 **Version 3.3 Build 1**。
**警告:** 本项目仍处于实验阶段,不建议在生产环境中使用。使用风险请自行承担。
## 简介
JuiceAgent 是一个基于 JVMTI 的原生注入框架。它通过向目标 JVM 注入原生代码,动态加载外部 JAR,并执行字节码重定义或重转换,而不需要 `javaagent`。在 `DisableAttachMechanism=true` 的情况下依然可以工作。
## 功能特性
本项目是 JuiceAgent-API 的原生实现。API 定义可参考 [JuiceAgent.java](https://github.com/xiaozhou233/JuiceAgent-API/blob/master/src/main/java/cn/xiaozhou233/juiceagent/api/JuiceAgent.java)。
- `addToBootstrapClassLoaderSearch`
- `addToSystemClassLoaderSearch`
- `addToClassLoader`
- `defineClass`
- `redefineClass(ByName)`
- `retransformClass(ByName)`
- `getLoadedClasses`
- `getClassByName`
- `getClassBytes(ByName)`
## 使用方法
### 1. 下载文件
从 [Releases](https://github.com/xiaozhou233/JuiceAgent/releases) 下载以下文件,并放到 `YourDir` 中:
- `libagent.dll`
- `libinject.dll`
- `libloader.dll`
- `injector.exe`
从 [JuiceAgent-API Releases](https://github.com/xiaozhou233/JuiceAgent-API/releases) 下载 `JuiceAgent-API-X.X.X+build.X.jar`,并放到 `YourDir` 中。
### 2. 编写配置文件
在 `YourDir` 下创建 `config.toml`:
```toml
[JuiceAgent]
Version = 1
[JuiceAgent.Loader]
JuiceAgentAPIJarPath = ""
JuiceAgentNativeLibraryPath = ""
[JuiceAgent.Modules]
[JuiceAgent.Modules.JarLoader]
Enabled = true
InjectionDir = ""
JarPath = ""
EntryClass = ""
EntryMethod = ""
```
### 3. 执行注入
#### 方法 A:使用 `injector.exe`
在 `YourDir` 中运行 `injector.exe`。
```text
<jps 输出>
Input PID:
```
输入目标 JVM 进程的 PID 后按回车。
#### 方法 B:通过 JNI 调用 `inject`
在你的项目中创建 `cn/xiaozhou233/juiceagent/injector/InjectorNative.java`:
```java
package cn.xiaozhou233.juiceagent.injector;
public class InjectorNative {
/*
* @param pid target process id
* @param path injection DLL path
*/
public native boolean inject(int pid, String path);
/*
* @param pid target process id
* @param path injection DLL path
* @param configDir 包含 config.toml 的目录
*/
public native boolean inject(int pid, String path, String configDir);
}
```
调用示例:
```java
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
System.load("<path-to-libinject>");
InjectorNative injectorNative = new InjectorNative();
injectorNative.inject(<pid>, "<path-to-libloader>", "<path-to-config-directory>");
```
### 4. 完成
如果注入成功,目标进程会加载 `Entry.jar`(或 `EntryJarPath` 指定的文件),并调用 `EntryClass.EntryMethod`(默认值为 `com.example.Entry.start`)。
## 构建方法
### 环境要求
- Java 8+
- MinGW
- CMake 3.15+
- Ninja
### 使用 CMake Presets 构建
```powershell
git clone https://github.com/xiaozhou233/JuiceAgent.git
cd JuiceAgent
cmake --preset ninja-release
cmake --build build
```
### 手动构建
```powershell
git clone https://github.com/xiaozhou233/JuiceAgent.git
cd JuiceAgent
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
```
生成的二进制文件位于 `build/bin`。
`JuiceAgent-API.jar` 可以在 [JuiceAgent-API](https://github.com/xiaozhou233/JuiceAgent-API) 项目中构建,或直接从其发布页下载。
## 完整免责声明
本项目仅用于受控环境中的学习与研究。对于任何未经授权的使用、修改、破解,或违反适用协议与法律的行为所产生的后果,作者概不负责。使用者应自行确保其行为合法合规,并承担全部责任。
## 致谢
- [ReflectiveDLLInjection](https://github.com/stephenfewer/ReflectiveDLLInjection) - DLL 注入实现
- [plog](https://github.com/SergiusTheBest/plog) - 轻量、可扩展的 C++ 日志库
- [tinytoml](https://github.com/mayah/tinytoml) - Header-only C++11 TOML 解析库
- [eventpp](https://github.com/wqking/eventpp) - 用于事件分发和回调列表的 C++ 库
+4 -1
View File
@@ -16,4 +16,7 @@
## 2026-04-19
- [x] 在 `JuiceAgent/Utils.hpp`做序列化操作
- [x] 统一调用 module的Java实现
- [x] 统一调用 module的Java实现
## 2026-04-20
- [ ] 修改文档
+44
View File
@@ -0,0 +1,44 @@
# Inject Method
## Method A: Use `injector.exe`
Run `injector.exe` from `YourDir`.
```text
<jps output>
Input PID:
```
Enter the PID of the target JVM process and press Enter.
## Method B: Use JNI to call `inject`
Create `cn/xiaozhou233/juiceagent/injector/InjectorNative.java` in your project:
```java
package cn.xiaozhou233.juiceagent.injector;
public class InjectorNative {
/*
* @param pid target process id
* @param path injection DLL path
*/
public native boolean inject(int pid, String path);
/*
* @param pid target process id
* @param path injection DLL path
* @param configDir directory containing config.toml
*/
public native boolean inject(int pid, String path, String configDir);
}
```
Example:
```java
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
System.load("<path-to-libinject>");
InjectorNative injectorNative = new InjectorNative();
injectorNative.inject(<pid>, "<path-to-libloader>", "<path-to-config-directory>");
```
File diff suppressed because it is too large. Load diff