Support MagiskHide when /sbin does not exist

This commit is contained in:
topjohnwu 2020-04-18 23:45:00 -07:00
parent 4c959cd983
commit 1e714af3cf
3 changed files with 20 additions and 16 deletions

View File

@ -87,13 +87,14 @@ void hide_unmount(int pid) {
vector<string> targets; vector<string> targets;
// Unmount dummy skeletons and /sbin links // Unmount dummy skeletons and /sbin links
targets.push_back(MAGISKTMP);
parse_mnt("/proc/self/mounts", [&](mntent *mentry) { parse_mnt("/proc/self/mounts", [&](mntent *mentry) {
if (TMPFS_MNT(system) || TMPFS_MNT(vendor) || TMPFS_MNT(sbin) || TMPFS_MNT(product)) if (TMPFS_MNT(system) || TMPFS_MNT(vendor) || TMPFS_MNT(product) || TMPFS_MNT(system_ext))
targets.emplace_back(mentry->mnt_dir); targets.emplace_back(mentry->mnt_dir);
return true; return true;
}); });
for (auto &s : targets) for (auto &s : reversed(targets))
lazy_unmount(s.data()); lazy_unmount(s.data());
targets.clear(); targets.clear();
@ -104,7 +105,7 @@ void hide_unmount(int pid) {
return true; return true;
}); });
for (auto &s : targets) for (auto &s : reversed(targets))
lazy_unmount(s.data()); lazy_unmount(s.data());
} }

View File

@ -121,15 +121,13 @@ static int rm_list(const char *pkg, const char *proc = "") {
// Critical region // Critical region
mutex_guard lock(monitor_lock); mutex_guard lock(monitor_lock);
bool remove = false; bool remove = false;
auto next = hide_set.begin(); for (auto it = hide_set.begin(); it != hide_set.end();) {
decltype(next) cur; if (it->first == pkg && (proc[0] == '\0' || it->second == proc)) {
while (next != hide_set.end()) {
cur = next;
++next;
if (cur->first == pkg && (proc[0] == '\0' || cur->second == proc)) {
remove = true; remove = true;
LOGI("hide_list rm: [%s]\n", cur->second.data()); LOGI("hide_list rm: [%s]\n", it->second.data());
hide_set.erase(cur); it = hide_set.erase(it);
} else {
++it;
} }
} }
if (!remove) if (!remove)
@ -166,6 +164,11 @@ static void init_list(const char *pkg, const char *proc) {
#define LEGACY_LIST MODULEROOT "/.core/hidelist" #define LEGACY_LIST MODULEROOT "/.core/hidelist"
#define SAFETYNET_COMPONENT "com.google.android.gms/.droidguard.DroidGuardService"
#define SAFETYNET_PROCESS "com.google.android.gms.unstable"
#define SAFETYNET_PKG "com.google.android.gms"
#define MICROG_SAFETYNET "org.microg.gms.droidguard"
bool init_list() { bool init_list() {
LOGD("hide_list: initialize\n"); LOGD("hide_list: initialize\n");
@ -196,6 +199,11 @@ bool init_list() {
init_list(SAFETYNET_PKG, SAFETYNET_PROCESS); init_list(SAFETYNET_PKG, SAFETYNET_PROCESS);
init_list(MICROG_SAFETYNET, SAFETYNET_PROCESS); init_list(MICROG_SAFETYNET, SAFETYNET_PROCESS);
// We also need to hide the default GMS process if MAGISKTMP != /sbin
// The snet process communicates with the main process and get additional info
if (MAGISKTMP != "/sbin")
init_list(SAFETYNET_PKG, SAFETYNET_PKG);
update_uid_map(); update_uid_map();
return true; return true;
} }

View File

@ -15,11 +15,6 @@
#define SIGTERMTHRD SIGUSR1 #define SIGTERMTHRD SIGUSR1
#define SIGZYGOTE SIGUSR2 #define SIGZYGOTE SIGUSR2
#define SAFETYNET_COMPONENT "com.google.android.gms/.droidguard.DroidGuardService"
#define SAFETYNET_PROCESS "com.google.android.gms.unstable"
#define SAFETYNET_PKG "com.google.android.gms"
#define MICROG_SAFETYNET "org.microg.gms.droidguard"
// CLI entries // CLI entries
void launch_magiskhide(int client); void launch_magiskhide(int client);
int stop_magiskhide(); int stop_magiskhide();