Skip to content

Commit

Permalink
Support execute commands in magiskhide env
Browse files Browse the repository at this point in the history
Credits to topjohnwu#1454
  • Loading branch information
topjohnwu committed Jun 5, 2019
1 parent 9f8d4e1 commit c1602d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions native/jni/magiskhide/hide_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ void hide_daemon(int pid) {
tgkill(pid, pid, SIGCONT);
_exit(0);
});
hide_unmount(pid);
}

void hide_unmount(int pid) {
if (switch_mnt_ns(pid))
return;

Expand Down
11 changes: 11 additions & 0 deletions native/jni/magiskhide/magiskhide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/mount.h>

#include <magisk.h>
#include <daemon.h>
#include <utils.h>
#include <flags.h>

#include "magiskhide.h"
Expand All @@ -28,6 +30,8 @@ bool hide_enabled = false;
" add PKG [PROC] Add a new target to the hide list\n"
" rm PKG [PROC] Remove target(s) from the hide list\n"
" ls Print the current hide list\n"
" exec CMDs... Execute commands in isolated mount\n"
" namespace and do all hide unmounts\n"
#ifdef MAGISK_DEBUG
" test Run process monitor test\n"
#endif
Expand Down Expand Up @@ -99,6 +103,13 @@ int magiskhide_main(int argc, char *argv[]) {
req = LS_HIDELIST;
else if (opt == "status"sv)
req = HIDE_STATUS;
else if (opt == "exec"sv && argc > 2) {
xunshare(CLONE_NEWNS);
xmount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr);
hide_unmount();
execvp(argv[2], argv + 2);
exit(1);
}
#ifdef MAGISK_DEBUG
else if (opt == "test"sv)
test_proc_monitor();
Expand Down
1 change: 1 addition & 0 deletions native/jni/magiskhide/magiskhide.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void crawl_procfs(DIR *dir, const std::function<bool (int)> &fn);

// Hide policies
void hide_daemon(int pid);
void hide_unmount(int pid = getpid());
void hide_sensitive_props();

extern bool hide_enabled;
Expand Down

0 comments on commit c1602d2

Please sign in to comment.