From 9b6b3a350841213953a810d5e5e881b39291bc8d Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Fri, 11 Mar 2022 17:03:23 +0800 Subject: [PATCH 1/7] Merge branch 'main' of https://github.com/qqlittleice233/SimplicityTools into qqlittleice233-main --- .gitmodules | 3 + app/build.gradle.kts | 17 + app/proguard-rules.pro | 2 + app/src/main/cpp/CMakeLists.txt | 25 + app/src/main/cpp/biliroaming.cc | 669 ++++++++++++++++++ app/src/main/cpp/logging.h | 29 + app/src/main/cpp/native.cpp | 9 + app/src/main/cpp/native.h | 10 + app/src/main/cpp/native_api.h | 21 + .../hook/app/SecurityCenter.kt | 14 + .../securitycenter/ShowBatteryTemperature.kt | 39 + .../util/KotlinXposedHelper.kt | 2 + .../me/iacn/biliroaming/utils/DexHelper.java | 87 +++ 13 files changed, 927 insertions(+) create mode 100644 app/src/main/cpp/CMakeLists.txt create mode 100644 app/src/main/cpp/biliroaming.cc create mode 100644 app/src/main/cpp/logging.h create mode 100644 app/src/main/cpp/native.cpp create mode 100644 app/src/main/cpp/native.h create mode 100644 app/src/main/cpp/native_api.h create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt create mode 100644 app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java diff --git a/.gitmodules b/.gitmodules index 5f60ba22..4dcb4781 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "blockmiui"] path = blockmiui url = https://github.com/577fkj/blockmiui.git +[submodule "app/src/main/cpp/dex_builder"] + path = app/src/main/cpp/dex_builder + url = https://github.com/LSPosed/DexBuilder diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e2e14006..ca48cb36 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,6 +14,14 @@ android { targetSdk = 32 versionCode = 40 versionName = "1.3.9" + externalNativeBuild { + cmake { + targets("DexBuilder") + abiFilters("arm64-v8a") + cppFlags("-std=c++17") + cFlags("-std=gnu99") + } + } } buildTypes { @@ -53,6 +61,15 @@ android { "Simplicity_Tools_Xposed-${versionName}-${name}.apk" } } + androidResources { + noCompress("libDexBuilder.so") + } + externalNativeBuild { + cmake { + path("src/main/cpp/CMakeLists.txt") + } + } + ndkVersion = "23.1.7779620" } dependencies { diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 6102543f..12bb0427 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -36,5 +36,7 @@ public static void throw*(...); } +-keep class me.iacn.biliroaming.utils.DexHelper { *; } + -allowaccessmodification -overloadaggressively \ No newline at end of file diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt new file mode 100644 index 00000000..9c7d7553 --- /dev/null +++ b/app/src/main/cpp/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.18.1) + + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD 11) + +add_subdirectory(dex_builder) + +add_library( + DexBuilder + SHARED + native.cpp + biliroaming.cc + ) +target_include_directories(DexBuilder PUBLIC dex_builder/include) + +find_library( + log-lib + log) + +target_link_libraries( + DexBuilder + ${log-lib} + dex_builder_static + ) \ No newline at end of file diff --git a/app/src/main/cpp/biliroaming.cc b/app/src/main/cpp/biliroaming.cc new file mode 100644 index 00000000..8628d406 --- /dev/null +++ b/app/src/main/cpp/biliroaming.cc @@ -0,0 +1,669 @@ +#include +#include +#include + +#define LOG_TAG "QAuxv" +#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) +#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__) +#define PLOGE(fmt, args...) \ + LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) + +namespace { +jfieldID token_field; +jfieldID class_loader_field; +jmethodID load_class_method; +// jmethodID get_declared_method; +// jmethodID get_declared_field; +jmethodID get_name_method; +jmethodID get_declaring_class_method; +jmethodID get_parameters_method; +jmethodID get_class_name_method; +jfieldID path_list_field; +jfieldID element_field; +jfieldID dex_file_field; +jfieldID cookie_field; + +jclass LoadClass(JNIEnv *env, jobject class_loader, + std::string_view descriptor) { + if (descriptor.empty()) + return nullptr; + if (descriptor[0] != 'L') + return nullptr; + std::string name(descriptor.substr(1, descriptor.length() - 2)); + std::replace(name.begin(), name.end(), '/', '.'); + auto java_name = env->NewStringUTF(name.data()); + auto res = (jclass)env->CallObjectMethod(class_loader, load_class_method, + java_name, false); + return res; +} + +std::string GetClassDescriptor(JNIEnv *env, jclass clazz) { + auto java_name = (jstring)env->CallObjectMethod(clazz, get_class_name_method); + auto name = env->GetStringUTFChars(java_name, nullptr); + std::string descriptor = name; + std::replace(descriptor.begin(), descriptor.end(), '.', '/'); + if (descriptor[0] != '[') { + if (descriptor == "boolean") { + descriptor = "Z"; + } else if (descriptor == "byte") { + descriptor = "B"; + } else if (descriptor == "short") { + descriptor = "S"; + } else if (descriptor == "char") { + descriptor = "C"; + } else if (descriptor == "int") { + descriptor = "I"; + } else if (descriptor == "long") { + descriptor = "J"; + } else if (descriptor == "float") { + descriptor = "F"; + } else if (descriptor == "double") { + descriptor = "D"; + } + descriptor = "L" + std::string(name) + ";"; + } + env->ReleaseStringUTFChars(java_name, name); + return descriptor; +} +} // namespace + +struct MyDexFile { + const void *begin_{}; + size_t size_{}; + const uint8_t *const data_begin_{}; + const size_t data_size_{}; + + virtual ~MyDexFile() = default; +}; + +extern "C" JNIEXPORT jlongArray JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_findMethodUsingString( + JNIEnv *env, jobject thiz, jstring str, jboolean match_prefix, + jlong return_type, jshort parameter_count, jstring parameter_shorty, + jlong declaring_class, jlongArray parameter_types, + jlongArray contains_parameter_types, jintArray dex_priority, + jboolean find_first) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + if (!str) + return nullptr; + auto str_ = env->GetStringUTFChars(str, nullptr); + auto parameter_shorty_ = + parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) + : nullptr; + std::vector dex_priority_; + jint *dex_priority_elements = nullptr; + if (dex_priority) { + dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); + dex_priority_.assign(dex_priority_elements, + dex_priority_elements + + env->GetArrayLength(dex_priority)); + } + + std::vector parameter_types_; + jlong *parameter_types_elements = nullptr; + if (parameter_types) { + parameter_types_elements = + env->GetLongArrayElements(parameter_types, nullptr); + parameter_types_.assign(parameter_types_elements, + parameter_types_elements + + env->GetArrayLength(parameter_types)); + } + + std::vector contains_parameter_types_; + jlong *contains_parameter_types_elements = nullptr; + if (contains_parameter_types) { + contains_parameter_types_elements = + env->GetLongArrayElements(contains_parameter_types, nullptr); + contains_parameter_types_.assign( + contains_parameter_types_elements, + contains_parameter_types_elements + + env->GetArrayLength(contains_parameter_types)); + } + + auto out = helper->FindMethodUsingString( + str_, match_prefix, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", + declaring_class, contains_parameter_types_, contains_parameter_types_, + dex_priority_, find_first); + + env->ReleaseStringUTFChars(str, str_); + if (parameter_shorty_) + env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); + if (dex_priority_elements) + env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, + JNI_ABORT); + if (parameter_types_elements) + env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, + JNI_ABORT); + if (contains_parameter_types_elements) + env->ReleaseLongArrayElements(contains_parameter_types, + contains_parameter_types_elements, JNI_ABORT); + auto res = env->NewLongArray(static_cast(out.size())); + auto res_element = env->GetLongArrayElements(res, nullptr); + for (size_t i = 0; i < out.size(); ++i) { + res_element[i] = out[i]; + } + env->ReleaseLongArrayElements(res, res_element, 0); + return res; +} + +extern "C" JNIEXPORT jlong JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_load(JNIEnv *env, jobject thiz, + jobject class_loader) { + if (!class_loader) + return 0; + auto path_list = env->GetObjectField(class_loader, path_list_field); + if (!path_list) + return 0; + auto elements = (jobjectArray)env->GetObjectField(path_list, element_field); + if (!elements) + return 0; + std::vector> images; + for (auto i = 0, len = env->GetArrayLength(elements); i < len; ++i) { + auto element = env->GetObjectArrayElement(elements, i); + if (!element) continue; + auto java_dex_file = env->GetObjectField(element, dex_file_field); + if (!java_dex_file) continue; + auto cookie = (jlongArray)env->GetObjectField(java_dex_file, cookie_field); + if (!cookie) continue; + auto dex_file_length = env->GetArrayLength(cookie); + const auto *dex_files = reinterpret_cast( + env->GetLongArrayElements(cookie, nullptr)); + while (dex_file_length-- > 1) { + const auto *dex_file = dex_files[dex_file_length]; + if (!dex_file) { + LOGE("dex_file is nullptr at %d", dex_file_length); + continue; + } + LOGD("Got dex file %d", dex_file_length); + if (dex::Reader::IsCompact(dex_file->begin_)) { + images.emplace_back(dex_file->begin_, dex_file->size_, dex_file->data_begin_, dex_file->data_size_); + } else { + images.emplace_back(dex_file->begin_, dex_file->size_, nullptr, 0); + } + } + } + if (images.empty()) return 0; + auto res = reinterpret_cast(new DexHelper(images)); + env->SetLongField(thiz, token_field, res); + return res; +} + +extern "C" JNIEXPORT jlongArray JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_findMethodInvoking( + JNIEnv *env, jobject thiz, jlong method_index, jlong return_type, + jshort parameter_count, jstring parameter_shorty, jlong declaring_class, + jlongArray parameter_types, jlongArray contains_parameter_types, + jintArray dex_priority, jboolean find_first) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + auto parameter_shorty_ = + parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) + : nullptr; + std::vector dex_priority_; + jint *dex_priority_elements = nullptr; + if (dex_priority) { + dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); + dex_priority_.assign(dex_priority_elements, + dex_priority_elements + + env->GetArrayLength(dex_priority)); + } + + std::vector parameter_types_; + jlong *parameter_types_elements = nullptr; + if (parameter_types) { + parameter_types_elements = + env->GetLongArrayElements(parameter_types, nullptr); + parameter_types_.assign(parameter_types_elements, + parameter_types_elements + + env->GetArrayLength(parameter_types)); + } + + std::vector contains_parameter_types_; + jlong *contains_parameter_types_elements = nullptr; + if (contains_parameter_types) { + contains_parameter_types_elements = + env->GetLongArrayElements(contains_parameter_types, nullptr); + contains_parameter_types_.assign( + contains_parameter_types_elements, + contains_parameter_types_elements + + env->GetArrayLength(contains_parameter_types)); + } + + auto out = helper->FindMethodInvoking( + method_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", + declaring_class, contains_parameter_types_, contains_parameter_types_, + dex_priority_, find_first); + + if (parameter_shorty_) + env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); + if (dex_priority_elements) + env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, + JNI_ABORT); + if (parameter_types_elements) + env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, + JNI_ABORT); + if (contains_parameter_types_elements) + env->ReleaseLongArrayElements(contains_parameter_types, + contains_parameter_types_elements, JNI_ABORT); + auto res = env->NewLongArray(static_cast(out.size())); + auto res_element = env->GetLongArrayElements(res, nullptr); + for (size_t i = 0; i < out.size(); ++i) { + res_element[i] = out[i]; + } + env->ReleaseLongArrayElements(res, res_element, 0); + return res; +} +extern "C" JNIEXPORT jlongArray JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_findMethodInvoked( + JNIEnv *env, jobject thiz, jlong method_index, jlong return_type, + jshort parameter_count, jstring parameter_shorty, jlong declaring_class, + jlongArray parameter_types, jlongArray contains_parameter_types, + jintArray dex_priority, jboolean find_first) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + auto parameter_shorty_ = + parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) + : nullptr; + std::vector dex_priority_; + jint *dex_priority_elements = nullptr; + if (dex_priority) { + dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); + dex_priority_.assign(dex_priority_elements, + dex_priority_elements + + env->GetArrayLength(dex_priority)); + } + + std::vector parameter_types_; + jlong *parameter_types_elements = nullptr; + if (parameter_types) { + parameter_types_elements = + env->GetLongArrayElements(parameter_types, nullptr); + parameter_types_.assign(parameter_types_elements, + parameter_types_elements + + env->GetArrayLength(parameter_types)); + } + + std::vector contains_parameter_types_; + jlong *contains_parameter_types_elements = nullptr; + if (contains_parameter_types) { + contains_parameter_types_elements = + env->GetLongArrayElements(contains_parameter_types, nullptr); + contains_parameter_types_.assign( + contains_parameter_types_elements, + contains_parameter_types_elements + + env->GetArrayLength(contains_parameter_types)); + } + + auto out = helper->FindMethodInvoked( + method_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", + declaring_class, contains_parameter_types_, contains_parameter_types_, + dex_priority_, find_first); + + if (parameter_shorty_) + env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); + if (dex_priority_elements) + env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, + JNI_ABORT); + if (parameter_types_elements) + env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, + JNI_ABORT); + if (contains_parameter_types_elements) + env->ReleaseLongArrayElements(contains_parameter_types, + contains_parameter_types_elements, JNI_ABORT); + auto res = env->NewLongArray(static_cast(out.size())); + auto res_element = env->GetLongArrayElements(res, nullptr); + for (size_t i = 0; i < out.size(); ++i) { + res_element[i] = out[i]; + } + env->ReleaseLongArrayElements(res, res_element, 0); + return res; +} +extern "C" JNIEXPORT jlongArray JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_findMethodSettingField( + JNIEnv *env, jobject thiz, jlong field_index, jlong return_type, + jshort parameter_count, jstring parameter_shorty, jlong declaring_class, + jlongArray parameter_types, jlongArray contains_parameter_types, + jintArray dex_priority, jboolean find_first) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + auto parameter_shorty_ = + parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) + : nullptr; + std::vector dex_priority_; + jint *dex_priority_elements = nullptr; + if (dex_priority) { + dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); + dex_priority_.assign(dex_priority_elements, + dex_priority_elements + + env->GetArrayLength(dex_priority)); + } + + std::vector parameter_types_; + jlong *parameter_types_elements = nullptr; + if (parameter_types) { + parameter_types_elements = + env->GetLongArrayElements(parameter_types, nullptr); + parameter_types_.assign(parameter_types_elements, + parameter_types_elements + + env->GetArrayLength(parameter_types)); + } + + std::vector contains_parameter_types_; + jlong *contains_parameter_types_elements = nullptr; + if (contains_parameter_types) { + contains_parameter_types_elements = + env->GetLongArrayElements(contains_parameter_types, nullptr); + contains_parameter_types_.assign( + contains_parameter_types_elements, + contains_parameter_types_elements + + env->GetArrayLength(contains_parameter_types)); + } + + auto out = helper->FindMethodSettingField( + field_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", + declaring_class, contains_parameter_types_, contains_parameter_types_, + dex_priority_, find_first); + + if (parameter_shorty_) + env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); + if (dex_priority_elements) + env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, + JNI_ABORT); + if (parameter_types_elements) + env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, + JNI_ABORT); + if (contains_parameter_types_elements) + env->ReleaseLongArrayElements(contains_parameter_types, + contains_parameter_types_elements, JNI_ABORT); + auto res = env->NewLongArray(static_cast(out.size())); + auto res_element = env->GetLongArrayElements(res, nullptr); + for (size_t i = 0; i < out.size(); ++i) { + res_element[i] = out[i]; + } + env->ReleaseLongArrayElements(res, res_element, 0); + return res; +} +extern "C" JNIEXPORT jlongArray JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_findMethodGettingField( + JNIEnv *env, jobject thiz, jlong field_index, jlong return_type, + jshort parameter_count, jstring parameter_shorty, jlong declaring_class, + jlongArray parameter_types, jlongArray contains_parameter_types, + jintArray dex_priority, jboolean find_first) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + auto parameter_shorty_ = + parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) + : nullptr; + std::vector dex_priority_; + jint *dex_priority_elements = nullptr; + if (dex_priority) { + dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); + dex_priority_.assign(dex_priority_elements, + dex_priority_elements + + env->GetArrayLength(dex_priority)); + } + + std::vector parameter_types_; + jlong *parameter_types_elements = nullptr; + if (parameter_types) { + parameter_types_elements = + env->GetLongArrayElements(parameter_types, nullptr); + parameter_types_.assign(parameter_types_elements, + parameter_types_elements + + env->GetArrayLength(parameter_types)); + } + + std::vector contains_parameter_types_; + jlong *contains_parameter_types_elements = nullptr; + if (contains_parameter_types) { + contains_parameter_types_elements = + env->GetLongArrayElements(contains_parameter_types, nullptr); + contains_parameter_types_.assign( + contains_parameter_types_elements, + contains_parameter_types_elements + + env->GetArrayLength(contains_parameter_types)); + } + + auto out = helper->FindMethodGettingField( + field_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", + declaring_class, contains_parameter_types_, contains_parameter_types_, + dex_priority_, find_first); + + if (parameter_shorty_) + env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); + if (dex_priority_elements) + env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, + JNI_ABORT); + if (parameter_types_elements) + env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, + JNI_ABORT); + if (contains_parameter_types_elements) + env->ReleaseLongArrayElements(contains_parameter_types, + contains_parameter_types_elements, JNI_ABORT); + auto res = env->NewLongArray(static_cast(out.size())); + auto res_element = env->GetLongArrayElements(res, nullptr); + for (size_t i = 0; i < out.size(); ++i) { + res_element[i] = out[i]; + } + env->ReleaseLongArrayElements(res, res_element, 0); + return res; +} +extern "C" JNIEXPORT jlongArray JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_findField(JNIEnv *env, jobject thiz, + jlong type, + jintArray dex_priority, + jboolean find_first) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + std::vector dex_priority_; + jint *dex_priority_elements = nullptr; + if (dex_priority) { + dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); + dex_priority_.assign(dex_priority_elements, + dex_priority_elements + + env->GetArrayLength(dex_priority)); + } + + auto out = helper->FindField(type, dex_priority_, find_first); + + if (dex_priority_elements) + env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, + JNI_ABORT); + + auto res = env->NewLongArray(static_cast(out.size())); + auto res_element = env->GetLongArrayElements(res, nullptr); + for (size_t i = 0; i < out.size(); ++i) { + res_element[i] = out[i]; + } + env->ReleaseLongArrayElements(res, res_element, 0); + return res; +} + +extern "C" JNIEXPORT jobject JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_decodeMethodIndex(JNIEnv *env, + jobject thiz, + jlong method_index) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + auto out = helper->DecodeMethod(method_index); + auto cl = env->GetObjectField(thiz, class_loader_field); + auto clazz = LoadClass(env, cl, out.declaring_class.name); + env->DeleteLocalRef(cl); + std::string sig; + sig.reserve(4096); + sig += "("; + for (const auto ¶m : out.parameters) { + sig += param.name; + } + sig += ")"; + sig += out.return_type.name; + auto *method = env->GetMethodID(clazz, out.name.data(), sig.data()); + if ((*env).ExceptionCheck()) { + (*env).ExceptionClear(); + } + if (!method) { + method = env->GetStaticMethodID(clazz, out.name.data(), sig.data()); + } + return env->ToReflectedMethod(clazz, method, false); +} + +extern "C" JNIEXPORT jobject JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_decodeFieldIndex(JNIEnv *env, + jobject thiz, + jlong field_index) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + auto out = helper->DecodeField(field_index); + auto cl = env->GetObjectField(thiz, class_loader_field); + auto clazz = LoadClass(env, cl, out.declaring_class.name); + env->DeleteLocalRef(cl); + return env->ToReflectedField( + clazz, env->GetFieldID(clazz, out.name.data(), out.type.name.data()), + false); +} + +extern "C" JNIEXPORT jlong JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_encodeClassIndex(JNIEnv *env, + jobject thiz, + jclass clazz) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + return helper->CreateClassIndex(GetClassDescriptor(env, clazz)); +} + +extern "C" JNIEXPORT jlong JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_encodeFieldIndex(JNIEnv *env, + jobject thiz, + jobject field) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return -1; + auto java_name = (jstring)env->CallObjectMethod(field, get_name_method); + auto clazz = (jclass)env->CallObjectMethod(field, get_declaring_class_method); + auto name = env->GetStringUTFChars(java_name, nullptr); + auto res = helper->CreateFieldIndex(name, GetClassDescriptor(env, clazz)); + env->ReleaseStringUTFChars(java_name, name); + return res; +} + +extern "C" JNIEXPORT jlong JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_encodeMethodIndex(JNIEnv *env, + jobject thiz, + jobject method) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return -1; + auto java_name = (jstring)env->CallObjectMethod(method, get_name_method); + auto clazz = + (jclass)env->CallObjectMethod(method, get_declaring_class_method); + auto name = env->GetStringUTFChars(java_name, nullptr); + auto params = + (jobjectArray)env->CallObjectMethod(method, get_parameters_method); + auto param_len = env->GetArrayLength(params); + std::vector param_descriptors; + param_descriptors.reserve(param_len); + for (size_t i = 0; i < param_len; ++i) { + auto param = (jclass)env->GetObjectArrayElement(params, i); + param_descriptors.emplace_back(GetClassDescriptor(env, param)); + env->DeleteLocalRef(param); + } + std::vector params_name; + params_name.reserve(param_descriptors.size()); + for (const auto &descriptor : param_descriptors) { + params_name.emplace_back(descriptor); + } + auto res = helper->CreateMethodIndex(name, GetClassDescriptor(env, clazz), + params_name); + env->ReleaseStringUTFChars(java_name, name); + return res; +} + +extern "C" JNIEXPORT jclass JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_decodeClassIndex(JNIEnv *env, + jobject thiz, + jlong class_index) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return nullptr; + auto out = helper->DecodeClass(class_index); + auto cl = env->GetObjectField(thiz, class_loader_field); + auto res = LoadClass(env, cl, out.name); + env->DeleteLocalRef(cl); + return res; +} + +extern "C" JNIEXPORT void JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_close(JNIEnv *env, jobject thiz) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + env->SetLongField(thiz, token_field, jlong(0)); + delete helper; +} + +extern "C" JNIEXPORT jint JNICALL BILI_JNI_OnLoad(JavaVM *vm, void *) { + JNIEnv *env = nullptr; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_4) != JNI_OK) { + return -1; + } + jclass helper = env->FindClass("me/iacn/biliroaming/utils/DexHelper"); + token_field = env->GetFieldID(helper, "token", "J"); + class_loader_field = + env->GetFieldID(helper, "classLoader", "Ljava/lang/ClassLoader;"); + auto class_loader = env->FindClass("java/lang/ClassLoader"); + load_class_method = env->GetMethodID( + class_loader, "loadClass", "(Ljava/lang/String;Z)Ljava/lang/Class;"); + auto member = env->FindClass("java/lang/reflect/Member"); + get_declaring_class_method = + env->GetMethodID(member, "getDeclaringClass", "()Ljava/lang/Class;"); + get_name_method = env->GetMethodID(member, "getName", "()Ljava/lang/String;"); + auto executable = env->FindClass("java/lang/reflect/Executable"); + get_parameters_method = + env->GetMethodID(executable, "getParameterTypes", "()[Ljava/lang/Class;"); + auto clazz = env->FindClass("java/lang/Class"); + get_class_name_method = + env->GetMethodID(clazz, "getName", "()Ljava/lang/String;"); + auto dex_class_loader = env->FindClass("dalvik/system/BaseDexClassLoader"); + path_list_field = env->GetFieldID(dex_class_loader, "pathList", + "Ldalvik/system/DexPathList;"); + auto dex_path_list = env->FindClass("dalvik/system/DexPathList"); + element_field = env->GetFieldID(dex_path_list, "dexElements", + "[Ldalvik/system/DexPathList$Element;"); + auto element = env->FindClass("dalvik/system/DexPathList$Element"); + dex_file_field = + env->GetFieldID(element, "dexFile", "Ldalvik/system/DexFile;"); + auto dex_file = env->FindClass("dalvik/system/DexFile"); + cookie_field = env->GetFieldID(dex_file, "mCookie", "Ljava/lang/Object;"); + return JNI_VERSION_1_4; +} + +extern "C" +JNIEXPORT void JNICALL +Java_me_iacn_biliroaming_utils_DexHelper_createFullCache(JNIEnv *env, jobject thiz) { + auto *helper = + reinterpret_cast(env->GetLongField(thiz, token_field)); + if (!helper) + return; + helper->CreateFullCache(); +} diff --git a/app/src/main/cpp/logging.h b/app/src/main/cpp/logging.h new file mode 100644 index 00000000..2f3b6145 --- /dev/null +++ b/app/src/main/cpp/logging.h @@ -0,0 +1,29 @@ +#ifndef _LOGGING_H +#define _LOGGING_H + +#include + +#ifndef LOG_TAG +#define LOG_TAG "SimplicityTools" +#endif + +#ifdef LOG_DISABLED +#define LOGD(...) +#define LOGV(...) +#define LOGI(...) +#define LOGW(...) +#define LOGE(...) +#else +#ifndef NDEBUG +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) +#else +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) +#endif +#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) +#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) +#endif + +#endif // _LOGGING_H diff --git a/app/src/main/cpp/native.cpp b/app/src/main/cpp/native.cpp new file mode 100644 index 00000000..aab2b785 --- /dev/null +++ b/app/src/main/cpp/native.cpp @@ -0,0 +1,9 @@ +#include +#include "logging.h" +#include "native.h" + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { + LOGD("%s", "JNI_OnLoad"); + BILI_JNI_OnLoad(vm, reserved); + return JNI_VERSION_1_6; +} diff --git a/app/src/main/cpp/native.h b/app/src/main/cpp/native.h new file mode 100644 index 00000000..e7989924 --- /dev/null +++ b/app/src/main/cpp/native.h @@ -0,0 +1,10 @@ +// +// Created by Owner on 2022/3/9. +// + +#ifndef FUCKCOOLAPKR_NATIVE_H +#define FUCKCOOLAPKR_NATIVE_H + +extern "C" jint BILI_JNI_OnLoad(JavaVM *vm, void *reserved); + +#endif //FUCKCOOLAPKR_NATIVE_H diff --git a/app/src/main/cpp/native_api.h b/app/src/main/cpp/native_api.h new file mode 100644 index 00000000..f2c3e5fe --- /dev/null +++ b/app/src/main/cpp/native_api.h @@ -0,0 +1,21 @@ +#ifndef XPOSEDTEMPLATE_NATIVE_API_H +#define XPOSEDTEMPLATE_NATIVE_API_H + +#include +#include + +typedef int (*HookFunType)(void *func, void *replace, void **backup); + +typedef int (*UnhookFunType)(void *func); + +typedef void (*NativeOnModuleLoaded)(const char *name, void *handle); + +typedef struct { + uint32_t version; + HookFunType hookFunc; + UnhookFunType unhookFunc; +} NativeAPIEntries; + +typedef NativeOnModuleLoaded (*NativeInit)(const NativeAPIEntries *entries); + +#endif //XPOSEDTEMPLATE_NATIVE_API_H diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt index 64816012..4847c113 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt @@ -2,19 +2,33 @@ package com.lt2333.simplicitytools.hook.app import com.lt2333.simplicitytools.hook.app.securitycenter.LockOneHundred import com.lt2333.simplicitytools.hook.app.securitycenter.RemoveMacroBlacklist +import com.lt2333.simplicitytools.hook.app.securitycenter.ShowBatteryTemperature import com.lt2333.simplicitytools.hook.app.securitycenter.SkipWaitingTime +import com.lt2333.simplicitytools.util.log import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.XposedBridge import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam +import me.iacn.biliroaming.utils.DexHelper class SecurityCenter : IXposedHookLoadPackage { + + var dexHelper: DexHelper? = null + override fun handleLoadPackage(lpparam: LoadPackageParam) { XposedBridge.log("Simplicitytools: 成功 Hook "+javaClass.simpleName) + try { + System.loadLibrary("DexBuilder") + dexHelper = DexHelper.getInstance(lpparam.classLoader) + } catch (e: UnsatisfiedLinkError) { + log("DexBuilder 加载失败") + } //跳过 5/10秒等待时间 SkipWaitingTime().handleLoadPackage(lpparam) //锁定 100分 LockOneHundred().handleLoadPackage(lpparam) //去除自动连招黑名单 RemoveMacroBlacklist().handleLoadPackage(lpparam) + //显示电池温度 + ShowBatteryTemperature(dexHelper).handleLoadPackage(lpparam) } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt new file mode 100644 index 00000000..30be292c --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt @@ -0,0 +1,39 @@ +package com.lt2333.simplicitytools.hook.app.securitycenter + +import com.lt2333.simplicitytools.util.log +import de.robv.android.xposed.IXposedHookLoadPackage +import de.robv.android.xposed.XC_MethodReplacement +import de.robv.android.xposed.XposedBridge +import de.robv.android.xposed.callbacks.XC_LoadPackage +import me.iacn.biliroaming.utils.DexHelper + +class ShowBatteryTemperature(private val dexHelper: DexHelper?): IXposedHookLoadPackage { + + override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { + if (dexHelper == null) { + log("DexHelper为null,hook ShowBatteryTemperature 失败") + return + } + + val methodIndex = dexHelper.findMethodUsingString( + "isBatteryLifeFunctionSupported", + true, + -1, + 0, + null, + -1, + null, + null, + null, + true + ).firstOrNull() + if (methodIndex == null) { + log("ShowBatteryTemperature 无法定位方法") + return + } + val method = dexHelper.decodeMethodIndex(methodIndex) + log(method) + XposedBridge.hookMethod(method, XC_MethodReplacement.returnConstant(true)) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt b/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt index d22161e9..81526532 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt @@ -8,6 +8,8 @@ import de.robv.android.xposed.XC_MethodReplacement import de.robv.android.xposed.XposedBridge import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LayoutInflated +import me.iacn.biliroaming.utils.DexHelper + import java.lang.reflect.Field import java.lang.reflect.Member import java.util.* diff --git a/app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java b/app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java new file mode 100644 index 00000000..f676c227 --- /dev/null +++ b/app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java @@ -0,0 +1,87 @@ +package me.iacn.biliroaming.utils; + +import com.lt2333.simplicitytools.util.KotlinXposedHelperKt; + +import java.io.Closeable; +import java.lang.reflect.Field; +import java.lang.reflect.Member; + +import dalvik.system.BaseDexClassLoader; + +public class DexHelper implements AutoCloseable, Closeable { + public static final int NO_CLASS_INDEX = -1; + private final ClassLoader classLoader; + private final long token; + private static DexHelper instance; + + public static DexHelper getInstance(ClassLoader classLoader) { + synchronized (DexHelper.class) { + if (instance != null) return instance; + BaseDexClassLoader loader = KotlinXposedHelperKt.findDexClassLoader(classLoader); + if (loader == null) { + return null; + } + instance = new DexHelper(loader); + return instance; + } + } + + public DexHelper(ClassLoader classLoader) { + this.classLoader = classLoader; + token = load(classLoader); + } + + public native long[] findMethodUsingString( + String str, boolean matchPrefix, long returnType, short parameterCount, + String parameterShorty, long declaringClass, long[] parameterTypes, + long[] containsParameterTypes, int[] dexPriority, boolean findFirst); + + public native long[] findMethodInvoking(long methodIndex, long returnType, + short parameterCount, String parameterShorty, + long declaringClass, long[] parameterTypes, + long[] containsParameterTypes, + int[] dexPriority, boolean findFirst); + + public native long[] findMethodInvoked(long methodIndex, long returnType, + short parameterCount, String parameterShorty, + long declaringClass, long[] parameterTypes, + long[] containsParameterTypes, + int[] dexPriority, boolean findFirst); + + public native long[] findMethodSettingField( + long fieldIndex, long returnType, short parameterCount, + String parameterShorty, long declaringClass, long[] parameterTypes, + long[] containsParameterTypes, int[] dexPriority, boolean findFirst); + + public native long[] findMethodGettingField( + long fieldIndex, long returnType, short parameterCount, + String parameterShorty, long declaringClass, long[] parameterTypes, + long[] containsParameterTypes, int[] dexPriority, boolean findFirst); + + public native long[] findField(long type, int[] dexPriority, boolean findFirst); + + public native Member decodeMethodIndex(long methodIndex); + + public native long encodeMethodIndex(Member method); + + public native Field decodeFieldIndex(long fieldIndex); + + public native long encodeFieldIndex(Field field); + + public native long encodeClassIndex(Class clazz); + + public native Class decodeClassIndex(long classIndex); + + public native void createFullCache(); + + @Override + public native void close(); + + @Override + protected void finalize() { + close(); + } + + private native long load(ClassLoader classLoader); +} + From fdc1a331f8eca5f81c8082b8584e21de6d8191af Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Fri, 11 Mar 2022 19:44:48 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E7=94=B5=E6=B1=A0=E6=B8=A9=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/dex_builder | 1 + .../activity/SettingsActivity.kt | 8 +++ .../simplicitytools/hook/app/Updater.kt | 10 ++-- .../hook/app/android/DisableFlagSecure.kt | 3 +- .../securitycenter/ShowBatteryTemperature.kt | 60 +++++++++++++++++-- .../util/KotlinXposedHelper.kt | 2 - app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- 11 files changed, 75 insertions(+), 15 deletions(-) create mode 160000 app/src/main/cpp/dex_builder diff --git a/app/src/main/cpp/dex_builder b/app/src/main/cpp/dex_builder new file mode 160000 index 00000000..77f48fdd --- /dev/null +++ b/app/src/main/cpp/dex_builder @@ -0,0 +1 @@ +Subproject commit 77f48fdd795f5e178aeefb6858e3357505e5daba diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt index cdb79da2..5c580955 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt @@ -966,6 +966,14 @@ class SettingsActivity : MIUIActivity() { SwitchV("remove_macro_blacklist") ) ) + add( + TextSummaryWithSwitchV( + TextSummaryV( + textId = R.string.battery_life_function + ), + SwitchV("battery_life_function") + ) + ) add(LineV()) add(TitleTextV(resId = R.string.scope_mediaeditor)) add( diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/Updater.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/Updater.kt index dfaaa69c..b60cddd0 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/Updater.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/Updater.kt @@ -1,8 +1,8 @@ package com.lt2333.simplicitytools.hook.app import com.lt2333.simplicitytools.util.XSPUtils +import com.lt2333.simplicitytools.util.hookBeforeMethod import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LoadPackage @@ -15,11 +15,9 @@ class Updater : IXposedHookLoadPackage { "com.android.updater.common.utils.$letter", lpparam.classLoader ) ?: continue if (classIfExists.declaredFields.size >= 9 && classIfExists.declaredMethods.size > 60) { - XposedHelpers.findAndHookMethod(classIfExists, "T", object : XC_MethodHook() { - override fun beforeHookedMethod(param: MethodHookParam) { - param.result = false - } - }) + classIfExists.hookBeforeMethod("T") { + it.result = false + } return } letter++ diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt index 234fbee5..611b1e69 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/android/DisableFlagSecure.kt @@ -1,6 +1,7 @@ package com.lt2333.simplicitytools.hook.app.android -import com.lt2333.simplicitytools.util.* +import com.lt2333.simplicitytools.util.hasEnable +import com.lt2333.simplicitytools.util.hookBeforeMethod import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.callbacks.XC_LoadPackage diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt index 30be292c..81fa6aa0 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt @@ -1,15 +1,28 @@ package com.lt2333.simplicitytools.hook.app.securitycenter -import com.lt2333.simplicitytools.util.log +import android.app.AndroidAppHelper +import android.content.BroadcastReceiver +import android.content.Context +import android.content.IntentFilter +import android.content.res.Configuration +import android.graphics.Color +import android.graphics.Typeface +import android.util.TypedValue +import android.view.Gravity +import android.view.View +import android.widget.LinearLayout +import android.widget.TextView +import cn.fkj233.ui.activity.dp2px +import com.lt2333.simplicitytools.util.* import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodReplacement -import de.robv.android.xposed.XposedBridge import de.robv.android.xposed.callbacks.XC_LoadPackage import me.iacn.biliroaming.utils.DexHelper +import java.lang.reflect.Field class ShowBatteryTemperature(private val dexHelper: DexHelper?): IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { + if (!XSPUtils.getBoolean("battery_life_function", false)) return if (dexHelper == null) { log("DexHelper为null,hook ShowBatteryTemperature 失败") return @@ -33,7 +46,44 @@ class ShowBatteryTemperature(private val dexHelper: DexHelper?): IXposedHookLoad } val method = dexHelper.decodeMethodIndex(methodIndex) log(method) - XposedBridge.hookMethod(method, XC_MethodReplacement.returnConstant(true)) + method.hookBeforeMethod { it.result = true } + val a = "com.miui.powercenter.a\$a".findClass(lpparam.classLoader) + "com.miui.powercenter.a".hookBeforeMethod(lpparam.classLoader, "b", Context::class.java) { + it.result = getBatteryTemperature(it.args[0] as Context).toString() + } + a.hookAfterMethod("run") { + val context = AndroidAppHelper.currentApplication().applicationContext + val isDarkMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES + val currentTemperatureValue = context.resources.getIdentifier("current_temperature_value", "id", "com.miui.securitycenter") + val field = a.getDeclaredField("a") as Field + field.isAccessible = true + val view = field.get(it.thisObject) as View + val textView = view.findViewById(currentTemperatureValue) + textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36.399998f) + textView.gravity = Gravity.NO_GRAVITY + textView.setPadding(0, 0, 0, 0) + textView.height = dp2px(context, 49.099983f) + textView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START + (textView.layoutParams as LinearLayout.LayoutParams).marginStart = dp2px(context, 25f) + (textView.layoutParams as LinearLayout.LayoutParams).topMargin = 0 + val tempView = TextView(context) + tempView.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, dp2px(context, 49.099983f)) + (tempView.layoutParams as LinearLayout.LayoutParams).marginStart = dp2px(context, 3.599976f) + tempView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13.099977f) + tempView.setPadding(0, dp2px(context, 25f), 0, 0) + tempView.text = "℃" + tempView.setTextColor(Color.parseColor(if (isDarkMode) "#e6e6e6" else "#333333")) + tempView.typeface = Typeface.create(null, 500, false) + tempView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START + val tempeValueContainer = context.resources.getIdentifier("tempe_value_container", "id", "com.miui.securitycenter") + val linearLayout = view.findViewById(tempeValueContainer) + linearLayout.addView(tempView) + } + } + private fun getBatteryTemperature(context: Context): Int { + return context.registerReceiver( + null as BroadcastReceiver?, + IntentFilter("android.intent.action.BATTERY_CHANGED") + )!!.getIntExtra("temperature", 0) / 10 } - } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt b/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt index 81526532..d22161e9 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/util/KotlinXposedHelper.kt @@ -8,8 +8,6 @@ import de.robv.android.xposed.XC_MethodReplacement import de.robv.android.xposed.XposedBridge import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.callbacks.XC_LayoutInflated -import me.iacn.biliroaming.utils.DexHelper - import java.lang.reflect.Field import java.lang.reflect.Member import java.util.* diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index fcc332cf..460b950b 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -149,4 +149,5 @@ 显示通知重要程度 去广告 移除主题壁纸的广告 + 电池页面显示当前温度 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 6682e828..f57d4a29 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -149,4 +149,5 @@ 設定 去廣告 拿掉主題壁紙的廣告 + 電池頁面展示當前溫度 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 16d31db1..1dd980a6 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -149,4 +149,5 @@ 設定 去廣告 拿掉主題壁紙的廣告 + 電池頁面展示當前溫度 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bde848e7..cc56bb3c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -149,4 +149,5 @@ Show notification importance settings which are hidden in MIUI 12 and later versions Remove ads Remove ads for theme manager + Battery page shows the current temperature diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c4a685e2..f37c82dd 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sun Feb 13 16:53:34 CST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From 9e5743581745e2d1de02b386c6e6d69e43033c3a Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Fri, 11 Mar 2022 20:55:39 +0800 Subject: [PATCH 3/7] Try fix build --- .github/workflows/android.yml | 4 +++- .gitmodules | 2 +- app/build.gradle.kts | 3 +-- app/src/main/cpp/CMakeLists.txt | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 07ed3db4..017c17fc 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -32,8 +32,10 @@ jobs: path: | ~/.gradle/caches/build-cache-* key: gradle-builds-${{ github.sha }} - - name: Clone UI + - name: Clone blockmiui run: git clone https://github.com/Block-Network/blockmiui.git + - name: Clone DexBuilder + run: git clone https://github.com/LSPosed/DexBuilder.git - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle diff --git a/.gitmodules b/.gitmodules index 4dcb4781..0616fc51 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,4 @@ url = https://github.com/577fkj/blockmiui.git [submodule "app/src/main/cpp/dex_builder"] path = app/src/main/cpp/dex_builder - url = https://github.com/LSPosed/DexBuilder + url = https://github.com/LSPosed/DexBuilder.git diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ca48cb36..9349210f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -27,7 +27,6 @@ android { buildTypes { release { isMinifyEnabled = true - isZipAlignEnabled = true isShrinkResources = true setProguardFiles( listOf( @@ -58,7 +57,7 @@ android { applicationVariants.all { outputs.all { (this as BaseVariantOutputImpl).outputFileName = - "Simplicity_Tools_Xposed-${versionName}-${name}.apk" + "Simplicity_Tools_Xposed-$versionName-$name.apk" } } androidResources { diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 9c7d7553..a79e3ef1 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.18.1) - set(CMAKE_CXX_STANDARD 17) set(CMAKE_C_STANDARD 11) @@ -12,11 +11,13 @@ add_library( native.cpp biliroaming.cc ) + target_include_directories(DexBuilder PUBLIC dex_builder/include) find_library( log-lib - log) + log + ) target_link_libraries( DexBuilder From 8fe25aa836e3c959975ad398aff2fabf3acf3faa Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Fri, 11 Mar 2022 21:02:21 +0800 Subject: [PATCH 4/7] Update .gitmodules --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 0616fc51..4dcb4781 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,4 @@ url = https://github.com/577fkj/blockmiui.git [submodule "app/src/main/cpp/dex_builder"] path = app/src/main/cpp/dex_builder - url = https://github.com/LSPosed/DexBuilder.git + url = https://github.com/LSPosed/DexBuilder From 26c2fae2e64bb6b492991714ee9d70030252b335 Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Fri, 11 Mar 2022 21:06:36 +0800 Subject: [PATCH 5/7] Update android.yml --- .github/workflows/android.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 017c17fc..776aeed2 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -32,10 +32,10 @@ jobs: path: | ~/.gradle/caches/build-cache-* key: gradle-builds-${{ github.sha }} - - name: Clone blockmiui - run: git clone https://github.com/Block-Network/blockmiui.git - - name: Clone DexBuilder - run: git clone https://github.com/LSPosed/DexBuilder.git + - name: init submodule + run: | + git submodule init + git submodule update - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle From 6aa89685e6f0449cfde39ab92c9bf40a35d7d3b1 Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Fri, 11 Mar 2022 21:15:25 +0800 Subject: [PATCH 6/7] Upload Apk --- .github/workflows/android.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 776aeed2..f8a50cc3 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -32,12 +32,24 @@ jobs: path: | ~/.gradle/caches/build-cache-* key: gradle-builds-${{ github.sha }} - - name: init submodule + + - name: Init Submodule run: | git submodule init git submodule update - - name: Grant execute permission for gradlew - run: chmod +x gradlew + - name: Build with Gradle - run: ./gradlew build + run: bash ./gradlew assemble + + - name: Upload Release APK + uses: actions/upload-artifact@v2 + with: + name: SimplicityTools_Release + path: "app/build/outputs/apk/release/*.apk" + + - name: Upload Debug APK + uses: actions/upload-artifact@v2 + with: + name: Simplicity Tools_Debug + path: "app/build/outputs/apk/debug/*.apk" From 304ae68c5947f7ca2ac54da172b9890b024f2393 Mon Sep 17 00:00:00 2001 From: YuKongA <1348547200@qq.com> Date: Fri, 11 Mar 2022 22:53:23 +0800 Subject: [PATCH 7/7] Remove DexBuilder --- .gitmodules | 3 - app/build.gradle.kts | 23 +- app/proguard-rules.pro | 2 - app/src/main/cpp/CMakeLists.txt | 26 - app/src/main/cpp/biliroaming.cc | 669 ------------------ app/src/main/cpp/dex_builder | 1 - app/src/main/cpp/logging.h | 29 - app/src/main/cpp/native.cpp | 9 - app/src/main/cpp/native.h | 10 - app/src/main/cpp/native_api.h | 21 - .../hook/app/SecurityCenter.kt | 12 +- .../securitycenter/ShowBatteryTemperature.kt | 27 +- .../me/iacn/biliroaming/utils/DexHelper.java | 87 --- 13 files changed, 3 insertions(+), 916 deletions(-) delete mode 100644 app/src/main/cpp/CMakeLists.txt delete mode 100644 app/src/main/cpp/biliroaming.cc delete mode 160000 app/src/main/cpp/dex_builder delete mode 100644 app/src/main/cpp/logging.h delete mode 100644 app/src/main/cpp/native.cpp delete mode 100644 app/src/main/cpp/native.h delete mode 100644 app/src/main/cpp/native_api.h delete mode 100644 app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java diff --git a/.gitmodules b/.gitmodules index 4dcb4781..5f60ba22 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "blockmiui"] path = blockmiui url = https://github.com/577fkj/blockmiui.git -[submodule "app/src/main/cpp/dex_builder"] - path = app/src/main/cpp/dex_builder - url = https://github.com/LSPosed/DexBuilder diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9349210f..5e473635 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,25 +14,13 @@ android { targetSdk = 32 versionCode = 40 versionName = "1.3.9" - externalNativeBuild { - cmake { - targets("DexBuilder") - abiFilters("arm64-v8a") - cppFlags("-std=c++17") - cFlags("-std=gnu99") - } - } } buildTypes { release { isMinifyEnabled = true isShrinkResources = true - setProguardFiles( - listOf( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) + setProguardFiles(listOf("proguard-rules.pro") ) } } @@ -60,15 +48,6 @@ android { "Simplicity_Tools_Xposed-$versionName-$name.apk" } } - androidResources { - noCompress("libDexBuilder.so") - } - externalNativeBuild { - cmake { - path("src/main/cpp/CMakeLists.txt") - } - } - ndkVersion = "23.1.7779620" } dependencies { diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 12bb0427..6102543f 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -36,7 +36,5 @@ public static void throw*(...); } --keep class me.iacn.biliroaming.utils.DexHelper { *; } - -allowaccessmodification -overloadaggressively \ No newline at end of file diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt deleted file mode 100644 index a79e3ef1..00000000 --- a/app/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.18.1) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_STANDARD 11) - -add_subdirectory(dex_builder) - -add_library( - DexBuilder - SHARED - native.cpp - biliroaming.cc - ) - -target_include_directories(DexBuilder PUBLIC dex_builder/include) - -find_library( - log-lib - log - ) - -target_link_libraries( - DexBuilder - ${log-lib} - dex_builder_static - ) \ No newline at end of file diff --git a/app/src/main/cpp/biliroaming.cc b/app/src/main/cpp/biliroaming.cc deleted file mode 100644 index 8628d406..00000000 --- a/app/src/main/cpp/biliroaming.cc +++ /dev/null @@ -1,669 +0,0 @@ -#include -#include -#include - -#define LOG_TAG "QAuxv" -#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) -#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) -#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__) -#define PLOGE(fmt, args...) \ - LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) - -namespace { -jfieldID token_field; -jfieldID class_loader_field; -jmethodID load_class_method; -// jmethodID get_declared_method; -// jmethodID get_declared_field; -jmethodID get_name_method; -jmethodID get_declaring_class_method; -jmethodID get_parameters_method; -jmethodID get_class_name_method; -jfieldID path_list_field; -jfieldID element_field; -jfieldID dex_file_field; -jfieldID cookie_field; - -jclass LoadClass(JNIEnv *env, jobject class_loader, - std::string_view descriptor) { - if (descriptor.empty()) - return nullptr; - if (descriptor[0] != 'L') - return nullptr; - std::string name(descriptor.substr(1, descriptor.length() - 2)); - std::replace(name.begin(), name.end(), '/', '.'); - auto java_name = env->NewStringUTF(name.data()); - auto res = (jclass)env->CallObjectMethod(class_loader, load_class_method, - java_name, false); - return res; -} - -std::string GetClassDescriptor(JNIEnv *env, jclass clazz) { - auto java_name = (jstring)env->CallObjectMethod(clazz, get_class_name_method); - auto name = env->GetStringUTFChars(java_name, nullptr); - std::string descriptor = name; - std::replace(descriptor.begin(), descriptor.end(), '.', '/'); - if (descriptor[0] != '[') { - if (descriptor == "boolean") { - descriptor = "Z"; - } else if (descriptor == "byte") { - descriptor = "B"; - } else if (descriptor == "short") { - descriptor = "S"; - } else if (descriptor == "char") { - descriptor = "C"; - } else if (descriptor == "int") { - descriptor = "I"; - } else if (descriptor == "long") { - descriptor = "J"; - } else if (descriptor == "float") { - descriptor = "F"; - } else if (descriptor == "double") { - descriptor = "D"; - } - descriptor = "L" + std::string(name) + ";"; - } - env->ReleaseStringUTFChars(java_name, name); - return descriptor; -} -} // namespace - -struct MyDexFile { - const void *begin_{}; - size_t size_{}; - const uint8_t *const data_begin_{}; - const size_t data_size_{}; - - virtual ~MyDexFile() = default; -}; - -extern "C" JNIEXPORT jlongArray JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_findMethodUsingString( - JNIEnv *env, jobject thiz, jstring str, jboolean match_prefix, - jlong return_type, jshort parameter_count, jstring parameter_shorty, - jlong declaring_class, jlongArray parameter_types, - jlongArray contains_parameter_types, jintArray dex_priority, - jboolean find_first) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - if (!str) - return nullptr; - auto str_ = env->GetStringUTFChars(str, nullptr); - auto parameter_shorty_ = - parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) - : nullptr; - std::vector dex_priority_; - jint *dex_priority_elements = nullptr; - if (dex_priority) { - dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); - dex_priority_.assign(dex_priority_elements, - dex_priority_elements + - env->GetArrayLength(dex_priority)); - } - - std::vector parameter_types_; - jlong *parameter_types_elements = nullptr; - if (parameter_types) { - parameter_types_elements = - env->GetLongArrayElements(parameter_types, nullptr); - parameter_types_.assign(parameter_types_elements, - parameter_types_elements + - env->GetArrayLength(parameter_types)); - } - - std::vector contains_parameter_types_; - jlong *contains_parameter_types_elements = nullptr; - if (contains_parameter_types) { - contains_parameter_types_elements = - env->GetLongArrayElements(contains_parameter_types, nullptr); - contains_parameter_types_.assign( - contains_parameter_types_elements, - contains_parameter_types_elements + - env->GetArrayLength(contains_parameter_types)); - } - - auto out = helper->FindMethodUsingString( - str_, match_prefix, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", - declaring_class, contains_parameter_types_, contains_parameter_types_, - dex_priority_, find_first); - - env->ReleaseStringUTFChars(str, str_); - if (parameter_shorty_) - env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); - if (dex_priority_elements) - env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, - JNI_ABORT); - if (parameter_types_elements) - env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, - JNI_ABORT); - if (contains_parameter_types_elements) - env->ReleaseLongArrayElements(contains_parameter_types, - contains_parameter_types_elements, JNI_ABORT); - auto res = env->NewLongArray(static_cast(out.size())); - auto res_element = env->GetLongArrayElements(res, nullptr); - for (size_t i = 0; i < out.size(); ++i) { - res_element[i] = out[i]; - } - env->ReleaseLongArrayElements(res, res_element, 0); - return res; -} - -extern "C" JNIEXPORT jlong JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_load(JNIEnv *env, jobject thiz, - jobject class_loader) { - if (!class_loader) - return 0; - auto path_list = env->GetObjectField(class_loader, path_list_field); - if (!path_list) - return 0; - auto elements = (jobjectArray)env->GetObjectField(path_list, element_field); - if (!elements) - return 0; - std::vector> images; - for (auto i = 0, len = env->GetArrayLength(elements); i < len; ++i) { - auto element = env->GetObjectArrayElement(elements, i); - if (!element) continue; - auto java_dex_file = env->GetObjectField(element, dex_file_field); - if (!java_dex_file) continue; - auto cookie = (jlongArray)env->GetObjectField(java_dex_file, cookie_field); - if (!cookie) continue; - auto dex_file_length = env->GetArrayLength(cookie); - const auto *dex_files = reinterpret_cast( - env->GetLongArrayElements(cookie, nullptr)); - while (dex_file_length-- > 1) { - const auto *dex_file = dex_files[dex_file_length]; - if (!dex_file) { - LOGE("dex_file is nullptr at %d", dex_file_length); - continue; - } - LOGD("Got dex file %d", dex_file_length); - if (dex::Reader::IsCompact(dex_file->begin_)) { - images.emplace_back(dex_file->begin_, dex_file->size_, dex_file->data_begin_, dex_file->data_size_); - } else { - images.emplace_back(dex_file->begin_, dex_file->size_, nullptr, 0); - } - } - } - if (images.empty()) return 0; - auto res = reinterpret_cast(new DexHelper(images)); - env->SetLongField(thiz, token_field, res); - return res; -} - -extern "C" JNIEXPORT jlongArray JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_findMethodInvoking( - JNIEnv *env, jobject thiz, jlong method_index, jlong return_type, - jshort parameter_count, jstring parameter_shorty, jlong declaring_class, - jlongArray parameter_types, jlongArray contains_parameter_types, - jintArray dex_priority, jboolean find_first) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - auto parameter_shorty_ = - parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) - : nullptr; - std::vector dex_priority_; - jint *dex_priority_elements = nullptr; - if (dex_priority) { - dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); - dex_priority_.assign(dex_priority_elements, - dex_priority_elements + - env->GetArrayLength(dex_priority)); - } - - std::vector parameter_types_; - jlong *parameter_types_elements = nullptr; - if (parameter_types) { - parameter_types_elements = - env->GetLongArrayElements(parameter_types, nullptr); - parameter_types_.assign(parameter_types_elements, - parameter_types_elements + - env->GetArrayLength(parameter_types)); - } - - std::vector contains_parameter_types_; - jlong *contains_parameter_types_elements = nullptr; - if (contains_parameter_types) { - contains_parameter_types_elements = - env->GetLongArrayElements(contains_parameter_types, nullptr); - contains_parameter_types_.assign( - contains_parameter_types_elements, - contains_parameter_types_elements + - env->GetArrayLength(contains_parameter_types)); - } - - auto out = helper->FindMethodInvoking( - method_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", - declaring_class, contains_parameter_types_, contains_parameter_types_, - dex_priority_, find_first); - - if (parameter_shorty_) - env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); - if (dex_priority_elements) - env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, - JNI_ABORT); - if (parameter_types_elements) - env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, - JNI_ABORT); - if (contains_parameter_types_elements) - env->ReleaseLongArrayElements(contains_parameter_types, - contains_parameter_types_elements, JNI_ABORT); - auto res = env->NewLongArray(static_cast(out.size())); - auto res_element = env->GetLongArrayElements(res, nullptr); - for (size_t i = 0; i < out.size(); ++i) { - res_element[i] = out[i]; - } - env->ReleaseLongArrayElements(res, res_element, 0); - return res; -} -extern "C" JNIEXPORT jlongArray JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_findMethodInvoked( - JNIEnv *env, jobject thiz, jlong method_index, jlong return_type, - jshort parameter_count, jstring parameter_shorty, jlong declaring_class, - jlongArray parameter_types, jlongArray contains_parameter_types, - jintArray dex_priority, jboolean find_first) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - auto parameter_shorty_ = - parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) - : nullptr; - std::vector dex_priority_; - jint *dex_priority_elements = nullptr; - if (dex_priority) { - dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); - dex_priority_.assign(dex_priority_elements, - dex_priority_elements + - env->GetArrayLength(dex_priority)); - } - - std::vector parameter_types_; - jlong *parameter_types_elements = nullptr; - if (parameter_types) { - parameter_types_elements = - env->GetLongArrayElements(parameter_types, nullptr); - parameter_types_.assign(parameter_types_elements, - parameter_types_elements + - env->GetArrayLength(parameter_types)); - } - - std::vector contains_parameter_types_; - jlong *contains_parameter_types_elements = nullptr; - if (contains_parameter_types) { - contains_parameter_types_elements = - env->GetLongArrayElements(contains_parameter_types, nullptr); - contains_parameter_types_.assign( - contains_parameter_types_elements, - contains_parameter_types_elements + - env->GetArrayLength(contains_parameter_types)); - } - - auto out = helper->FindMethodInvoked( - method_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", - declaring_class, contains_parameter_types_, contains_parameter_types_, - dex_priority_, find_first); - - if (parameter_shorty_) - env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); - if (dex_priority_elements) - env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, - JNI_ABORT); - if (parameter_types_elements) - env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, - JNI_ABORT); - if (contains_parameter_types_elements) - env->ReleaseLongArrayElements(contains_parameter_types, - contains_parameter_types_elements, JNI_ABORT); - auto res = env->NewLongArray(static_cast(out.size())); - auto res_element = env->GetLongArrayElements(res, nullptr); - for (size_t i = 0; i < out.size(); ++i) { - res_element[i] = out[i]; - } - env->ReleaseLongArrayElements(res, res_element, 0); - return res; -} -extern "C" JNIEXPORT jlongArray JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_findMethodSettingField( - JNIEnv *env, jobject thiz, jlong field_index, jlong return_type, - jshort parameter_count, jstring parameter_shorty, jlong declaring_class, - jlongArray parameter_types, jlongArray contains_parameter_types, - jintArray dex_priority, jboolean find_first) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - auto parameter_shorty_ = - parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) - : nullptr; - std::vector dex_priority_; - jint *dex_priority_elements = nullptr; - if (dex_priority) { - dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); - dex_priority_.assign(dex_priority_elements, - dex_priority_elements + - env->GetArrayLength(dex_priority)); - } - - std::vector parameter_types_; - jlong *parameter_types_elements = nullptr; - if (parameter_types) { - parameter_types_elements = - env->GetLongArrayElements(parameter_types, nullptr); - parameter_types_.assign(parameter_types_elements, - parameter_types_elements + - env->GetArrayLength(parameter_types)); - } - - std::vector contains_parameter_types_; - jlong *contains_parameter_types_elements = nullptr; - if (contains_parameter_types) { - contains_parameter_types_elements = - env->GetLongArrayElements(contains_parameter_types, nullptr); - contains_parameter_types_.assign( - contains_parameter_types_elements, - contains_parameter_types_elements + - env->GetArrayLength(contains_parameter_types)); - } - - auto out = helper->FindMethodSettingField( - field_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", - declaring_class, contains_parameter_types_, contains_parameter_types_, - dex_priority_, find_first); - - if (parameter_shorty_) - env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); - if (dex_priority_elements) - env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, - JNI_ABORT); - if (parameter_types_elements) - env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, - JNI_ABORT); - if (contains_parameter_types_elements) - env->ReleaseLongArrayElements(contains_parameter_types, - contains_parameter_types_elements, JNI_ABORT); - auto res = env->NewLongArray(static_cast(out.size())); - auto res_element = env->GetLongArrayElements(res, nullptr); - for (size_t i = 0; i < out.size(); ++i) { - res_element[i] = out[i]; - } - env->ReleaseLongArrayElements(res, res_element, 0); - return res; -} -extern "C" JNIEXPORT jlongArray JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_findMethodGettingField( - JNIEnv *env, jobject thiz, jlong field_index, jlong return_type, - jshort parameter_count, jstring parameter_shorty, jlong declaring_class, - jlongArray parameter_types, jlongArray contains_parameter_types, - jintArray dex_priority, jboolean find_first) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - auto parameter_shorty_ = - parameter_shorty ? env->GetStringUTFChars(parameter_shorty, nullptr) - : nullptr; - std::vector dex_priority_; - jint *dex_priority_elements = nullptr; - if (dex_priority) { - dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); - dex_priority_.assign(dex_priority_elements, - dex_priority_elements + - env->GetArrayLength(dex_priority)); - } - - std::vector parameter_types_; - jlong *parameter_types_elements = nullptr; - if (parameter_types) { - parameter_types_elements = - env->GetLongArrayElements(parameter_types, nullptr); - parameter_types_.assign(parameter_types_elements, - parameter_types_elements + - env->GetArrayLength(parameter_types)); - } - - std::vector contains_parameter_types_; - jlong *contains_parameter_types_elements = nullptr; - if (contains_parameter_types) { - contains_parameter_types_elements = - env->GetLongArrayElements(contains_parameter_types, nullptr); - contains_parameter_types_.assign( - contains_parameter_types_elements, - contains_parameter_types_elements + - env->GetArrayLength(contains_parameter_types)); - } - - auto out = helper->FindMethodGettingField( - field_index, return_type, parameter_count, parameter_shorty_ ? parameter_shorty_ : "", - declaring_class, contains_parameter_types_, contains_parameter_types_, - dex_priority_, find_first); - - if (parameter_shorty_) - env->ReleaseStringUTFChars(parameter_shorty, parameter_shorty_); - if (dex_priority_elements) - env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, - JNI_ABORT); - if (parameter_types_elements) - env->ReleaseLongArrayElements(parameter_types, parameter_types_elements, - JNI_ABORT); - if (contains_parameter_types_elements) - env->ReleaseLongArrayElements(contains_parameter_types, - contains_parameter_types_elements, JNI_ABORT); - auto res = env->NewLongArray(static_cast(out.size())); - auto res_element = env->GetLongArrayElements(res, nullptr); - for (size_t i = 0; i < out.size(); ++i) { - res_element[i] = out[i]; - } - env->ReleaseLongArrayElements(res, res_element, 0); - return res; -} -extern "C" JNIEXPORT jlongArray JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_findField(JNIEnv *env, jobject thiz, - jlong type, - jintArray dex_priority, - jboolean find_first) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - std::vector dex_priority_; - jint *dex_priority_elements = nullptr; - if (dex_priority) { - dex_priority_elements = env->GetIntArrayElements(dex_priority, nullptr); - dex_priority_.assign(dex_priority_elements, - dex_priority_elements + - env->GetArrayLength(dex_priority)); - } - - auto out = helper->FindField(type, dex_priority_, find_first); - - if (dex_priority_elements) - env->ReleaseIntArrayElements(dex_priority, dex_priority_elements, - JNI_ABORT); - - auto res = env->NewLongArray(static_cast(out.size())); - auto res_element = env->GetLongArrayElements(res, nullptr); - for (size_t i = 0; i < out.size(); ++i) { - res_element[i] = out[i]; - } - env->ReleaseLongArrayElements(res, res_element, 0); - return res; -} - -extern "C" JNIEXPORT jobject JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_decodeMethodIndex(JNIEnv *env, - jobject thiz, - jlong method_index) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - auto out = helper->DecodeMethod(method_index); - auto cl = env->GetObjectField(thiz, class_loader_field); - auto clazz = LoadClass(env, cl, out.declaring_class.name); - env->DeleteLocalRef(cl); - std::string sig; - sig.reserve(4096); - sig += "("; - for (const auto ¶m : out.parameters) { - sig += param.name; - } - sig += ")"; - sig += out.return_type.name; - auto *method = env->GetMethodID(clazz, out.name.data(), sig.data()); - if ((*env).ExceptionCheck()) { - (*env).ExceptionClear(); - } - if (!method) { - method = env->GetStaticMethodID(clazz, out.name.data(), sig.data()); - } - return env->ToReflectedMethod(clazz, method, false); -} - -extern "C" JNIEXPORT jobject JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_decodeFieldIndex(JNIEnv *env, - jobject thiz, - jlong field_index) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - auto out = helper->DecodeField(field_index); - auto cl = env->GetObjectField(thiz, class_loader_field); - auto clazz = LoadClass(env, cl, out.declaring_class.name); - env->DeleteLocalRef(cl); - return env->ToReflectedField( - clazz, env->GetFieldID(clazz, out.name.data(), out.type.name.data()), - false); -} - -extern "C" JNIEXPORT jlong JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_encodeClassIndex(JNIEnv *env, - jobject thiz, - jclass clazz) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - return helper->CreateClassIndex(GetClassDescriptor(env, clazz)); -} - -extern "C" JNIEXPORT jlong JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_encodeFieldIndex(JNIEnv *env, - jobject thiz, - jobject field) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return -1; - auto java_name = (jstring)env->CallObjectMethod(field, get_name_method); - auto clazz = (jclass)env->CallObjectMethod(field, get_declaring_class_method); - auto name = env->GetStringUTFChars(java_name, nullptr); - auto res = helper->CreateFieldIndex(name, GetClassDescriptor(env, clazz)); - env->ReleaseStringUTFChars(java_name, name); - return res; -} - -extern "C" JNIEXPORT jlong JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_encodeMethodIndex(JNIEnv *env, - jobject thiz, - jobject method) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return -1; - auto java_name = (jstring)env->CallObjectMethod(method, get_name_method); - auto clazz = - (jclass)env->CallObjectMethod(method, get_declaring_class_method); - auto name = env->GetStringUTFChars(java_name, nullptr); - auto params = - (jobjectArray)env->CallObjectMethod(method, get_parameters_method); - auto param_len = env->GetArrayLength(params); - std::vector param_descriptors; - param_descriptors.reserve(param_len); - for (size_t i = 0; i < param_len; ++i) { - auto param = (jclass)env->GetObjectArrayElement(params, i); - param_descriptors.emplace_back(GetClassDescriptor(env, param)); - env->DeleteLocalRef(param); - } - std::vector params_name; - params_name.reserve(param_descriptors.size()); - for (const auto &descriptor : param_descriptors) { - params_name.emplace_back(descriptor); - } - auto res = helper->CreateMethodIndex(name, GetClassDescriptor(env, clazz), - params_name); - env->ReleaseStringUTFChars(java_name, name); - return res; -} - -extern "C" JNIEXPORT jclass JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_decodeClassIndex(JNIEnv *env, - jobject thiz, - jlong class_index) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return nullptr; - auto out = helper->DecodeClass(class_index); - auto cl = env->GetObjectField(thiz, class_loader_field); - auto res = LoadClass(env, cl, out.name); - env->DeleteLocalRef(cl); - return res; -} - -extern "C" JNIEXPORT void JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_close(JNIEnv *env, jobject thiz) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - env->SetLongField(thiz, token_field, jlong(0)); - delete helper; -} - -extern "C" JNIEXPORT jint JNICALL BILI_JNI_OnLoad(JavaVM *vm, void *) { - JNIEnv *env = nullptr; - if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_4) != JNI_OK) { - return -1; - } - jclass helper = env->FindClass("me/iacn/biliroaming/utils/DexHelper"); - token_field = env->GetFieldID(helper, "token", "J"); - class_loader_field = - env->GetFieldID(helper, "classLoader", "Ljava/lang/ClassLoader;"); - auto class_loader = env->FindClass("java/lang/ClassLoader"); - load_class_method = env->GetMethodID( - class_loader, "loadClass", "(Ljava/lang/String;Z)Ljava/lang/Class;"); - auto member = env->FindClass("java/lang/reflect/Member"); - get_declaring_class_method = - env->GetMethodID(member, "getDeclaringClass", "()Ljava/lang/Class;"); - get_name_method = env->GetMethodID(member, "getName", "()Ljava/lang/String;"); - auto executable = env->FindClass("java/lang/reflect/Executable"); - get_parameters_method = - env->GetMethodID(executable, "getParameterTypes", "()[Ljava/lang/Class;"); - auto clazz = env->FindClass("java/lang/Class"); - get_class_name_method = - env->GetMethodID(clazz, "getName", "()Ljava/lang/String;"); - auto dex_class_loader = env->FindClass("dalvik/system/BaseDexClassLoader"); - path_list_field = env->GetFieldID(dex_class_loader, "pathList", - "Ldalvik/system/DexPathList;"); - auto dex_path_list = env->FindClass("dalvik/system/DexPathList"); - element_field = env->GetFieldID(dex_path_list, "dexElements", - "[Ldalvik/system/DexPathList$Element;"); - auto element = env->FindClass("dalvik/system/DexPathList$Element"); - dex_file_field = - env->GetFieldID(element, "dexFile", "Ldalvik/system/DexFile;"); - auto dex_file = env->FindClass("dalvik/system/DexFile"); - cookie_field = env->GetFieldID(dex_file, "mCookie", "Ljava/lang/Object;"); - return JNI_VERSION_1_4; -} - -extern "C" -JNIEXPORT void JNICALL -Java_me_iacn_biliroaming_utils_DexHelper_createFullCache(JNIEnv *env, jobject thiz) { - auto *helper = - reinterpret_cast(env->GetLongField(thiz, token_field)); - if (!helper) - return; - helper->CreateFullCache(); -} diff --git a/app/src/main/cpp/dex_builder b/app/src/main/cpp/dex_builder deleted file mode 160000 index 77f48fdd..00000000 --- a/app/src/main/cpp/dex_builder +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 77f48fdd795f5e178aeefb6858e3357505e5daba diff --git a/app/src/main/cpp/logging.h b/app/src/main/cpp/logging.h deleted file mode 100644 index 2f3b6145..00000000 --- a/app/src/main/cpp/logging.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _LOGGING_H -#define _LOGGING_H - -#include - -#ifndef LOG_TAG -#define LOG_TAG "SimplicityTools" -#endif - -#ifdef LOG_DISABLED -#define LOGD(...) -#define LOGV(...) -#define LOGI(...) -#define LOGW(...) -#define LOGE(...) -#else -#ifndef NDEBUG -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) -#else -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) -#endif -#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) -#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) -#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) -#endif - -#endif // _LOGGING_H diff --git a/app/src/main/cpp/native.cpp b/app/src/main/cpp/native.cpp deleted file mode 100644 index aab2b785..00000000 --- a/app/src/main/cpp/native.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "logging.h" -#include "native.h" - -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { - LOGD("%s", "JNI_OnLoad"); - BILI_JNI_OnLoad(vm, reserved); - return JNI_VERSION_1_6; -} diff --git a/app/src/main/cpp/native.h b/app/src/main/cpp/native.h deleted file mode 100644 index e7989924..00000000 --- a/app/src/main/cpp/native.h +++ /dev/null @@ -1,10 +0,0 @@ -// -// Created by Owner on 2022/3/9. -// - -#ifndef FUCKCOOLAPKR_NATIVE_H -#define FUCKCOOLAPKR_NATIVE_H - -extern "C" jint BILI_JNI_OnLoad(JavaVM *vm, void *reserved); - -#endif //FUCKCOOLAPKR_NATIVE_H diff --git a/app/src/main/cpp/native_api.h b/app/src/main/cpp/native_api.h deleted file mode 100644 index f2c3e5fe..00000000 --- a/app/src/main/cpp/native_api.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef XPOSEDTEMPLATE_NATIVE_API_H -#define XPOSEDTEMPLATE_NATIVE_API_H - -#include -#include - -typedef int (*HookFunType)(void *func, void *replace, void **backup); - -typedef int (*UnhookFunType)(void *func); - -typedef void (*NativeOnModuleLoaded)(const char *name, void *handle); - -typedef struct { - uint32_t version; - HookFunType hookFunc; - UnhookFunType unhookFunc; -} NativeAPIEntries; - -typedef NativeOnModuleLoaded (*NativeInit)(const NativeAPIEntries *entries); - -#endif //XPOSEDTEMPLATE_NATIVE_API_H diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt index 4847c113..6b2dcd6f 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SecurityCenter.kt @@ -4,24 +4,14 @@ import com.lt2333.simplicitytools.hook.app.securitycenter.LockOneHundred import com.lt2333.simplicitytools.hook.app.securitycenter.RemoveMacroBlacklist import com.lt2333.simplicitytools.hook.app.securitycenter.ShowBatteryTemperature import com.lt2333.simplicitytools.hook.app.securitycenter.SkipWaitingTime -import com.lt2333.simplicitytools.util.log import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.XposedBridge import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam -import me.iacn.biliroaming.utils.DexHelper class SecurityCenter : IXposedHookLoadPackage { - var dexHelper: DexHelper? = null - override fun handleLoadPackage(lpparam: LoadPackageParam) { XposedBridge.log("Simplicitytools: 成功 Hook "+javaClass.simpleName) - try { - System.loadLibrary("DexBuilder") - dexHelper = DexHelper.getInstance(lpparam.classLoader) - } catch (e: UnsatisfiedLinkError) { - log("DexBuilder 加载失败") - } //跳过 5/10秒等待时间 SkipWaitingTime().handleLoadPackage(lpparam) //锁定 100分 @@ -29,6 +19,6 @@ class SecurityCenter : IXposedHookLoadPackage { //去除自动连招黑名单 RemoveMacroBlacklist().handleLoadPackage(lpparam) //显示电池温度 - ShowBatteryTemperature(dexHelper).handleLoadPackage(lpparam) + ShowBatteryTemperature().handleLoadPackage(lpparam) } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt index 81fa6aa0..66fd0f3e 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/securitycenter/ShowBatteryTemperature.kt @@ -16,37 +16,12 @@ import cn.fkj233.ui.activity.dp2px import com.lt2333.simplicitytools.util.* import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.callbacks.XC_LoadPackage -import me.iacn.biliroaming.utils.DexHelper import java.lang.reflect.Field -class ShowBatteryTemperature(private val dexHelper: DexHelper?): IXposedHookLoadPackage { +class ShowBatteryTemperature: IXposedHookLoadPackage { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { if (!XSPUtils.getBoolean("battery_life_function", false)) return - if (dexHelper == null) { - log("DexHelper为null,hook ShowBatteryTemperature 失败") - return - } - - val methodIndex = dexHelper.findMethodUsingString( - "isBatteryLifeFunctionSupported", - true, - -1, - 0, - null, - -1, - null, - null, - null, - true - ).firstOrNull() - if (methodIndex == null) { - log("ShowBatteryTemperature 无法定位方法") - return - } - val method = dexHelper.decodeMethodIndex(methodIndex) - log(method) - method.hookBeforeMethod { it.result = true } val a = "com.miui.powercenter.a\$a".findClass(lpparam.classLoader) "com.miui.powercenter.a".hookBeforeMethod(lpparam.classLoader, "b", Context::class.java) { it.result = getBatteryTemperature(it.args[0] as Context).toString() diff --git a/app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java b/app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java deleted file mode 100644 index f676c227..00000000 --- a/app/src/main/java/me/iacn/biliroaming/utils/DexHelper.java +++ /dev/null @@ -1,87 +0,0 @@ -package me.iacn.biliroaming.utils; - -import com.lt2333.simplicitytools.util.KotlinXposedHelperKt; - -import java.io.Closeable; -import java.lang.reflect.Field; -import java.lang.reflect.Member; - -import dalvik.system.BaseDexClassLoader; - -public class DexHelper implements AutoCloseable, Closeable { - public static final int NO_CLASS_INDEX = -1; - private final ClassLoader classLoader; - private final long token; - private static DexHelper instance; - - public static DexHelper getInstance(ClassLoader classLoader) { - synchronized (DexHelper.class) { - if (instance != null) return instance; - BaseDexClassLoader loader = KotlinXposedHelperKt.findDexClassLoader(classLoader); - if (loader == null) { - return null; - } - instance = new DexHelper(loader); - return instance; - } - } - - public DexHelper(ClassLoader classLoader) { - this.classLoader = classLoader; - token = load(classLoader); - } - - public native long[] findMethodUsingString( - String str, boolean matchPrefix, long returnType, short parameterCount, - String parameterShorty, long declaringClass, long[] parameterTypes, - long[] containsParameterTypes, int[] dexPriority, boolean findFirst); - - public native long[] findMethodInvoking(long methodIndex, long returnType, - short parameterCount, String parameterShorty, - long declaringClass, long[] parameterTypes, - long[] containsParameterTypes, - int[] dexPriority, boolean findFirst); - - public native long[] findMethodInvoked(long methodIndex, long returnType, - short parameterCount, String parameterShorty, - long declaringClass, long[] parameterTypes, - long[] containsParameterTypes, - int[] dexPriority, boolean findFirst); - - public native long[] findMethodSettingField( - long fieldIndex, long returnType, short parameterCount, - String parameterShorty, long declaringClass, long[] parameterTypes, - long[] containsParameterTypes, int[] dexPriority, boolean findFirst); - - public native long[] findMethodGettingField( - long fieldIndex, long returnType, short parameterCount, - String parameterShorty, long declaringClass, long[] parameterTypes, - long[] containsParameterTypes, int[] dexPriority, boolean findFirst); - - public native long[] findField(long type, int[] dexPriority, boolean findFirst); - - public native Member decodeMethodIndex(long methodIndex); - - public native long encodeMethodIndex(Member method); - - public native Field decodeFieldIndex(long fieldIndex); - - public native long encodeFieldIndex(Field field); - - public native long encodeClassIndex(Class clazz); - - public native Class decodeClassIndex(long classIndex); - - public native void createFullCache(); - - @Override - public native void close(); - - @Override - protected void finalize() { - close(); - } - - private native long load(ClassLoader classLoader); -} -