Skip to content

Commit

Permalink
fix crashes on some roms
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyZhang023 committed Apr 14, 2019
1 parent aae578c commit fe4a935
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ android {

task zip(type: Exec) {
workingDir '..'
commandLine 'sh', 'build.sh', project.name, 'v8'
commandLine 'sh', 'build.sh', project.name, 'v9'
}
28 changes: 14 additions & 14 deletions jni/main/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand All @@ -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;
}
Expand Down
62 changes: 45 additions & 17 deletions jni/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}


}
2 changes: 1 addition & 1 deletion template_override/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions template_override/module.prop
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions template_override/riru_module.prop
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit fe4a935

Please sign in to comment.