@@ -223,6 +223,55 @@ static int hook_dlopen(int api_level) {
223223 return result ;
224224}
225225
226+ #define SH_LINKER_SYM_CALL_CONSTRUCTORS_L "__dl__ZN6soinfo16CallConstructorsEv"
227+ #define SH_LINKER_SYM_CALL_DESTRUCTORS_L "__dl__ZN6soinfo15CallDestructorsEv"
228+ #define SH_LINKER_SYM_CALL_CONSTRUCTORS_M "__dl__ZN6soinfo17call_constructorsEv"
229+ #define SH_LINKER_SYM_CALL_DESTRUCTORS_M "__dl__ZN6soinfo16call_destructorsEv"
230+
231+ typedef void (* linker_proxy_soinfo_call_ctors_t )(void * );
232+ static linker_proxy_soinfo_call_ctors_t linker_orig_soinfo_call_ctors ;
233+ static void linker_proxy_soinfo_call_ctors (void * soinfo ) {
234+ if (SHADOWHOOK_IS_SHARED_MODE )
235+ SHADOWHOOK_CALL_PREV (linker_proxy_soinfo_call_ctors , linker_proxy_soinfo_call_ctors_t , soinfo );
236+ else
237+ linker_orig_soinfo_call_ctors (soinfo );
238+
239+ if (SHADOWHOOK_IS_SHARED_MODE ) SHADOWHOOK_POP_STACK ();
240+ }
241+
242+ typedef void (* linker_proxy_soinfo_call_dtors_t )(void * );
243+ static linker_proxy_soinfo_call_dtors_t linker_orig_soinfo_call_dtors ;
244+ static void linker_proxy_soinfo_call_dtors (void * soinfo ) {
245+ if (SHADOWHOOK_IS_SHARED_MODE )
246+ SHADOWHOOK_CALL_PREV (linker_proxy_soinfo_call_dtors , linker_proxy_soinfo_call_dtors_t , soinfo );
247+ else
248+ linker_orig_soinfo_call_dtors (soinfo );
249+
250+ if (SHADOWHOOK_IS_SHARED_MODE ) SHADOWHOOK_POP_STACK ();
251+ }
252+
253+ static int hook_call_ctors_dtors (int api_level ) {
254+ static int result = -1 ;
255+ static bool hooked = false;
256+
257+ if (hooked ) return result ;
258+ hooked = true;
259+
260+ void * stub_ctors = shadowhook_hook_sym_name (
261+ LINKER_BASENAME ,
262+ api_level >= __ANDROID_API_M__ ? SH_LINKER_SYM_CALL_CONSTRUCTORS_M : SH_LINKER_SYM_CALL_CONSTRUCTORS_L ,
263+ (void * )linker_proxy_soinfo_call_ctors , (void * * )& linker_orig_soinfo_call_ctors );
264+ int errno_ctors = shadowhook_get_errno ();
265+ void * stub_dtors = shadowhook_hook_sym_name (
266+ LINKER_BASENAME ,
267+ api_level >= __ANDROID_API_M__ ? SH_LINKER_SYM_CALL_DESTRUCTORS_M : SH_LINKER_SYM_CALL_DESTRUCTORS_L ,
268+ (void * )linker_proxy_soinfo_call_dtors , (void * * )& linker_orig_soinfo_call_dtors );
269+ int errno_dtors = shadowhook_get_errno ();
270+
271+ result = (NULL != stub_ctors && NULL != stub_dtors && 0 == errno_ctors && 0 == errno_dtors ) ? 0 : -1 ;
272+ return result ;
273+ }
274+
226275// end of - hooking dlopen() or do_dlopen()
227276///////////////////////////////////////////////////////////////////////////
228277
@@ -270,6 +319,7 @@ PROXY(t16_cbnz_t1)
270319PROXY (t16_cbnz_t1_fixaddr )
271320PROXY (t16_it_t1_case1 )
272321PROXY (t16_it_t1_case2 )
322+ PROXY (t16_it_t1_case3 )
273323
274324PROXY (t32_b_t3 )
275325PROXY (t32_b_t4 )
@@ -398,6 +448,13 @@ static int unittest_hook(int api_level) {
398448 return -1 ;
399449 }
400450
451+ if (api_level >= __ANDROID_API_L__ ) {
452+ if (0 != hook_call_ctors_dtors (api_level )) {
453+ LOG ("hook soinfo::call_constructors() and get soinfo::call_destructors() FAILED" );
454+ return -1 ;
455+ }
456+ }
457+
401458#if defined(__arm__ )
402459
403460 HOOK (t16_b_t1 );
@@ -454,6 +511,7 @@ static int unittest_hook(int api_level) {
454511 HOOK (a32_ldr_lit_a1_case2 );
455512 HOOK (a32_ldr_reg_a1_case1 );
456513 HOOK (a32_ldr_reg_a1_case2 );
514+ HOOK (t16_it_t1_case3 );
457515
458516#elif defined(__aarch64__ )
459517
@@ -538,6 +596,7 @@ int unittest_unhook(void) {
538596 UNHOOK (t16_cbnz_t1_fixaddr );
539597 UNHOOK (t16_it_t1_case1 );
540598 UNHOOK (t16_it_t1_case2 );
599+ UNHOOK (t16_it_t1_case3 );
541600
542601 UNHOOK (t32_b_t3 );
543602 UNHOOK (t32_b_t4 );
@@ -644,6 +703,7 @@ int unittest_run(bool hookee2_loaded) {
644703 RUN (t16_cbnz_t1_fixaddr );
645704 RUN (t16_it_t1_case1 );
646705 RUN (t16_it_t1_case2 );
706+ RUN (t16_it_t1_case3 );
647707
648708 LOG (DELIMITER , "TEST INST T32" );
649709 RUN (t32_b_t3 );
@@ -731,6 +791,12 @@ int unittest_run(bool hookee2_loaded) {
731791 RUN_WITH_DLSYM (libhookee2 .so , hook_before_dlopen_2 );
732792 }
733793
794+ LOG (DELIMITER , "TEST - dlopen" );
795+ void * handle = dlopen ("libc.so" , RTLD_NOW );
796+ dlclose (handle );
797+ handle = dlopen ("libshadowhook_nothing.so" , RTLD_NOW );
798+ dlclose (handle );
799+
734800 return 0 ;
735801}
736802
0 commit comments