mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Docs: rewrite README to match current module structure and config
This commit is contained in:
1 parent
b17ce02ae1
commit
8b5ea4cf28
1 file changed
+87
-44
@@ -1,6 +1,6 @@
|
||||
# JuiceAgent
|
||||
|
||||
JuiceAgent is an advanced JVMTI-based injection framework designed for runtime JAR loading, bytecode transformation, and runtime JVM instrumentation, even when DisableAttachMechanism is enabled.
|
||||
JuiceAgent is an advanced JVMTI-based injection framework for runtime JAR loading, bytecode transformation, and runtime JVM instrumentation. It injects into a running JVM process even when `DisableAttachMechanism=true`, without requiring `-javaagent` startup arguments or the attach mechanism.
|
||||
|
||||
**Warning**: This project is still experimental and is not recommended for production use. Use it at your own risk.
|
||||
|
||||
@@ -23,61 +23,77 @@ JuiceAgent is an advanced JVMTI-based injection framework designed for runtime J
|
||||

|
||||

|
||||
|
||||
## Introduction
|
||||
JuiceAgent is a JVMTI-native injection framework for loading external JARs and redefining or retransformation of Java classes in a target JVM without requiring -javaagent startup arguments or attach javaagent. It also works when DisableAttachMechanism=true.
|
||||
|
||||
With JuiceAgent, developers can:
|
||||
- Dynamically load external JARs into a running JVM process
|
||||
- Invoke a specified entry class and method after injection
|
||||
- Redefine already loaded classes at runtime
|
||||
- Retransform bytecode for instrumentation or modification
|
||||
- And more...
|
||||
|
||||
**If you have any questions or suggestions, please feel free to open an issue or submit a pull request. =D**
|
||||
|
||||
## Index
|
||||
|
||||
- [JuiceAgent](#juiceagent)
|
||||
- [Introduction](#introduction)
|
||||
- [Index](#index)
|
||||
- [How It Works](#how-it-works)
|
||||
- [Features](#features)
|
||||
- [Project Structure](#project-structure)
|
||||
- [Quick Start](#quick-start)
|
||||
- [1. Download Release](#1-download-release)
|
||||
- [2. Copy your custom JAR/Dependencies to Directory](#2-copy-your-custom-jardependencies-to-directory)
|
||||
- [3. Write Config](#3-write-config)
|
||||
- [4. Run the Injector](#4-run-the-injector)
|
||||
- [Method A: Use `injector.exe`](#method-a-use-injectorexe)
|
||||
- [Method B: Use JNI to call `inject`](#method-b-use-jni-to-call-inject)
|
||||
- [5. Done](#5-done)
|
||||
- [JuiceAgent API](#juiceagent-api)
|
||||
- [Examples](#examples)
|
||||
- [How To Build](#how-to-build)
|
||||
- [Requirements](#requirements)
|
||||
- [Build with CMake Presets](#build-with-cmake-presets)
|
||||
- [Manual Build](#manual-build)
|
||||
- [Full Disclaimer](#full-disclaimer)
|
||||
- [Acknowledgements](#acknowledgements)
|
||||
|
||||
## Features
|
||||
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.
|
||||
## Introduction
|
||||
|
||||
- Load JARs into the Bootstrap or System ClassLoader
|
||||
JuiceAgent is the native implementation of the [JuiceAgent-API](https://github.com/xiaozhou233/JuiceAgent-API). It loads external JARs into a running JVM, invokes a specified entry class/method, and redefines or retransforms already-loaded classes — all without a `-javaagent` startup flag and even when `DisableAttachMechanism=true`.
|
||||
|
||||
With JuiceAgent, developers can:
|
||||
|
||||
- Dynamically load external JARs into a running JVM process
|
||||
- Invoke a specified entry class and method after injection
|
||||
- Redefine already loaded classes at runtime
|
||||
- Retransform bytecode for instrumentation or modification
|
||||
- Query loaded classes and read class bytecode
|
||||
|
||||
**If you have any questions or suggestions, please feel free to open an issue or submit a pull request. =D**
|
||||
|
||||
## How It Works
|
||||
|
||||
1. `injector.exe` (or `libinject.dll` via JNI) reflectively injects `libloader.dll` into the target JVM process.
|
||||
2. `libloader.dll` attaches to the JVM, reads `config.toml`, extracts the embedded `JuiceAgent-API` jar, and adds it to the system class loader search path.
|
||||
3. The loader bootstraps the agent: it loads `libagent.dll` and initializes the JVMTI agent (`JuiceAgent::Agent`).
|
||||
4. The agent registers JVMTI callbacks and starts the configured modules (e.g. `JarLoader`), which loads the target JAR and invokes the entry class/method.
|
||||
|
||||
The `JuiceAgent-API` jar is embedded in the native binaries, so no separate download is required.
|
||||
|
||||
## Features
|
||||
|
||||
- Load external JARs into the Bootstrap or System ClassLoader
|
||||
- Add JARs to an arbitrary class loader
|
||||
- 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
|
||||
- Find a class by name
|
||||
- Get class bytecode by name or class reference
|
||||
- Automatic JVM attachment that works with `DisableAttachMechanism=true`
|
||||
|
||||
## Project Structure
|
||||
|
||||
- `src/libloader` — `libloader.dll`. Injected into the target JVM. Attaches to the JVM, parses `config.toml`, injects the embedded `JuiceAgent-API`, and bootstraps the agent.
|
||||
- `src/libagent` — `libagent.dll`. The JVMTI agent. Registers callbacks (e.g. `ClassFileLoadHook`) and implements the native side of `JuiceAgent-API`.
|
||||
- `src/libinjector` — `injector.exe` + `libinject.dll`. Reflective DLL injector that loads `libloader.dll` into the target process. Can be driven from the command line or through JNI.
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Download Release
|
||||
|
||||
Download `JuiceAgent_vx.x.x_x64.zip` from the [releases](https://github.com/xiaozhou233/JuiceAgent/releases) page.
|
||||
|
||||
Extract the ZIP file to a directory.
|
||||
Extract the ZIP file to a directory:
|
||||
|
||||
- YourDir
|
||||
- libagent.dll
|
||||
- libinject.dll
|
||||
- libloader.dll
|
||||
- injector.exe
|
||||
|
||||
### 2. Copy your custom JAR/Dependencies to Directory
|
||||
### 2. Copy your Custom JAR / Dependencies
|
||||
|
||||
- YourDir
|
||||
- libagent.dll
|
||||
- libinject.dll
|
||||
@@ -95,8 +111,6 @@ Extract the ZIP file to a directory.
|
||||
Version = 1
|
||||
|
||||
[JuiceAgent.Loader]
|
||||
# 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 = ""
|
||||
|
||||
@@ -104,18 +118,17 @@ JuiceAgentNativeLibraryPath = ""
|
||||
|
||||
[JuiceAgent.Modules.JarLoader]
|
||||
Enabled = true
|
||||
# Path to the Injection JAR files to be loaded
|
||||
# Directory containing dependency JARs to load first
|
||||
InjectionDir = "./injection"
|
||||
# Path to the JAR file to be loaded
|
||||
JarPath = "./MyCustomJar.jar"
|
||||
# Entry class to be executed after loading the JAR
|
||||
EntryClass = "Example.Main"
|
||||
# Entry method to be executed after loading the JAR
|
||||
# Method: public static void run()
|
||||
# Entry method, must be: public static void run()
|
||||
EntryMethod = "run"
|
||||
```
|
||||
|
||||
Save the config file as `config.toml`.
|
||||
Save the file as `config.toml` in the same directory (the runtime directory). Relative paths are resolved against the runtime directory.
|
||||
|
||||
- YourDir
|
||||
- **config.toml**
|
||||
@@ -131,7 +144,8 @@ Save the config file as `config.toml`.
|
||||
### 4. Run the Injector
|
||||
|
||||
#### Method A: Use `injector.exe`
|
||||
Run `injector.exe` from `YourDir`.
|
||||
|
||||
Run `injector.exe` from `YourDir`:
|
||||
|
||||
```text
|
||||
<jps output>
|
||||
@@ -140,22 +154,50 @@ Input PID:
|
||||
|
||||
Enter the PID of the target JVM process and press Enter.
|
||||
|
||||
You can also pass arguments directly: `injector.exe <pid> <libloader.dll path> [libinject.dll path]`.
|
||||
|
||||
#### Method B: Use JNI to call `inject`
|
||||
|
||||
See [Documents](https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/Inject.md) for details.
|
||||
See [docs/Inject.md](docs/Inject.md) for details.
|
||||
|
||||
### 5. Done
|
||||
|
||||
The target JVM will load the specified JAR and execute the specified entry class and method.
|
||||
|
||||
## JuiceAgent API
|
||||
|
||||
The following native functions are exposed to Java through the `cn.xiaozhou233.juiceagent.api.JuiceAgent` class (see the [JuiceAgent-API](https://github.com/xiaozhou233/JuiceAgent-API) project for the Java API definition):
|
||||
|
||||
- `init(String runtimeDir)` — initialize the agent from Java
|
||||
- `addToBootstrapClassLoaderSearch(String jarPath)`
|
||||
- `addToSystemClassLoaderSearch(String jarPath)`
|
||||
- `addToClassLoader(String jarPath, ClassLoader targetClassLoader)`
|
||||
- `defineClass(ClassLoader targetClassLoader, byte[] bytes)` — returns `Class<?>`
|
||||
- `redefineClass(Class<?> clazz, byte[] classBytes, int length)`
|
||||
- `redefineClassByName(String className, byte[] classBytes, int length)`
|
||||
- `retransformClass(Class<?> clazz, byte[] bytecodes, int length)`
|
||||
- `retransformClassByName(String className, byte[] bytecodes, int length)`
|
||||
- `getLoadedClasses()` — returns `Class<?>[]`
|
||||
- `getClassByName(String name)` — returns `Class<?>`
|
||||
- `getClassBytes(Class<?> clazz)` — returns `byte[]`
|
||||
- `getClassBytesByName(String name)` — returns `byte[]`
|
||||
|
||||
## Examples
|
||||
|
||||
- `examples/load-via-injector-exe` — loads a JAR into a target JVM via `injector.exe` and runs an entry point.
|
||||
- `examples/retansform-class` — demonstrates class retransformation with a target JVM and a modified copy of the class.
|
||||
|
||||
## 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
|
||||
@@ -165,6 +207,7 @@ cmake --build build
|
||||
```
|
||||
|
||||
### Manual Build
|
||||
|
||||
```powershell
|
||||
git clone https://github.com/xiaozhou233/JuiceAgent.git
|
||||
cd JuiceAgent
|
||||
@@ -175,13 +218,13 @@ 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
|
||||
- [toml11](https://github.com/ToruNiina/toml11) - TOML for Modern C++
|
||||
- [eventpp](https://github.com/wqking/eventpp) - C++ library for event dispatchers and callback lists
|
||||
|
||||
- [ReflectiveDLLInjection](https://github.com/stephenfewer/ReflectiveDLLInjection) — DLL injection implementation
|
||||
- [plog](https://github.com/SergiusTheBest/plog) — Portable, simple, and extensible C++ logging library
|
||||
- [toml11](https://github.com/ToruNiina/toml11) — TOML for Modern C++
|
||||
- [eventpp](https://github.com/wqking/eventpp) — C++ library for event dispatchers and callback lists
|
||||
Reference in new issue
Block a user