|
37 | 37 |
|
38 | 38 | #pragma clang diagnostic push |
39 | 39 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" |
40 | | -#define LOG(fmt, ...) __android_log_print(ANDROID_LOG_INFO, "shadowhook_tag", fmt, ##__VA_ARGS__) |
41 | | -#pragma clang diagnostic pop |
| 40 | +#pragma clang diagnostic ignored "-Wunused-function" |
| 41 | +#pragma clang diagnostic ignored "-Wunused-variable" |
42 | 42 |
|
| 43 | +#define LOG(fmt, ...) __android_log_print(ANDROID_LOG_INFO, "shadowhook_tag", fmt, ##__VA_ARGS__) |
43 | 44 | #define DELIMITER ">>>>>>>>>>>>>>>>>>> %s >>>>>>>>>>>>>>>>>>>" |
44 | 45 | #define TO_STR_HELPER(x) #x |
45 | 46 | #define TO_STR(x) TO_STR_HELPER(x) |
@@ -119,7 +120,7 @@ typedef int (*test_t)(int, int); |
119 | 120 |
|
120 | 121 | #define UNHOOK_WITH_TAG(inst, tag) \ |
121 | 122 | do { \ |
122 | | - if (NULL == stub_##inst##tag) return -1; \ |
| 123 | + if (NULL == stub_##inst##tag) break; \ |
123 | 124 | int r_ = shadowhook_unhook(stub_##inst##tag); \ |
124 | 125 | stub_##inst##tag = NULL; \ |
125 | 126 | if (0 != r_) { \ |
@@ -225,6 +226,30 @@ static int hook_dlopen(int api_level) { |
225 | 226 | // end of - hooking dlopen() or do_dlopen() |
226 | 227 | /////////////////////////////////////////////////////////////////////////// |
227 | 228 |
|
| 229 | +/////////////////////////////////////////////////////////////////////////// |
| 230 | +// hooking hidden function (without symbol info in ELF) |
| 231 | + |
| 232 | +static test_t test_hidden_func = NULL; |
| 233 | +PROXY(hidden_func) |
| 234 | + |
| 235 | +static void run_hidden_func(void) { |
| 236 | + if (NULL == test_hidden_func) test_hidden_func = (test_t)get_hidden_func_addr(); |
| 237 | + RUN(hidden_func); |
| 238 | +} |
| 239 | + |
| 240 | +static int hook_hidden_func(void) { |
| 241 | + if (NULL == test_hidden_func) test_hidden_func = (test_t)get_hidden_func_addr(); |
| 242 | + if (NULL != stub_hidden_func) return -1; |
| 243 | + stub_hidden_func = shadowhook_hook_func_addr( |
| 244 | + (void *)test_hidden_func, |
| 245 | + SHADOWHOOK_IS_UNIQUE_MODE ? (void *)unique_proxy_hidden_func : (void *)shared_proxy_hidden_func, |
| 246 | + (void **)(&orig_hidden_func)); |
| 247 | + return NULL == stub_hidden_func ? -1 : 0; |
| 248 | +} |
| 249 | + |
| 250 | +// end of - hooking hidden function (without symbol info in ELF) |
| 251 | +/////////////////////////////////////////////////////////////////////////// |
| 252 | + |
228 | 253 | /////////////////////////////////////////////////////////////////////////// |
229 | 254 | // (1) test proxy for instructions |
230 | 255 |
|
@@ -458,6 +483,13 @@ static int unittest_hook(int api_level) { |
458 | 483 |
|
459 | 484 | #endif |
460 | 485 |
|
| 486 | + if (unittest_is_hook_addr) { |
| 487 | + if (0 != hook_hidden_func()) { |
| 488 | + LOG("hook hidden function FAILED"); |
| 489 | + return -1; |
| 490 | + } |
| 491 | + } |
| 492 | + |
461 | 493 | if (SHADOWHOOK_IS_SHARED_MODE) { |
462 | 494 | HOOK(recursion_1); |
463 | 495 | HOOK(recursion_2); |
@@ -574,6 +606,8 @@ int unittest_unhook(void) { |
574 | 606 |
|
575 | 607 | #endif |
576 | 608 |
|
| 609 | + UNHOOK(hidden_func); |
| 610 | + |
577 | 611 | if (SHADOWHOOK_IS_SHARED_MODE) { |
578 | 612 | UNHOOK(recursion_1); |
579 | 613 | UNHOOK(recursion_2); |
@@ -681,18 +715,23 @@ int unittest_run(bool hookee2_loaded) { |
681 | 715 |
|
682 | 716 | #endif |
683 | 717 |
|
| 718 | + LOG(DELIMITER, "TEST - hidden function"); |
| 719 | + run_hidden_func(); |
| 720 | + |
684 | 721 | if (SHADOWHOOK_IS_SHARED_MODE) { |
685 | | - LOG(DELIMITER, "TEST BIZ - recursion"); |
| 722 | + LOG(DELIMITER, "TEST - recursion"); |
686 | 723 | RUN(recursion_1); |
687 | | - LOG(DELIMITER, "TEST BIZ - hook multi times"); |
| 724 | + LOG(DELIMITER, "TEST - hook multi times"); |
688 | 725 | RUN(hook_multi_times); |
689 | 726 | } |
690 | 727 |
|
691 | 728 | if (hookee2_loaded) { |
692 | | - LOG(DELIMITER, "TEST BIZ - hook before dlopen"); |
| 729 | + LOG(DELIMITER, "TEST - hook before dlopen"); |
693 | 730 | RUN_WITH_DLSYM(libhookee2.so, hook_before_dlopen_1); |
694 | 731 | RUN_WITH_DLSYM(libhookee2.so, hook_before_dlopen_2); |
695 | 732 | } |
696 | 733 |
|
697 | 734 | return 0; |
698 | 735 | } |
| 736 | + |
| 737 | +#pragma clang diagnostic pop |
0 commit comments