|
5 | 5 | #include <string.h>
|
6 | 6 |
|
7 | 7 | #include <dlfcn.h>
|
| 8 | +#ifndef __APPLE__ |
| 9 | +# include <link.h> |
| 10 | +#endif |
8 | 11 |
|
9 | 12 | #include <JavaScriptCore/JavaScript.h>
|
10 | 13 |
|
@@ -376,13 +379,32 @@ bool proxy_execute_jscore_global_init(void) {
|
376 | 379 | g_proxy_execute_jscore.module = dlopen(
|
377 | 380 | "/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore", RTLD_LAZY | RTLD_LOCAL);
|
378 | 381 | #else
|
379 |
| - g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-4.1.so.0", RTLD_LAZY | RTLD_LOCAL); |
380 |
| - if (!g_proxy_execute_jscore.module) |
381 |
| - g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-4.0.so.18", RTLD_LAZY | RTLD_LOCAL); |
382 |
| - if (!g_proxy_execute_jscore.module) |
383 |
| - g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-3.0.so.0", RTLD_LAZY | RTLD_LOCAL); |
384 |
| - if (!g_proxy_execute_jscore.module) |
385 |
| - g_proxy_execute_jscore.module = dlopen("libjavascriptcoregtk-1.0.so.0", RTLD_LAZY | RTLD_LOCAL); |
| 382 | + const char *library_names[] = {"libjavascriptcoregtk-4.1.so.0", "libjavascriptcoregtk-4.0.so.18", |
| 383 | + "libjavascriptcoregtk-3.0.so.0", "libjavascriptcoregtk-1.0.so.0"}; |
| 384 | + const size_t library_names_size = sizeof(library_names) / sizeof(library_names[0]); |
| 385 | + |
| 386 | + // Use existing JavaScriptCoreGTK if already loaded |
| 387 | + struct link_map *map = NULL; |
| 388 | + void *current_process = dlopen(0, RTLD_LAZY); |
| 389 | + if (!current_process) |
| 390 | + return false; |
| 391 | + if (dlinfo(current_process, RTLD_DI_LINKMAP, &map) == 0) { |
| 392 | + while (map && !g_proxy_execute_jscore.module) { |
| 393 | + for (size_t i = 0; i < library_names_size; i++) { |
| 394 | + if (strstr(map->l_name, library_names[i])) { |
| 395 | + g_proxy_execute_jscore.module = dlopen(map->l_name, RTLD_NOLOAD | RTLD_LAZY | RTLD_LOCAL); |
| 396 | + break; |
| 397 | + } |
| 398 | + } |
| 399 | + map = map->l_next; |
| 400 | + } |
| 401 | + } |
| 402 | + dlclose(current_process); |
| 403 | + |
| 404 | + // Load the first available version of the JavaScriptCoreGTK |
| 405 | + for (size_t i = 0; !g_proxy_execute_jscore.module && i < library_names_size; i++) { |
| 406 | + g_proxy_execute_jscore.module = dlopen(library_names[i], RTLD_LAZY | RTLD_LOCAL); |
| 407 | + } |
386 | 408 | #endif
|
387 | 409 |
|
388 | 410 | if (!g_proxy_execute_jscore.module)
|
|
0 commit comments