mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
382bfb7fed | ||
|
|
560215c0ae | ||
|
|
55303b7dc9 | ||
|
|
41049f1852 | ||
|
|
396ec1a96f | ||
|
|
10ec330480 | ||
|
|
0ddcfcd7c8 | ||
|
|
87a91376c5 | ||
|
|
dbae5e5258 | ||
|
|
ff216aabee | ||
|
|
18a923373b | ||
|
|
6fe467bccf | ||
|
|
4bed99f417 |
No files matched your search
@@ -1,3 +1,4 @@
|
||||
build/
|
||||
.cache/
|
||||
*.log
|
||||
dist/
|
||||
@@ -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
@@ -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
@@ -1 +1,3 @@
|
||||
Version 4.1.0
|
||||
Major=4
|
||||
Minor=1
|
||||
Patch=2
|
||||
@@ -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>");
|
||||
```
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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}")
|
||||
@@ -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{};
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace JuiceAgent {
|
||||
JuiceAgent::Config::Config config;
|
||||
|
||||
bool loaded = false;
|
||||
bool initialized_ = false;
|
||||
public:
|
||||
// Singleton
|
||||
static Agent& getInstance();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user