[WIP] [Update & BugFix] Config

This commit is contained in:
xiaozhou233 committed 2025-10-17 03:32:49 +08:00
1 parent 09944abe08
commit 9a13a10a23
8 files changed
+94 -118

No files matched your search

+1 -6
View File
@@ -6,12 +6,7 @@
#define INJECT_PATH_MAX 4096
typedef struct InjectParameters{
char JuiceLoaderJarPath[INJECT_PATH_MAX];
char BootstrapApiPath[INJECT_PATH_MAX];
// Optional:
char JuiceLoaderLibPath[INJECT_PATH_MAX];
// Optional:
char EntryJarPath[INJECT_PATH_MAX];
char ConfigPath[INJECT_PATH_MAX];
} InjectParameters;
#endif
Binary file not shown.
+4 -3
View File
@@ -4,11 +4,12 @@ public class InjectorNative {
/*
* @param pid target process id
*/
public native boolean inject(int pid);
public native boolean inject(int pid, String path);
/*
* @param pid target process id
* @param path libinjector path
* @param path injection dll path
* @param configPath config file path
*/
public native boolean inject(int pid, String path);
public native boolean inject(int pid, String path, String configPath);
}
@@ -7,14 +7,6 @@
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: cn_xiaozhou233_juiceagent_injector_InjectorNative
* Method: inject
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__I
(JNIEnv *, jobject, jint);
/*
* Class: cn_xiaozhou233_juiceagent_injector_InjectorNative
* Method: inject
@@ -23,6 +15,14 @@ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNativ
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__ILjava_lang_String_2
(JNIEnv *, jobject, jint, jstring);
/*
* Class: cn_xiaozhou233_juiceagent_injector_InjectorNative
* Method: inject
* Signature: (ILjava/lang/String;Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__ILjava_lang_String_2Ljava_lang_String_2
(JNIEnv *, jobject, jint, jstring, jstring);
#ifdef __cplusplus
}
#endif
+2
View File
@@ -1 +1,3 @@
# src/core/CMakeLists.txt
target_link_libraries(agent PRIVATE shlwapi)
+32 -33
View File
@@ -23,11 +23,7 @@ DWORD WINAPI ThreadProc(LPVOID lpParam) {
return 1;
}
log_info("%s ThreadProc got param: \nJuiceLoaderJarPath: %s\nJuiceLoaderLibPath: %s\nEntryJarPath: %s\nBootstrapApiPath: %s", LOG_PREFIX,
param->JuiceLoaderJarPath,
param->JuiceLoaderLibPath,
param->EntryJarPath,
param->BootstrapApiPath);
log_info("%s ThreadProc got param: ConfigPath: %s", LOG_PREFIX, param->ConfigPath);
const char* bootstrapApiJar = param->BootstrapApiPath;
if (bootstrapApiJar == NULL) {
@@ -147,41 +143,44 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved){
log_info("%s DLL_PROCESS_ATTACH", LOG_PREFIX);
DisableThreadLibraryCalls(hinstDLL);
InjectParameters *localParm = (InjectParameters*)malloc(sizeof(InjectParameters));
if (localParm == NULL) {
log_error("%s malloc failed for InjectParameters", LOG_PREFIX);
break;
}
memset(localParm, 0, sizeof(InjectParameters));
if (lpReserved != NULL) {
InjectParameters *remoteParm = (InjectParameters*)lpReserved;
InjectParameters *localParm = (InjectParameters*)malloc(sizeof(InjectParameters));
if (localParm == NULL) {
log_error("%s malloc failed for InjectParameters", LOG_PREFIX);
break;
}
memset(localParm, 0, sizeof(InjectParameters));
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\nBootstrapApiPath: %s", LOG_PREFIX,
localParm->JuiceLoaderJarPath,
localParm->JuiceLoaderLibPath,
localParm->EntryJarPath,
localParm->BootstrapApiPath);
HANDLE hThread = CreateThread(NULL, 0, ThreadProc, localParm, 0, NULL);
if (hThread) {
CloseHandle(hThread);
} else {
log_error("%s CreateThread failed %lu", LOG_PREFIX, GetLastError());
free(localParm);
}
safe_copy(localParm->ConfigPath, remoteParm->ConfigPath, sizeof(localParm->ConfigPath));
} else {
log_error("%s RemoteParm is NULL!", LOG_PREFIX);
log_info("%s RemoteParm is NULL!", LOG_PREFIX);
char DllDir[INJECT_PATH_MAX] = {0};
if (GetModuleFileNameA(hinstDLL, DllDir, MAX_PATH) != 0) {
PathRemoveFileSpecA(DllDir);
log_info("%s path: %s", LOG_PREFIX, DllDir);
} else {
log_error("GetModuleFileName failed, error=%lu\n", GetLastError());
return -1;
}
safe_copy(localParm->ConfigPath, DllDir, sizeof(localParm->ConfigPath));
}
log_info("%s ConfigPath: %s", LOG_PREFIX, localParm->ConfigPath);
HANDLE hThread = CreateThread(NULL, 0, ThreadProc, localParm, 0, NULL);
if (hThread) {
CloseHandle(hThread);
} else {
log_error("%s CreateThread failed %lu", LOG_PREFIX, GetLastError());
free(localParm);
}
break;
case DLL_PROCESS_DETACH:
log_info("%s DLL_PROCESS_DETACH", LOG_PREFIX);
break;
+8 -8
View File
@@ -7,14 +7,6 @@
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: cn_xiaozhou233_juiceagent_injector_InjectorNative
* Method: inject
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__I
(JNIEnv *, jobject, jint);
/*
* Class: cn_xiaozhou233_juiceagent_injector_InjectorNative
* Method: inject
@@ -23,6 +15,14 @@ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNativ
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__ILjava_lang_String_2
(JNIEnv *, jobject, jint, jstring);
/*
* Class: cn_xiaozhou233_juiceagent_injector_InjectorNative
* Method: inject
* Signature: (ILjava/lang/String;Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__ILjava_lang_String_2Ljava_lang_String_2
(JNIEnv *, jobject, jint, jstring, jstring);
#ifdef __cplusplus
}
#endif
+39 -60
View File
@@ -137,7 +137,7 @@ int inject(int pid, char *path, InjectParameters *params){
InjectParameters verify;
SIZE_T read = 0;
if (ReadProcessMemory(hProcess, lpRemoteParam, &verify, sizeof(InjectParameters), &read)) {
log_debug("[*] Read back remote param, JuiceLoaderJarPath=%.*s", (int)sizeof(verify.JuiceLoaderJarPath), verify.JuiceLoaderJarPath);
log_debug("[*] Read back remote param, ConfigPath=%.*s", (int)sizeof(verify.ConfigPath), verify.ConfigPath);
} else {
log_error("[-] ReadProcessMemory failed: %lu", GetLastError());
}
@@ -187,65 +187,44 @@ int inject(int pid, char *path, InjectParameters *params){
return bSuccess ? 0 : -1;
}
/* wrapper using HOME */
int inject_pid(int pid){
const char* home = getenv("HOME");
if (!home) {
home = getenv("USERPROFILE");
if (!home)
return -1;
}
char dir[INJECT_PATH_MAX];
snprintf(dir, sizeof(dir), "%s\\JuiceAgent\\", home);
char path[INJECT_PATH_MAX];
snprintf(path, sizeof(path), "%s\\libagent.dll", dir);
char loaderJarPath[INJECT_PATH_MAX];
snprintf(loaderJarPath, sizeof(loaderJarPath), "%s\\JuiceLoader.jar", dir);
InjectParameters params;
memset(&params, 0, sizeof(params));
strncpy(params.JuiceLoaderJarPath, loaderJarPath, sizeof(params.JuiceLoaderJarPath) - 1);
params.JuiceLoaderJarPath[sizeof(params.JuiceLoaderJarPath) - 1] = '\0';
strncpy(params.JuiceLoaderLibPath, "", sizeof(params.JuiceLoaderLibPath) - 1);
params.JuiceLoaderLibPath[sizeof(params.JuiceLoaderLibPath) - 1] = '\0';
strncpy(params.EntryJarPath, "", sizeof(params.EntryJarPath) - 1);
params.EntryJarPath[sizeof(params.EntryJarPath) - 1] = '\0';
return inject(pid, path, &params);
}
/* 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, 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(&params, 0, sizeof(params));
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, &params);
if (localAgentPath) (*env)->ReleaseStringUTFChars(env, jAgentPth, localAgentPath);
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);
/*
* JNI Function: inject(int pid)
* Note:
*/
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__ILjava_lang_String_2
(JNIEnv *env, jobject obj, jint pid, jstring path) {
// Injection Path
const char* InjectionDLL = (*env)->GetStringUTFChars(env, path, NULL);
int ret = inject(pid, InjectionDLL, NULL);
(*env)->ReleaseStringUTFChars(env, path, InjectionDLL);
return (ret == 0) ? JNI_TRUE : JNI_FALSE;
}
/*
* JNI Function: inject(int pid, String path)
* Param pid: target process id
* Param path: path of inject dll
* Param configPath: path of config file (toml)
*/
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__ILjava_lang_String_2Ljava_lang_String_2
(JNIEnv *env, jobject obj, jint pid , jstring path, jstring configPath){
// Injection Path
const char* InjectionDLL = (*env)->GetStringUTFChars(env, path, NULL);
// Config Path
const char* ConfigPath = (*env)->GetStringUTFChars(env, configPath, NULL);
InjectParameters params;
memset(&params, 0, sizeof(params));
strncpy(params.ConfigPath, ConfigPath ? ConfigPath : "", sizeof(params.ConfigPath)-1);
int ret = inject(pid, (char*)InjectionDLL, &params);
// Clean up
(*env)->ReleaseStringUTFChars(env, path, InjectionDLL);
(*env)->ReleaseStringUTFChars(env, configPath, ConfigPath);
return (ret == 0) ? JNI_TRUE : JNI_FALSE;
}