Add API for running independent proc_monitor test
This commit is contained in:
parent
75405b2b25
commit
21984fac8b
@ -328,3 +328,10 @@ void auto_start_magiskhide() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_proc_monitor() {
|
||||||
|
if (procfp == nullptr && (procfp = opendir("/proc")) == nullptr)
|
||||||
|
exit(1);
|
||||||
|
proc_monitor();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include "magiskhide.h"
|
#include "magiskhide.h"
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
bool hide_enabled = false;
|
bool hide_enabled = false;
|
||||||
|
|
||||||
[[noreturn]] static void usage(char *arg0) {
|
[[noreturn]] static void usage(char *arg0) {
|
||||||
@ -26,6 +28,7 @@ bool hide_enabled = false;
|
|||||||
" --add PKG [PROC] Add a new target to the hide list\n"
|
" --add PKG [PROC] Add a new target to the hide list\n"
|
||||||
" --rm PKG [PROC] Remove from the hide list\n"
|
" --rm PKG [PROC] Remove from the hide list\n"
|
||||||
" --ls List the current hide list\n"
|
" --ls List the current hide list\n"
|
||||||
|
" --test Run process monitor test\n"
|
||||||
, arg0);
|
, arg0);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -77,18 +80,20 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
|
||||||
int req;
|
int req;
|
||||||
if (strcmp(argv[1], "--enable") == 0)
|
if (argv[1] == "--enable"sv)
|
||||||
req = LAUNCH_MAGISKHIDE;
|
req = LAUNCH_MAGISKHIDE;
|
||||||
else if (strcmp(argv[1], "--disable") == 0)
|
else if (argv[1] == "--disable"sv)
|
||||||
req = STOP_MAGISKHIDE;
|
req = STOP_MAGISKHIDE;
|
||||||
else if (strcmp(argv[1], "--add") == 0 && argc > 2)
|
else if (argv[1] == "--add"sv)
|
||||||
req = ADD_HIDELIST;
|
req = ADD_HIDELIST;
|
||||||
else if (strcmp(argv[1], "--rm") == 0 && argc > 2)
|
else if (argv[1] == "--rm"sv)
|
||||||
req = RM_HIDELIST;
|
req = RM_HIDELIST;
|
||||||
else if (strcmp(argv[1], "--ls") == 0)
|
else if (argv[1] == "--ls"sv)
|
||||||
req = LS_HIDELIST;
|
req = LS_HIDELIST;
|
||||||
else if (strcmp(argv[1], "--status") == 0)
|
else if (argv[1] == "--status"sv)
|
||||||
req = HIDE_STATUS;
|
req = HIDE_STATUS;
|
||||||
|
else if (argv[1] == "--test"sv)
|
||||||
|
test_proc_monitor();
|
||||||
else
|
else
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ int stop_magiskhide();
|
|||||||
int add_list(int client);
|
int add_list(int client);
|
||||||
int rm_list(int client);
|
int rm_list(int client);
|
||||||
void ls_list(int client);
|
void ls_list(int client);
|
||||||
|
[[noreturn]] void test_proc_monitor();
|
||||||
|
|
||||||
// Process monitoring
|
// Process monitoring
|
||||||
void proc_monitor();
|
void proc_monitor();
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
/* proc_monitor.cpp - Monitor am_proc_start events and unmount
|
|
||||||
*
|
|
||||||
* We monitor the listed APK files from /data/app until they get opened
|
|
||||||
* via inotify to detect a new app launch.
|
|
||||||
*
|
|
||||||
* If it's a target we pause it ASAP, and fork a new process to join
|
|
||||||
* its mount namespace and do all the unmounting/mocking.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -188,9 +179,6 @@ static void setup_inotify() {
|
|||||||
} else {
|
} else {
|
||||||
inotify_add_watch(inotify_fd, APP_PROC, IN_ACCESS);
|
inotify_add_watch(inotify_fd, APP_PROC, IN_ACCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First find existing zygotes
|
|
||||||
check_zygote();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
@ -291,12 +279,12 @@ static void term_thread(int) {
|
|||||||
* Ptrace Madness
|
* Ptrace Madness
|
||||||
******************/
|
******************/
|
||||||
|
|
||||||
/* Ptrace is super tricky, preserve all excessive debug in code
|
/* Ptrace is super tricky, preserve all excessive logging in code
|
||||||
* but disable when actually building for usage (you won't want
|
* but disable when actually building for usage (you won't want
|
||||||
* your logcat spammed with new thread events from all apps) */
|
* your logcat spammed with new thread events from all apps) */
|
||||||
|
|
||||||
//#define PTRACE_LOG(fmt, args...) LOGD("PID=[%d] " fmt, pid, ##args)
|
#define PTRACE_LOG(fmt, args...) LOGD("PID=[%d] " fmt, pid, ##args)
|
||||||
#define PTRACE_LOG(...)
|
//#define PTRACE_LOG(...)
|
||||||
|
|
||||||
static void detach_pid(int pid, int signal = 0) {
|
static void detach_pid(int pid, int signal = 0) {
|
||||||
char path[128];
|
char path[128];
|
||||||
@ -371,7 +359,7 @@ static bool check_pid(int pid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PTRACE_LOG("not our target\n");
|
PTRACE_LOG("[%s] not our target\n", cmdline);
|
||||||
detach_pid(pid);
|
detach_pid(pid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -414,6 +402,9 @@ void proc_monitor() {
|
|||||||
|
|
||||||
setup_inotify();
|
setup_inotify();
|
||||||
|
|
||||||
|
// First find existing zygotes
|
||||||
|
check_zygote();
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
Loading…
Reference in New Issue
Block a user