Compare commits

..
5 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
8 changed files with 117 additions and 40 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.1
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>");
```
+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}")
+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);