Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
support using already defined prop
Browse files Browse the repository at this point in the history
Add support to use values already set at runtime.
  • Loading branch information
eebssk1 committed Dec 22, 2021
1 parent 5b01316 commit ee8fd6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ ext {
moduleName = "mph"
moduleAuthor = "eebssk1"
moduleDescription = "Hook system prop function with dobby to simulate miui for MiPushFOSS"
moduleVersion = "v25.6.0"
moduleVersionCode = 37
moduleVersion = "v25.7.0"
moduleVersionCode = 38
}
23 changes: 18 additions & 5 deletions module/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace android {

static int apiLevel = 0;

static bool prefer_system = false;
static int GetApiLevel() {
if (LIKELY(apiLevel > 0)) return apiLevel;

Expand All @@ -38,6 +38,7 @@ namespace android {
}

namespace Config {

static int foreach_dir(const char *path, void(*callback)(int, struct dirent *)) {
DIR *dir;
struct dirent *entry;
Expand Down Expand Up @@ -124,6 +125,10 @@ namespace Config {
static void Load() {
foreach_dir(PROPS_PATH, [](int dirfd, struct dirent *entry) {
auto name = entry->d_name;
if(LIKELY(!strcmp(name,"prefer_system"))) {
android::prefer_system = true;
return;
}
int fd = openat(dirfd, name, O_RDONLY);
if (fd == -1) return;
char buf[PROP_VALUE_MAX]{0};
Expand Down Expand Up @@ -162,6 +167,7 @@ namespace Hook {
};

static std::map<std::string, struct prop_info_compat *> mprop;
static std::unordered_set<std::string> sys_aval_props;

static void prepare() {
LOGV("preparing fake prop memory..");
Expand All @@ -184,13 +190,20 @@ namespace Hook {
memset(mname, 0, psz);
strcpy(mname, name);
auto prop = Config::Properties::Find(mname);
prop_info *sysprop = orig__system_property_find(name);
if (UNLIKELY(prop)) {
auto it = mprop.find(mname);
if (it != mprop.end())
if (it != mprop.end()) {
if(UNLIKELY(android::prefer_system == true && sysprop)) {
if(UNLIKELY(sys_aval_props.find(mname)==sys_aval_props.end())) sys_aval_props.insert(mname);
return sysprop;
} else {
if(android::prefer_system == true && sys_aval_props.find(mname)!=sys_aval_props.end()) sys_aval_props.erase(mname);
}
}
return reinterpret_cast<prop_info *>(it->second);
return orig__system_property_find(name);
} else {
return orig__system_property_find(name);
return sysprop;
}
}

Expand All @@ -201,7 +214,7 @@ namespace Hook {

void
my__system_property_read_callback(const prop_info *pi, callback_func *callback, void *cookie) {
if(UNLIKELY(Config::Properties::Find(pi->name)))
if(UNLIKELY(Config::Properties::Find(pi->name) && !(android::prefer_system && sys_aval_props.find(pi->name)!=sys_aval_props.end())))
return callback(cookie, pi->name, pi->value, pi->serial);
return orig__system_property_read_callback(pi, callback, cookie);

Expand Down
3 changes: 3 additions & 0 deletions template/magisk_module/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ fi
if [ ! -d "$CONFIG_PATH/packages" ]; then
ui_print "- Creating default configuration (2)"
mkdir -p "$CONFIG_PATH/packages"

touch "$CONFIG_PATH/packages/prefer_system"

touch "$CONFIG_PATH/packages/cmb.pb"
touch "$CONFIG_PATH/packages/cn.adidas.app"
touch "$CONFIG_PATH/packages/com.autonavi.minimap"
Expand Down

0 comments on commit ee8fd6b

Please sign in to comment.