From d01517f09cccdcd05da24bb315fb07b1c025f492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=91=A8XiaoZhou?= Date: Mon, 13 Oct 2025 13:15:52 +0800 Subject: [PATCH] [Update] BootstrapAPI [Add] Entry can use JuiceLoader Now! --- includes/JuiceAgent/InjectParameters.h | 1 + src/agent/libagent.c | 33 +++++++++++++++++++++----- src/injector/include/InjectorNative.h | 2 +- src/injector/libinjector.c | 5 +++- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/includes/JuiceAgent/InjectParameters.h b/includes/JuiceAgent/InjectParameters.h index 7fbf6a0..864a29f 100644 --- a/includes/JuiceAgent/InjectParameters.h +++ b/includes/JuiceAgent/InjectParameters.h @@ -7,6 +7,7 @@ typedef struct InjectParameters{ char JuiceLoaderJarPath[INJECT_PATH_MAX]; + char BootstrapApiPath[INJECT_PATH_MAX]; // Optional: char JuiceLoaderLibPath[INJECT_PATH_MAX]; // Optional: diff --git a/src/agent/libagent.c b/src/agent/libagent.c index 5046c52..cbd406a 100644 --- a/src/agent/libagent.c +++ b/src/agent/libagent.c @@ -23,15 +23,30 @@ DWORD WINAPI ThreadProc(LPVOID lpParam) { return 1; } - log_info("%s ThreadProc got param: \nJuiceLoaderJarPath: %s\nJuiceLoaderLibPath: %s\nEntryJarPath: %s", LOG_PREFIX, + log_info("%s ThreadProc got param: \nJuiceLoaderJarPath: %s\nJuiceLoaderLibPath: %s\nEntryJarPath: %s\nBootstrapApiPath: %s", LOG_PREFIX, param->JuiceLoaderJarPath, param->JuiceLoaderLibPath, - param->EntryJarPath); + param->EntryJarPath, + param->BootstrapApiPath); + + const char* bootstrapApiJar = param->BootstrapApiPath; + if (bootstrapApiJar == NULL) { + log_error("%s BootstrapApiPath is not set", LOG_PREFIX); + MessageBoxA(NULL, "BootstrapApiPath is not set", "Error", MB_OK); + return 1; + } + + log_trace("%s Checking bootstrap-api.jar", LOG_PREFIX); + if (access(bootstrapApiJar, 0) == -1) { + log_error("%s bootstrap-api.jar not found", LOG_PREFIX); + MessageBoxA(NULL, "bootstrap-api.jar not found", "Error", MB_OK); + return 1; + } const char* loaderJar = param->JuiceLoaderJarPath; if (loaderJar == NULL) { - log_error("%s LoaderDir is not set", LOG_PREFIX); - MessageBoxA(NULL, "LoaderDir is not set", "Error", MB_OK); + log_error("%s JuiceLoaderJarPath is not set", LOG_PREFIX); + MessageBoxA(NULL, "JuiceLoaderJarPath is not set", "Error", MB_OK); return 1; } @@ -81,6 +96,10 @@ DWORD WINAPI ThreadProc(LPVOID lpParam) { log_info("%s Enabled jvmti", LOG_PREFIX); // Inject jars + log_info("%s injecting bootstrap-api jar...", LOG_PREFIX); + (*jvmti)->AddToBootstrapClassLoaderSearch(jvmti, bootstrapApiJar); + log_info("%s injected bootstrap-api jar", LOG_PREFIX); + log_info("%s injecting loader jar...", LOG_PREFIX); (*jvmti)->AddToBootstrapClassLoaderSearch(jvmti, loaderJar); log_info("%s injected loader jar", LOG_PREFIX); @@ -143,11 +162,13 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved){ safe_copy(localParm->JuiceLoaderJarPath, remoteParm->JuiceLoaderJarPath, sizeof(localParm->JuiceLoaderJarPath)); safe_copy(localParm->JuiceLoaderLibPath, remoteParm->JuiceLoaderLibPath, sizeof(localParm->JuiceLoaderLibPath)); safe_copy(localParm->EntryJarPath, remoteParm->EntryJarPath, sizeof(localParm->EntryJarPath)); + safe_copy(localParm->BootstrapApiPath, remoteParm->BootstrapApiPath, sizeof(localParm->BootstrapApiPath)); - log_info("%s DllMain got param: \nJuiceLoaderJarPath: %s\nJuiceLoaderLibPath: %s\nEntryJarPath: %s", LOG_PREFIX, + log_info("%s DllMain got param: \nJuiceLoaderJarPath: %s\nJuiceLoaderLibPath: %s\nEntryJarPath: %s\nBootstrapApiPath: %s", LOG_PREFIX, localParm->JuiceLoaderJarPath, localParm->JuiceLoaderLibPath, - localParm->EntryJarPath); + localParm->EntryJarPath, + localParm->BootstrapApiPath); HANDLE hThread = CreateThread(NULL, 0, ThreadProc, localParm, 0, NULL); if (hThread) { diff --git a/src/injector/include/InjectorNative.h b/src/injector/include/InjectorNative.h index ddfa190..789cd6c 100644 --- a/src/injector/include/InjectorNative.h +++ b/src/injector/include/InjectorNative.h @@ -13,7 +13,7 @@ extern "C" { * Signature: (ILjava/lang/String;)Z */ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_orangex_injector_InjectorNative_inject - (JNIEnv *, jobject, jint, jstring, jstring, jstring, jstring); + (JNIEnv *, jobject, jint, jstring, jstring, jstring, jstring, jstring); #ifdef __cplusplus diff --git a/src/injector/libinjector.c b/src/injector/libinjector.c index 4b5fd28..f1249f3 100644 --- a/src/injector/libinjector.c +++ b/src/injector/libinjector.c @@ -223,12 +223,13 @@ int inject_pid(int pid){ /* JNI interface */ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_orangex_injector_InjectorNative_inject - (JNIEnv *env, jobject obj, jint pid,jstring jAgentPth, jstring jJuiceLoaderJarPath, jstring jJuiceLoaderLibPath, jstring jEntryJarPath) { + (JNIEnv *env, jobject obj, jint pid,jstring jAgentPth, jstring jJuiceLoaderJarPath, jstring jJuiceLoaderLibPath, jstring jEntryJarPath, jstring jBootStrapApiPath) { const char* localAgentPath = (*env)->GetStringUTFChars(env, jAgentPth, NULL); const char* localLoaderJar = (*env)->GetStringUTFChars(env, jJuiceLoaderJarPath, NULL); const char* localLoaderLib = (*env)->GetStringUTFChars(env, jJuiceLoaderLibPath, NULL); const char* localEntryJar = (*env)->GetStringUTFChars(env, jEntryJarPath, NULL); + const char* bootstrapApiPath = (*env)->GetStringUTFChars(env, jBootStrapApiPath, NULL); InjectParameters params; memset(¶ms, 0, sizeof(params)); @@ -236,6 +237,7 @@ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_orangex_injector_InjectorNative_i strncpy(params.JuiceLoaderJarPath, localLoaderJar ? localLoaderJar : "", sizeof(params.JuiceLoaderJarPath)-1); strncpy(params.JuiceLoaderLibPath, localLoaderLib ? localLoaderLib : "", sizeof(params.JuiceLoaderLibPath)-1); strncpy(params.EntryJarPath, localEntryJar ? localEntryJar : "", sizeof(params.EntryJarPath)-1); + strncpy(params.BootstrapApiPath, bootstrapApiPath ? bootstrapApiPath : "", sizeof(params.BootstrapApiPath)-1); int ret = inject(pid, (char*)localAgentPath, ¶ms); @@ -243,6 +245,7 @@ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_orangex_injector_InjectorNative_i if (localLoaderJar) (*env)->ReleaseStringUTFChars(env, jJuiceLoaderJarPath, localLoaderJar); if (localLoaderLib) (*env)->ReleaseStringUTFChars(env, jJuiceLoaderLibPath, localLoaderLib); if (localEntryJar) (*env)->ReleaseStringUTFChars(env, jEntryJarPath, localEntryJar); + if (bootstrapApiPath) (*env)->ReleaseStringUTFChars(env, jBootStrapApiPath, bootstrapApiPath); return (ret == 0) ? JNI_TRUE : JNI_FALSE; }