diff --git a/build.gradle b/build.gradle index 95ebfaa..94ccd2a 100644 --- a/build.gradle +++ b/build.gradle @@ -22,5 +22,5 @@ android { task zip(type: Exec) { workingDir '..' - commandLine 'sh', 'build.sh', project.name, 'v8' + commandLine 'sh', 'build.sh', project.name, 'v9' } \ No newline at end of file diff --git a/jni/main/hook.cpp b/jni/main/hook.cpp index 0c143bc..6f1075d 100644 --- a/jni/main/hook.cpp +++ b/jni/main/hook.cpp @@ -28,25 +28,25 @@ NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) { if (key) { if (strcmp("ro.miui.ui.version.name", key) == 0) { strcpy(value, "V9"); - LOGI("system_property_get: %s -> %s", key, value); + //LOGI("system_property_get: %s -> %s", key, value); } else if (strcmp("ro.miui.ui.version.code", key) == 0) { strcpy(value, "7"); - LOGI("system_property_get: %s -> %s", key, value); + //LOGI("system_property_get: %s -> %s", key, value); } else if (strcmp("ro.miui.version.code_time", key) == 0) { strcpy(value, "1527550858"); - LOGI("system_property_get: %s -> %s", key, value); + //LOGI("system_property_get: %s -> %s", key, value); } else if (strcmp("ro.miui.internal.storage", key) == 0) { strcpy(value, "/sdcard/"); - LOGI("system_property_get: %s -> %s", key, value); + //LOGI("system_property_get: %s -> %s", key, value); } else if (strcmp("ro.product.manufacturer", key) == 0) { strcpy(value, "Xiaomi"); - LOGI("system_property_get: %s -> %s", key, value); + //LOGI("system_property_get: %s -> %s", key, value); } else if (strcmp("ro.product.brand", key) == 0) { strcpy(value, "Xiaomi"); - LOGI("system_property_get: %s -> %s", key, value); + //LOGI("system_property_get: %s -> %s", key, value); } else if (strcmp("ro.product.name", key) == 0) { strcpy(value, "Xiaomi"); - LOGI("system_property_get: %s -> %s", key, value); + //LOGI("system_property_get: %s -> %s", key, value); } } @@ -58,25 +58,25 @@ NEW_FUNC_DEF(std::string, _ZN7android4base11GetPropertyERKNSt3__112basic_stringI if (strcmp("ro.miui.ui.version.name", key.c_str()) == 0) { res = "V9"; - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + //LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } else if (strcmp("ro.miui.ui.version.code", key.c_str()) == 0) { res = "7"; - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + //LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } else if (strcmp("ro.miui.version.code_time", key.c_str()) == 0) { res = "1527550858"; - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + //LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } else if (strcmp("ro.miui.internal.storage", key.c_str()) == 0) { res = "/sdcard/"; - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + //LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } else if (strcmp("ro.product.manufacturer", key.c_str()) == 0) { res = "Xiaomi"; - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + //LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } else if (strcmp("ro.product.brand", key.c_str()) == 0) { res = "Xiaomi"; - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + //LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } else if (strcmp("ro.product.name", key.c_str()) == 0) { res = "Xiaomi"; - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + //LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } return res; } diff --git a/jni/main/main.cpp b/jni/main/main.cpp index 6a57b2e..2a5133c 100644 --- a/jni/main/main.cpp +++ b/jni/main/main.cpp @@ -73,6 +73,48 @@ void load_config() { //empty } + + +void injectBuild(JNIEnv *env) { + if (env == 0) { + LOGW("failed to inject android.os.Build for %s due to env is null", package_name); + return; + } + LOGI("inject android.os.Build for %s ", package_name); + + jclass build_class = env->FindClass("android/os/Build"); + if (build_class == 0) { + LOGW("failed to inject android.os.Build for %s due to build is null", package_name); + return; + } + + jstring new_str = env->NewStringUTF("Xiaomi"); + + jfieldID brand_id = env->GetStaticFieldID(build_class, "BRAND", "Ljava/lang/String;"); + if (brand_id != 0) { + env->SetStaticObjectField(build_class, brand_id, new_str); + } + + jfieldID manufacturer_id = env->GetStaticFieldID(build_class, "MANUFACTURER", "Ljava/lang/String;"); + if (manufacturer_id != 0) { + env->SetStaticObjectField(build_class, manufacturer_id, new_str); + } + + jfieldID product_id = env->GetStaticFieldID(build_class, "PRODUCT", "Ljava/lang/String;"); + if (product_id != 0) { + env->SetStaticObjectField(build_class, product_id, new_str); + } + + if(env->ExceptionCheck()) + { + env->ExceptionClear(); + } + + env->DeleteLocalRef(new_str); + +} + + void nativeForkAndSpecialize(int res, int enable_hook, const char *package_name, jint uid) { if (res == 0 && enable_hook) { install_hook(package_name, uid / 100000); @@ -104,26 +146,12 @@ __attribute__((visibility("default"))) int nativeForkAndSpecializePost(JNIEnv *e jint res) { if (res == 0 && enable_hook) { - if (env) { - LOGI("inject android.os.Build for %s ", package_name); - - jclass build_class = env->FindClass("android/os/Build"); - jfieldID brand_id = env->GetStaticFieldID(build_class, "BRAND", "Ljava/lang/String;"); - jfieldID manufacturer_id = env->GetStaticFieldID(build_class, "MANUFACTURER", - "Ljava/lang/String;"); - jfieldID product_id = env->GetStaticFieldID(build_class, "PRODUCT", - "Ljava/lang/String;"); - - jstring new_str = env->NewStringUTF("Xiaomi"); - env->SetStaticObjectField(build_class, brand_id, new_str); - env->SetStaticObjectField(build_class, product_id, new_str); - env->SetStaticObjectField(build_class, manufacturer_id, new_str); - - env->DeleteLocalRef(new_str); - } + injectBuild(env); } nativeForkAndSpecialize(res, enable_hook, package_name, uid); return !enable_hook; } + + } diff --git a/template_override/config.sh b/template_override/config.sh index 97eb972..2b30036 100644 --- a/template_override/config.sh +++ b/template_override/config.sh @@ -25,7 +25,7 @@ AUTOMOUNT=true # Set to true if you need to load system.prop -PROPFILE=false +PROPFILE=true # Set to true if you need post-fs-data script POSTFSDATA=false diff --git a/template_override/module.prop b/template_override/module.prop index b96f229..a7ff252 100644 --- a/template_override/module.prop +++ b/template_override/module.prop @@ -1,7 +1,7 @@ id=mipush_fake name=Riru - MiPushFakeModule -version=v8 -versionCode=8 +version=v9 +versionCode=9 author=Timothy description=Fake as XiaoMI device by hook system_property_get. Require Riru - Core installed. minMagisk=17000 diff --git a/template_override/riru_module.prop b/template_override/riru_module.prop index 47acfc4..98e9b90 100644 --- a/template_override/riru_module.prop +++ b/template_override/riru_module.prop @@ -1,5 +1,5 @@ name=Riru - MiPushFakeModule -version=v8 -versionCode=8 +version=v9 +versionCode=9 author=Timothy description=Fake as XiaoMI device by hook system_property_get. Require Riru-Core v9+ installed. \ No newline at end of file