Fix process name in MagiskHide

close #3997
This commit is contained in:
vvb2060 2021-03-18 13:36:42 +08:00 committed by John Wu
parent ed4d0867e8
commit 6865652125
6 changed files with 12 additions and 6 deletions

View File

@ -66,7 +66,7 @@ open class FlashZip(
console.add("- Installing ${mUri.displayName}") console.add("- Installing ${mUri.displayName}")
return Shell.su("sh $installDir/update-binary dummy 1 \"$zipFile\"") return Shell.su("sh $installDir/update-binary dummy 1 \'$zipFile\'")
.to(console, logs).exec().isSuccess .to(console, logs).exec().isSuccess
} }

View File

@ -99,7 +99,7 @@ class HideProcessRvItem(
set(value) = set(value, process.isHidden, { process.isHidden = it }, BR.hidden) { set(value) = set(value, process.isHidden, { process.isHidden = it }, BR.hidden) {
val arg = if (it) "add" else "rm" val arg = if (it) "add" else "rm"
val (name, pkg) = process val (name, pkg) = process
Shell.su("magiskhide $arg $pkg $name").submit() Shell.su("magiskhide $arg $pkg \'$name\'").submit()
} }
fun toggle() { fun toggle() {

View File

@ -108,6 +108,8 @@ static bool validate(const char *s) {
(c >= '0' && c <= '9') || c == '_' || c == ':') { (c >= '0' && c <= '9') || c == '_' || c == ':') {
continue; continue;
} }
if (SDK_INT >= 29 && c == '$')
continue;
if (c == '.') { if (c == '.') {
dot = true; dot = true;
continue; continue;
@ -333,7 +335,7 @@ void auto_start_magiskhide(bool late_props) {
} }
} }
bool is_hide_target(int uid, string_view process) { bool is_hide_target(int uid, string_view process, int max_len) {
mutex_guard lock(hide_state_lock); mutex_guard lock(hide_state_lock);
if (uid % 100000 >= 90000) { if (uid % 100000 >= 90000) {
@ -343,6 +345,8 @@ bool is_hide_target(int uid, string_view process) {
return false; return false;
for (auto &s : it->second) { for (auto &s : it->second) {
if (s.length() > max_len && process.length() > max_len && str_starts(s, process))
return true;
if (str_starts(process, s)) if (str_starts(process, s))
return true; return true;
} }
@ -352,6 +356,8 @@ bool is_hide_target(int uid, string_view process) {
return false; return false;
for (auto &s : it->second) { for (auto &s : it->second) {
if (s.length() > max_len && process.length() > max_len && str_starts(s, process))
return true;
if (s == process) if (s == process)
return true; return true;
} }

View File

@ -36,7 +36,7 @@ void crawl_procfs(const std::function<bool (int)> &fn);
void crawl_procfs(DIR *dir, const std::function<bool (int)> &fn); void crawl_procfs(DIR *dir, const std::function<bool (int)> &fn);
bool hide_enabled(); bool hide_enabled();
void update_uid_map(); void update_uid_map();
bool is_hide_target(int uid, std::string_view process); bool is_hide_target(int uid, std::string_view process, int max_len = 1024);
// Hide policies // Hide policies
void hide_daemon(int pid); void hide_daemon(int pid);

View File

@ -212,7 +212,7 @@ static bool check_pid(int pid) {
cmdline == "usap32"sv || cmdline == "usap64"sv) cmdline == "usap32"sv || cmdline == "usap64"sv)
return false; return false;
if (!is_hide_target(uid, cmdline)) if (!is_hide_target(uid, cmdline, 95))
goto not_target; goto not_target;
// Ensure ns is separated // Ensure ns is separated

View File

@ -71,7 +71,7 @@ static inline bool str_contains(std::string_view s, std::string_view ss) {
return s.find(ss) != std::string::npos; return s.find(ss) != std::string::npos;
} }
static inline bool str_starts(std::string_view s, std::string_view ss) { static inline bool str_starts(std::string_view s, std::string_view ss) {
return s.rfind(ss, 0) == 0; return s.size() >= ss.size() && s.compare(0, ss.size(), ss) == 0;
} }
static inline bool str_ends(std::string_view s, std::string_view ss) { static inline bool str_ends(std::string_view s, std::string_view ss) {
return s.size() >= ss.size() && s.compare(s.size() - ss.size(), std::string::npos, ss) == 0; return s.size() >= ss.size() && s.compare(s.size() - ss.size(), std::string::npos, ss) == 0;