| 8 | |
| 9 | |
| 10 | JNIEXPORT void JNICALL Java_com_wrbug_dumpdex_Native_dump |
| 11 | (JNIEnv *env, jclass obj, jstring packageName) { |
| 12 | |
| 13 | static bool is_hook = false; |
| 14 | char *p = (char *) env->GetStringUTFChars(packageName, 0); |
| 15 | __android_log_print(ANDROID_LOG_ERROR, TAG, "%s", p); |
| 16 | if (is_hook) { |
| 17 | __android_log_print(ANDROID_LOG_INFO, TAG, "hooked ignore"); |
| 18 | return; |
| 19 | } |
| 20 | init_package_name(p); |
| 21 | env->ReleaseStringChars(packageName, (const jchar *) p); |
| 22 | ndk_init(env); |
| 23 | void *handle = ndk_dlopen("libart.so", RTLD_NOW); |
| 24 | if (handle == NULL) { |
| 25 | __android_log_print(ANDROID_LOG_ERROR, TAG, "Error: unable to find the SO : libart.so"); |
| 26 | return; |
| 27 | } |
| 28 | void *open_common_addr = ndk_dlsym(handle, get_open_function_flag()); |
| 29 | if (open_common_addr == NULL) { |
| 30 | __android_log_print(ANDROID_LOG_ERROR, TAG, |
| 31 | "Error: unable to find the Symbol : "); |
| 32 | return; |
| 33 | } |
| 34 | #if defined(__aarch64__) |
| 35 | A64HookFunction(open_common_addr, get_new_open_function_addr(), get_old_open_function_addr()); |
| 36 | __android_log_print(ANDROID_LOG_DEFAULT, TAG, "loaded so: libart.so"); |
| 37 | #elif defined(__arm__) |
| 38 | if (registerInlineHook((uint32_t) open_common_addr, (uint32_t) get_new_open_function_addr(), |
| 39 | (uint32_t **) get_old_open_function_addr()) != ELE7EN_OK) { |
| 40 | __android_log_print(ANDROID_LOG_ERROR, TAG, "register1 hook failed!"); |
| 41 | return; |
| 42 | } else { |
| 43 | __android_log_print(ANDROID_LOG_ERROR, TAG, "register1 hook success!"); |
| 44 | } |
| 45 | if (inlineHook((uint32_t) open_common_addr) != ELE7EN_OK) { |
| 46 | __android_log_print(ANDROID_LOG_ERROR, TAG, "register2 hook failed!"); |
| 47 | return; |
| 48 | } else { |
| 49 | __android_log_print(ANDROID_LOG_ERROR, TAG, "register2 hook success!"); |
| 50 | } |
| 51 | __android_log_print(ANDROID_LOG_DEFAULT, TAG, "loaded so: libart.so"); |
| 52 | #endif |
| 53 | __android_log_print(ANDROID_LOG_INFO, TAG, "hook init complete"); |
| 54 | is_hook = true; |
| 55 | } |
nothing calls this directly
no test coverage detected