1
1
#include " Platform.hxx"
2
2
3
3
#if defined(__linux__)
4
+ #if defined(CUSTOM_INJECTOR)
4
5
#include " Injection/Injector.hxx"
6
+ #else
7
+ #include " Thirdparty/Injector.hxx"
8
+ #endif
9
+
5
10
#include < X11/Xlib.h>
6
11
#include < X11/Xatom.h>
7
12
#include < X11/Xutil.h>
@@ -197,10 +202,35 @@ std::int32_t InjectProcess(std::int32_t pid) noexcept
197
202
std::string path = std::string (PATH_MAX, ' \0 ' );
198
203
if (realpath (info.dli_fname , &path[0 ]))
199
204
{
205
+ #if defined(CUSTOM_INJECTOR)
200
206
if (Injector::Inject (info.dli_fname , pid, nullptr ))
201
207
{
202
208
return pid;
203
209
}
210
+ #else
211
+ extern std::vector<std::unique_ptr<Injector>> injectors;
212
+
213
+ for (auto & injector : injectors)
214
+ {
215
+ if (injector && injector->get_pid () == pid)
216
+ {
217
+ if (injector->is_injected ())
218
+ {
219
+ return pid;
220
+ }
221
+
222
+ return injector->Inject (info.dli_fname ) ? pid : -1 ;
223
+ }
224
+ }
225
+
226
+ std::unique_ptr<Injector> injector = std::make_unique<Injector>(pid);
227
+ if (injector)
228
+ {
229
+ bool result = injector->Inject (info.dli_fname );
230
+ injectors.push_back (std::move (injector));
231
+ return result ? pid : -1 ;
232
+ }
233
+ #endif
204
234
}
205
235
}
206
236
return -1 ;
@@ -455,8 +485,8 @@ void* GetModuleHandle(const char* module_name) noexcept
455
485
}
456
486
}
457
487
return 0 ;
458
- }, reinterpret_cast < void *>( &module_info) );
459
- return module_info.result ?: dlopen (module_name, RTLD_NOLOAD);
488
+ }, &module_info);
489
+ return module_info.result ? module_info. result : dlopen (module_name, RTLD_NOLOAD);
460
490
}
461
491
#endif
462
492
@@ -558,50 +588,6 @@ std::unique_ptr<Reflection> GetNativeReflector() noexcept
558
588
{
559
589
std::unique_ptr<Reflection> reflection;
560
590
bool hasReflection = TimeOut (20 , [&]{
561
- jclass cls = env->FindClass (" java/awt/Frame" );
562
- if (!cls)
563
- {
564
- return false ;
565
- }
566
-
567
- jmethodID method = env->GetStaticMethodID (cls, " getFrames" , " ()[Ljava/awt/Frame;" );
568
- if (!method)
569
- {
570
- return false ;
571
- }
572
-
573
- jobjectArray frames = static_cast <jobjectArray>(env->CallStaticObjectMethod (cls, method));
574
- env->DeleteLocalRef (cls);
575
- if (!frames)
576
- {
577
- return false ;
578
- }
579
-
580
- jsize size = env->GetArrayLength (frames);
581
- for (jsize i = 0 ; i < size; ++i)
582
- {
583
- jobject frame = env->GetObjectArrayElement (frames, i);
584
- if (frame)
585
- {
586
- if (IsValidFrame (env, frame))
587
- {
588
- reflection = Reflection::Create (frame);
589
- if (reflection)
590
- {
591
- env->DeleteLocalRef (frames);
592
- return true ;
593
- }
594
- }
595
-
596
- env->DeleteLocalRef (frame);
597
- }
598
- }
599
-
600
- env->DeleteLocalRef (frames);
601
- return false ;
602
- });
603
-
604
- bool hasReflection2 = !hasReflection && TimeOut (20 , [&]{
605
591
if (!ModuleLoaded (" libawt_xawt.so" ))
606
592
{
607
593
return false ;
@@ -617,7 +603,7 @@ std::unique_ptr<Reflection> GetNativeReflector() noexcept
617
603
void * windowFrame = reinterpret_cast <void *>(GetMainWindow ());
618
604
if (windowFrame)
619
605
{
620
- jobject frame = awt_GetComponent (reflection-> getEnv () , windowFrame); // java.awt.Frame
606
+ jobject frame = awt_GetComponent (env , windowFrame); // java.awt.Frame
621
607
if (frame)
622
608
{
623
609
if (IsValidFrame (env, frame))
@@ -634,7 +620,7 @@ std::unique_ptr<Reflection> GetNativeReflector() noexcept
634
620
});
635
621
});
636
622
637
- if (hasReflection || hasReflection2 )
623
+ if (hasReflection)
638
624
{
639
625
return reflection;
640
626
}
0 commit comments