mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
[Refactor] Merge agent and loader
This commit is contained in:
1 parent
96fee27476
commit
b46802faaa
12 files changed
+331
-356
No files matched your search
@@ -23,6 +23,14 @@ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNativ
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_inject__ILjava_lang_String_2Ljava_lang_String_2
|
||||
(JNIEnv *, jobject, jint, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_injector_InjectorNative
|
||||
* Method: findWindowsByTitle
|
||||
* Signature: (Ljava/lang/String;)[Lcn/xiaozhou233/juiceagent/injector/InjectorNative/WindowInfo;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_findWindowsByTitle
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -232,4 +232,64 @@ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNativ
|
||||
(*env)->ReleaseStringUTFChars(env, configDir, ConfigDir);
|
||||
|
||||
return (ret == 0) ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/// ================ FindWindowsByTitle =================
|
||||
#define MAX_RESULTS 128
|
||||
|
||||
typedef struct {
|
||||
wchar_t title[256];
|
||||
DWORD pid;
|
||||
} WindowData;
|
||||
|
||||
static wchar_t g_keyword[256];
|
||||
static WindowData g_results[MAX_RESULTS];
|
||||
static int g_count = 0;
|
||||
|
||||
|
||||
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
|
||||
wchar_t title[256];
|
||||
GetWindowTextW(hwnd, title, 256);
|
||||
if (wcslen(title) == 0) return TRUE;
|
||||
|
||||
if (wcsstr(title, g_keyword)) {
|
||||
DWORD pid = 0;
|
||||
GetWindowThreadProcessId(hwnd, &pid);
|
||||
|
||||
if (g_count < MAX_RESULTS && pid) {
|
||||
wcsncpy(g_results[g_count].title, title, 255);
|
||||
g_results[g_count].pid = pid;
|
||||
g_count++;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL Java_cn_xiaozhou233_juiceagent_injector_InjectorNative_findWindowsByTitle
|
||||
(JNIEnv *env, jclass clazz, jstring keyword) {
|
||||
|
||||
const jchar *input = (*env)->GetStringChars(env, keyword, NULL);
|
||||
wcsncpy(g_keyword, (const wchar_t *)input, 255);
|
||||
g_keyword[255] = L'\0';
|
||||
(*env)->ReleaseStringChars(env, keyword, input);
|
||||
|
||||
g_count = 0;
|
||||
EnumWindows(EnumWindowsProc, 0);
|
||||
|
||||
jclass infoClass = (*env)->FindClass(env, "cn/xiaozhou233/juiceagent/injector/InjectorNative$WindowInfo");
|
||||
if (!infoClass) return NULL;
|
||||
|
||||
jmethodID ctor = (*env)->GetMethodID(env, infoClass, "<init>", "(Ljava/lang/String;I)V");
|
||||
if (!ctor) return NULL;
|
||||
|
||||
jobjectArray array = (*env)->NewObjectArray(env, g_count, infoClass, NULL);
|
||||
|
||||
for (int i = 0; i < g_count; i++) {
|
||||
jstring title = (*env)->NewString(env, (jchar*)g_results[i].title, wcslen(g_results[i].title));
|
||||
jobject obj = (*env)->NewObject(env, infoClass, ctor, title, (jint)g_results[i].pid);
|
||||
(*env)->SetObjectArrayElement(env, array, i, obj);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
/// ===============================================================================
|
||||
Reference in new issue
Block a user