Compare commits

...
13 Commits
Author SHA1 Message Date
xiaozhou233 382bfb7fed Version 4.1.2 2026-10-11 14:23:16 +08:00
xiaozhou233 560215c0ae Feat: add version-based packaging script
Add script/package.bat and script/package.cmake to package build/bin artifacts into a versioned zip under dist/.

Version.txt now uses Major/Minor/Patch key-value format so the script can parse it, and dist/ is ignored.
2026-10-10 22:16:09 +08:00
xiaozhou233 55303b7dc9 BugFix: fix getClassBytesByName cannot get class in some environments 2026-08-25 20:32:56 +08:00
xiaozhou233 41049f1852 Docs: Fix doc path 2026-08-19 19:03:05 +08:00
xiaozhou233 396ec1a96f Docs: Update Inject.md 2026-08-19 19:01:25 +08:00
xiaozhou233 10ec330480 Version 4.1.1 2026-08-19 18:36:07 +08:00
xiaozhou233 0ddcfcd7c8 Remove remapper whitelist JNI declarations 2026-08-19 18:30:58 +08:00
xiaozhou233 87a91376c5 Remove JuiceRemapper module
Remove the runtime class remapping feature including its JNI bindings, service, config example, and Remapper singleton from global.hpp.
2026-08-19 18:29:38 +08:00
xiaozhou233 dbae5e5258 Fix: do not auto-read config when runtime dir is empty
Config no longer falls back to the current working directory when no
runtime directory is specified, so an empty runtime dir leaves the config
invalid instead of silently parsing config.toml from the CWD.
2026-08-18 20:11:00 +08:00
xiaozhou233 ff216aabee Fix: harden remapper filters and agent init guard
- skip empty include/exclude entries in Remapper::shouldRemap to avoid
  calling back() on an empty std::string (undefined behavior)
- null-check new_class_data_len/new_classbytes in JuiceRemapperService
  before writing remapped bytes back to the JVMTI callback
- add Agent::initialized_ guard so init() is a no-op on second call,
  preventing duplicate service instantiation and listeners
2026-08-18 16:51:21 +08:00
xiaozhou233 18a923373b Merge branch 'feat/remapper' into main 2026-08-18 16:43:47 +08:00
xiaozhou233 6fe467bccf Feat: add include/exclude filters for JuiceRemapper
- add thread-safe include/exclude sets to Remapper; shouldRemap matches
  exact name, package prefix (trailing '/'), or nested class ('\$' after
  the prefix), with exclude taking priority
- remapping stays OFF by default: an empty include set remaps nothing;
  it is only enabled once addInclude is called (no config include)
- implement addInclude/addExclude/removeInclude/removeExclude/
  clearIncludes/clearExcludes JNI bindings
- apply shouldRemap filter in JuiceRemapperService::onClassFileLoadHook
2026-08-18 16:41:55 +08:00
xiaozhou233 4bed99f417 Feat: add JuiceRemapper runtime class remapping
- add JuiceRemapperService that listens for ClassFileLoadHook and calls
  the Java static Remap.remap(String, byte[]) via cached JNI declarations,
  then writes the returned bytes back to the JVMTI callback
- add JNI bindings (initNative, add/remove/clear include/exclude) with
  Remapper singleton init state and cached jclass/jmethodID stored in
  Remapper (global.hpp)
- cache static class/method declarations lazily in initNative to avoid
  repeated FindClass/GetStaticMethodID
- add generated JuiceRemapper JNI header and runtime-remap example config
2026-08-18 16:28:29 +08:00
12 changed files with 130 additions and 67 deletions

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
build/
.cache/
*.log
dist/
+1 -19
View File
@@ -170,25 +170,7 @@ You can also pass arguments directly: `injector.exe <pid> <libloader.dll path> [
#### 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 {
public native boolean inject(int pid, String path);
public native boolean inject(int pid, String path, String configDir);
}
```
Example:
```java
System.load("<path-to-libinject.dll>");
InjectorNative injectorNative = new InjectorNative();
injectorNative.inject(<pid>, "<path-to-libloader.dll>", "<path-to-config-directory>");
```
See [Inject](docs/Inject.md)
### 5. Done
+1 -19
View File
@@ -171,25 +171,7 @@ Input PID:
#### 方法 B:通过 JNI 调用 `inject`
在你的项目中创建 `cn/xiaozhou233/juiceagent/injector/InjectorNative.java`:
```java
package cn.xiaozhou233.juiceagent.injector;
public class InjectorNative {
public native boolean inject(int pid, String path);
public native boolean inject(int pid, String path, String configDir);
}
```
示例:
```java
System.load("<libinject.dll 的路径>");
InjectorNative injectorNative = new InjectorNative();
injectorNative.inject(<pid>, "<libloader.dll 的路径>", "<配置文件所在目录>");
```
看 [Inject](docs/Inject.md)
### 5. 完成
+3 -1
View File
@@ -1 +1,3 @@
Version 4.1.0
Major=4
Minor=1
Patch=2
+26
View File
@@ -0,0 +1,26 @@
# 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`
Download the JuiceAgent-JavaInjector-x.x-xxxx.jar from [here](https://github.com/xiaozhou233/JuiceAgent-JavaInjector/releases).
Add JuiceAgent-JavaInjector-x.x-xxxx.jar to your classpath.
Example:
```java
import cn.xiaozhou233.juiceagent.injector.Injector;
System.load("<path-to-libinject>");
Injector.inject(<pid>, "<path-to-libloader>", "<path-to-config-directory>");
```
+7 -3
View File
@@ -15,9 +15,13 @@ class Config {
public:
explicit Config(const std::filesystem::path& runtime_dir = {})
{
_runtime_dir = runtime_dir.empty()
? std::filesystem::current_path()
: runtime_dir;
_runtime_dir = runtime_dir;
// No runtime directory specified: do not auto-read a config file
// from the current working directory.
if (runtime_dir.empty()) {
return;
}
const auto result = toml::try_parse(_runtime_dir / "config.toml");
@@ -111,30 +111,6 @@ JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getCl
JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassBytesByName
(JNIEnv *, jclass, jstring);
/*
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
* Method: addRemapperWhiteList
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addRemapperWhiteList
(JNIEnv *, jclass, jstring);
/*
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
* Method: removeRemapperWhiteList
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_removeRemapperWhiteList
(JNIEnv *, jclass, jstring);
/*
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
* Method: clearRemapperWhiteList
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_clearRemapperWhiteList
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
+16
View File
@@ -0,0 +1,16 @@
@echo off
setlocal
set "ROOT_DIR=%~dp0"
cmake -P "%ROOT_DIR%package.cmake"
if errorlevel 1 (
echo [ERROR] Packaging failed.
exit /b 1
)
echo [SUCCESS] Packaging completed.
pause
+68
View File
@@ -0,0 +1,68 @@
# Resolve project directory
get_filename_component(PROJECT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
set(VERSION_FILE "${PROJECT_DIR}/Version.txt")
set(BIN_DIR "${PROJECT_DIR}/build/bin")
set(OUTPUT_DIR "${PROJECT_DIR}/dist")
file(MAKE_DIRECTORY "${OUTPUT_DIR}")
# Read version file
if(NOT EXISTS "${VERSION_FILE}")
message(FATAL_ERROR "Version.txt not found: ${VERSION_FILE}")
endif()
file(STRINGS "${VERSION_FILE}" VERSION_LINES)
foreach(LINE IN LISTS VERSION_LINES)
if(LINE MATCHES "^[ \t]*Major[ \t]*=[ \t]*([0-9]+)[ \t]*$")
set(VERSION_MAJOR "${CMAKE_MATCH_1}")
elseif(LINE MATCHES "^[ \t]*Minor[ \t]*=[ \t]*([0-9]+)[ \t]*$")
set(VERSION_MINOR "${CMAKE_MATCH_1}")
elseif(LINE MATCHES "^[ \t]*Patch[ \t]*=[ \t]*([0-9]+)[ \t]*$")
set(VERSION_PATCH "${CMAKE_MATCH_1}")
endif()
endforeach()
if(NOT DEFINED VERSION_MAJOR OR
NOT DEFINED VERSION_MINOR OR
NOT DEFINED VERSION_PATCH)
message(FATAL_ERROR "Invalid Version.txt: Major, Minor and Patch are required")
endif()
# Define package files
set(PACKAGE_FILES
injector.exe
libinject.dll
libloader.dll
libagent.dll
)
foreach(FILE_NAME IN LISTS PACKAGE_FILES)
if(NOT EXISTS "${BIN_DIR}/${FILE_NAME}")
message(FATAL_ERROR "Required file not found: ${BIN_DIR}/${FILE_NAME}")
endif()
endforeach()
# Create package
set(OUTPUT_FILE
"${OUTPUT_DIR}/JuiceAgent_v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_x64.zip"
)
file(REMOVE "${OUTPUT_FILE}")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E tar
cf "${OUTPUT_FILE}"
--format=zip
${PACKAGE_FILES}
WORKING_DIRECTORY "${BIN_DIR}"
RESULT_VARIABLE TAR_RESULT
)
if(NOT TAR_RESULT STREQUAL "0")
message(FATAL_ERROR "Failed to create ZIP package: ${TAR_RESULT}")
endif()
message(STATUS "Package created: ${OUTPUT_FILE}")
+5
View File
@@ -69,6 +69,11 @@ namespace JuiceAgent {
spdlog::error("[JuiceAgent] Agent not loaded! Please call preload() first!");
return false;
}
if(initialized_) {
spdlog::warn("[JuiceAgent] Agent already initialized! Skipping...");
return true;
}
initialized_ = true;
// Add Abilities
jvmtiCapabilities caps{};
+1
View File
@@ -13,6 +13,7 @@ namespace JuiceAgent {
JuiceAgent::Config::Config config;
bool loaded = false;
bool initialized_ = false;
public:
// Singleton
static Agent& getInstance();
+1 -1
View File
@@ -108,7 +108,7 @@ JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getCl
std::string internalName = dottedToInternal(utf);
env->ReleaseStringUTFChars(name, utf);
jclass clazz = env->FindClass(internalName.c_str());
jclass clazz = findLoadedClass(agent.getJVMTI(), env, internalName);
if (!clazz) {
if (env->ExceptionCheck()) env->ExceptionClear();
spdlog::error("[bytecode] Class not found: {}", internalName);