Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyZhang023 committed Aug 25, 2018
1 parent 13b49d0 commit 6606af5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 85 deletions.
59 changes: 40 additions & 19 deletions jni/main/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@

#include "logging.h"

static const char *sim_operator_numeric = "310030";
static const char *sim_operator_country = "us";

void set_sim_operator_numeric(const char *string) {
sim_operator_numeric = strdup(string);
}

void set_sim_operator_country(const char *string) {
sim_operator_country = strdup(string);
}

#define XHOOK_REGISTER(NAME) \
if (xhook_register(".*", #NAME, (void*) new_##NAME, (void **) &old_##NAME) != 0) \
LOGE("failed to register hook " #NAME "."); \
Expand All @@ -36,24 +25,56 @@ void set_sim_operator_country(const char *string) {
NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) {
int res = old___system_property_get(key, value);
if (key) {
if (strcmp("gsm.sim.operator.numeric", key) == 0) {
strcpy(value, sim_operator_numeric);
if (strcmp("ro.miui.ui.version.name", key) == 0) {
strcpy(value, "V9");
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);
} else if (strcmp("ro.miui.version.code_time", key) == 0) {
strcpy(value, "1527550858");
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);
} else if (strcmp("gsm.sim.operator.iso-country", key) == 0) {
strcpy(value, sim_operator_country);
} else if (strcmp("ro.product.manufacturer", key) == 0) {
strcpy(value, "Xiaomi");
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);
} else if (strcmp("ro.product.name", key) == 0) {
strcpy(value, "Xiaomi");
LOGI("system_property_get: %s -> %s", key, value);
}

}
return res;
}

NEW_FUNC_DEF(std::string, _ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_, const std::string &key, const std::string &default_value) {
std::string res = old__ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_(key, default_value);
if (strcmp("gsm.sim.operator.numeric", key.c_str()) == 0) {
res = sim_operator_numeric;

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());
} 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());
} 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());
} 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());
} else if (strcmp("ro.product.manufacturer", key.c_str()) == 0) {
res = "Xiaomi";
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());
} else if (strcmp("gsm.sim.operator.iso-country", key.c_str()) == 0) {
res = sim_operator_country;
} else if (strcmp("ro.product.name", key.c_str()) == 0) {
res = "Xiaomi";
LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
}
return res;
Expand Down
3 changes: 1 addition & 2 deletions jni/main/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define HOOK_H

void install_hook(const char* package_name, int user);
void set_sim_operator_numeric(const char *string);
void set_sim_operator_country(const char* string);


#endif // HOOK_H
59 changes: 1 addition & 58 deletions jni/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,8 @@

static char package_name[256];
static int uid;
static int enable_hook;
static std::vector<std::string> packages = {
"com.google.android.gms",
"com.google.android.gsf",
"com.google.android.apps.maps"
};
static int enable_hook = true;

int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
if (!appDataDir)
return 0;


const char *app_data_dir = env->GetStringUTFChars(appDataDir, NULL);

int user = 0;
if (sscanf(app_data_dir, "/data/%*[^/]/%d/%s", &user, package_name) != 2) {
if (sscanf(app_data_dir, "/data/%*s/%s", package_name) != 1) {
package_name[0] = '\0';
LOGW("can't parse %s", app_data_dir);
return 0;
}
}

env->ReleaseStringUTFChars(appDataDir, app_data_dir);

if (access(CONFIG_PATH "/packages", R_OK) != 0) {
for (auto &s : packages) {
if (strcmp(s.c_str(), package_name) == 0)
return 1;
}
} else {
char path[PATH_MAX];
snprintf(path, PATH_MAX, CONFIG_PATH "/packages/%s", package_name);
return access(path, F_OK) == 0;
}
return 0;
}

void load_config() {
char buf[PROP_VALUE_MAX + 1];
int fd;
fd = open(CONFIG_PATH "/gsm.sim.operator.numeric", O_RDONLY);
if (fd > 0 && fdgets(buf, sizeof(buf), fd) > 0)
set_sim_operator_numeric(buf);

if (fd > 0)
close(fd);

fd = open(CONFIG_PATH "/gsm.sim.operator.iso-country", O_RDONLY);
if (fd > 0 && fdgets(buf, sizeof(buf), fd) > 0)
set_sim_operator_country(buf);

if (fd > 0)
close(fd);
}

void nativeForkAndSpecialize(int res, int enable_hook, const char *package_name, jint uid) {
if (res == 0 && enable_hook) {
Expand All @@ -97,10 +44,6 @@ __attribute__((visibility("default"))) void nativeForkAndSpecializePre(JNIEnv *e
jstring instructionSet,
jstring appDataDir) {
uid = _uid;
enable_hook = is_app_need_hook(env, appDataDir);

if (enable_hook)
load_config();
}

__attribute__((visibility("default"))) int nativeForkAndSpecializePost(JNIEnv *env, jclass clazz,
Expand Down
2 changes: 1 addition & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<manifest package="moe.rikka.riru.locationreportenabler" />
<manifest package="net.buguake.mipushmake" />
8 changes: 4 additions & 4 deletions template_override/module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=riru_location_report_enabler
name=Riru - Location Report Enabler
id=riru_mipushmake
name=Riru - MiPushMakeModule
version=v3
versionCode=3
author=Rikka
description=Enable location report by hook system_property_get. Require Riru - Core installed.
author=Timothy
description=Fake as XiaoMI device by hook system_property_get. Require Riru - Core installed.
minMagisk=1500
2 changes: 1 addition & 1 deletion template_override/riru_module.prop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Module template
version=v3
versionCode=3
author=Rikka
author=Timothy
description=Module template

0 comments on commit 6606af5

Please sign in to comment.