mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-04 16:07:38 +00:00
Add CLI to detect MagiskHide status
This commit is contained in:
parent
572e078d87
commit
3aad9d8166
@ -44,11 +44,11 @@ public class Const {
|
|||||||
public static final int USER_ID = Process.myUid() / 100000;
|
public static final int USER_ID = Process.myUid() / 100000;
|
||||||
|
|
||||||
public static final class MAGISK_VER {
|
public static final class MAGISK_VER {
|
||||||
public static final int REMOVE_LEGACY_LINK = 1630;
|
|
||||||
public static final int SEPOL_REFACTOR = 1640;
|
public static final int SEPOL_REFACTOR = 1640;
|
||||||
public static final int FIX_ENV = 1650;
|
public static final int FIX_ENV = 1650;
|
||||||
public static final int DBVER_SIX = 17000;
|
public static final int DBVER_SIX = 17000;
|
||||||
public static final int CMDLINE_DB = 17305;
|
public static final int CMDLINE_DB = 17305;
|
||||||
|
public static final int HIDE_STATUS = 17315;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ID {
|
public static class ID {
|
||||||
|
@ -91,8 +91,12 @@ public class Data {
|
|||||||
try {
|
try {
|
||||||
magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0];
|
magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0];
|
||||||
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
|
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
|
||||||
String s = ShellUtils.fastCmd(("resetprop -p ") + Const.MAGISKHIDE_PROP);
|
if (magiskVersionCode >= Const.MAGISK_VER.HIDE_STATUS) {
|
||||||
magiskHide = s.isEmpty() || Integer.parseInt(s) != 0;
|
magiskHide = Shell.su("magiskhide --status").exec().isSuccess();
|
||||||
|
} else {
|
||||||
|
String s = ShellUtils.fastCmd(("resetprop -p ") + Const.MAGISKHIDE_PROP);
|
||||||
|
magiskHide = s.isEmpty() || Integer.parseInt(s) != 0;
|
||||||
|
}
|
||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,15 +14,16 @@
|
|||||||
#include "resetprop.h"
|
#include "resetprop.h"
|
||||||
#include "flags.h"
|
#include "flags.h"
|
||||||
|
|
||||||
int hide_enabled = 0;
|
bool hide_enabled = false;
|
||||||
static pthread_t proc_monitor_thread;
|
static pthread_t proc_monitor_thread;
|
||||||
pthread_mutex_t list_lock;
|
pthread_mutex_t list_lock;
|
||||||
|
|
||||||
[[noreturn]] static void usage(char *arg0) {
|
[[noreturn]] static void usage(char *arg0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"MagiskHide v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu) - Hide Magisk!\n\n"
|
"MagiskHide v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu)\n\n"
|
||||||
"Usage: %s [--options [arguments...] ]\n\n"
|
"Usage: %s [--options [arguments...] ]\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
|
" --status Return the status of MagiskHide\n"
|
||||||
" --enable Start magiskhide\n"
|
" --enable Start magiskhide\n"
|
||||||
" --disable Stop magiskhide\n"
|
" --disable Stop magiskhide\n"
|
||||||
" --add PROCESS Add PROCESS to the hide list\n"
|
" --add PROCESS Add PROCESS to the hide list\n"
|
||||||
@ -43,7 +44,7 @@ int launch_magiskhide(int client) {
|
|||||||
return LOGCAT_DISABLED;
|
return LOGCAT_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
hide_enabled = 1;
|
hide_enabled = true;
|
||||||
LOGI("* Starting MagiskHide\n");
|
LOGI("* Starting MagiskHide\n");
|
||||||
|
|
||||||
deleteprop(MAGISKHIDE_PROP, true);
|
deleteprop(MAGISKHIDE_PROP, true);
|
||||||
@ -70,14 +71,14 @@ int launch_magiskhide(int client) {
|
|||||||
proc_monitor();
|
proc_monitor();
|
||||||
|
|
||||||
error:
|
error:
|
||||||
hide_enabled = 0;
|
hide_enabled = false;
|
||||||
return DAEMON_ERROR;
|
return DAEMON_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stop_magiskhide() {
|
int stop_magiskhide() {
|
||||||
LOGI("* Stopping MagiskHide\n");
|
LOGI("* Stopping MagiskHide\n");
|
||||||
|
|
||||||
hide_enabled = 0;
|
hide_enabled = false;
|
||||||
setprop(MAGISKHIDE_PROP, "0");
|
setprop(MAGISKHIDE_PROP, "0");
|
||||||
// Remove without actually removing persist props
|
// Remove without actually removing persist props
|
||||||
deleteprop(MAGISKHIDE_PROP);
|
deleteprop(MAGISKHIDE_PROP);
|
||||||
@ -119,6 +120,9 @@ void magiskhide_handler(int client) {
|
|||||||
ls_list(client);
|
ls_list(client);
|
||||||
client = -1;
|
client = -1;
|
||||||
break;
|
break;
|
||||||
|
case HIDE_STATUS:
|
||||||
|
res = hide_enabled ? HIDE_IS_ENABLED : HIDE_NOT_ENABLED;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_int(client, res);
|
write_int(client, res);
|
||||||
@ -126,61 +130,66 @@ void magiskhide_handler(int client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int magiskhide_main(int argc, char *argv[]) {
|
int magiskhide_main(int argc, char *argv[]) {
|
||||||
if (argc < 2) {
|
if (argc < 2)
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
}
|
|
||||||
int req;
|
|
||||||
if (strcmp(argv[1], "--enable") == 0) {
|
|
||||||
req = LAUNCH_MAGISKHIDE;
|
|
||||||
} else if (strcmp(argv[1], "--disable") == 0) {
|
|
||||||
req = STOP_MAGISKHIDE;
|
|
||||||
} else if (strcmp(argv[1], "--add") == 0 && argc > 2) {
|
|
||||||
req = ADD_HIDELIST;
|
|
||||||
} else if (strcmp(argv[1], "--rm") == 0 && argc > 2) {
|
|
||||||
req = RM_HIDELIST;
|
|
||||||
} else if (strcmp(argv[1], "--ls") == 0) {
|
|
||||||
req = LS_HIDELIST;
|
|
||||||
} else {
|
|
||||||
usage(argv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int req;
|
||||||
|
if (strcmp(argv[1], "--enable") == 0)
|
||||||
|
req = LAUNCH_MAGISKHIDE;
|
||||||
|
else if (strcmp(argv[1], "--disable") == 0)
|
||||||
|
req = STOP_MAGISKHIDE;
|
||||||
|
else if (strcmp(argv[1], "--add") == 0 && argc > 2)
|
||||||
|
req = ADD_HIDELIST;
|
||||||
|
else if (strcmp(argv[1], "--rm") == 0 && argc > 2)
|
||||||
|
req = RM_HIDELIST;
|
||||||
|
else if (strcmp(argv[1], "--ls") == 0)
|
||||||
|
req = LS_HIDELIST;
|
||||||
|
else if (strcmp(argv[1], "--status") == 0)
|
||||||
|
req = HIDE_STATUS;
|
||||||
|
else
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
// Send request
|
||||||
int fd = connect_daemon();
|
int fd = connect_daemon();
|
||||||
write_int(fd, MAGISKHIDE);
|
write_int(fd, MAGISKHIDE);
|
||||||
write_int(fd, req);
|
write_int(fd, req);
|
||||||
if (req == ADD_HIDELIST || req == RM_HIDELIST) {
|
if (req == ADD_HIDELIST || req == RM_HIDELIST)
|
||||||
write_string(fd, argv[2]);
|
write_string(fd, argv[2]);
|
||||||
}
|
|
||||||
|
// Get response
|
||||||
int code = read_int(fd);
|
int code = read_int(fd);
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case DAEMON_SUCCESS:
|
case DAEMON_SUCCESS:
|
||||||
break;
|
break;
|
||||||
case ROOT_REQUIRED:
|
|
||||||
fprintf(stderr, "Root is required for this operation\n");
|
|
||||||
return code;
|
|
||||||
case LOGCAT_DISABLED:
|
case LOGCAT_DISABLED:
|
||||||
fprintf(stderr, "Logcat is disabled, cannot start MagiskHide\n");
|
fprintf(stderr, "Logcat is disabled, cannot start MagiskHide\n");
|
||||||
return code;
|
break;
|
||||||
case HIDE_NOT_ENABLED:
|
case HIDE_NOT_ENABLED:
|
||||||
fprintf(stderr, "MagiskHide is not enabled yet\n");
|
fprintf(stderr, "MagiskHide is not enabled\n");
|
||||||
return code;
|
break;
|
||||||
case HIDE_IS_ENABLED:
|
case HIDE_IS_ENABLED:
|
||||||
fprintf(stderr, "MagiskHide is already enabled\n");
|
fprintf(stderr, "MagiskHide is enabled\n");
|
||||||
return code;
|
break;
|
||||||
case HIDE_ITEM_EXIST:
|
case HIDE_ITEM_EXIST:
|
||||||
fprintf(stderr, "Process [%s] already exists in hide list\n", argv[2]);
|
fprintf(stderr, "Process [%s] already exists in hide list\n", argv[2]);
|
||||||
return code;
|
break;
|
||||||
case HIDE_ITEM_NOT_EXIST:
|
case HIDE_ITEM_NOT_EXIST:
|
||||||
fprintf(stderr, "Process [%s] does not exist in hide list\n", argv[2]);
|
fprintf(stderr, "Process [%s] does not exist in hide list\n", argv[2]);
|
||||||
return code;
|
break;
|
||||||
|
|
||||||
|
/* Errors */
|
||||||
|
case ROOT_REQUIRED:
|
||||||
|
fprintf(stderr, "Root is required for this operation\n");
|
||||||
|
break;
|
||||||
case DAEMON_ERROR:
|
case DAEMON_ERROR:
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Error occured in daemon...\n");
|
fprintf(stderr, "Error occured in daemon...\n");
|
||||||
return code;
|
return DAEMON_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req == LS_HIDELIST) {
|
if (code == DAEMON_SUCCESS && req == LS_HIDELIST) {
|
||||||
int argc = read_int(fd);
|
int cnt = read_int(fd);
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < cnt; ++i) {
|
||||||
char *s = read_string(fd);
|
char *s = read_string(fd);
|
||||||
printf("%s\n", s);
|
printf("%s\n", s);
|
||||||
free(s);
|
free(s);
|
||||||
@ -188,5 +197,5 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return 0;
|
return req == HIDE_STATUS ? (code == HIDE_IS_ENABLED ? 0 : 1) : code != DAEMON_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ void clean_magisk_props();
|
|||||||
int add_list(const char *proc);
|
int add_list(const char *proc);
|
||||||
bool init_list();
|
bool init_list();
|
||||||
|
|
||||||
extern int hide_enabled;
|
extern bool hide_enabled;
|
||||||
extern pthread_mutex_t list_lock;
|
extern pthread_mutex_t list_lock;
|
||||||
extern Vector<CharArray> hide_list;
|
extern Vector<CharArray> hide_list;
|
||||||
|
|
||||||
@ -37,7 +37,8 @@ enum {
|
|||||||
STOP_MAGISKHIDE,
|
STOP_MAGISKHIDE,
|
||||||
ADD_HIDELIST,
|
ADD_HIDELIST,
|
||||||
RM_HIDELIST,
|
RM_HIDELIST,
|
||||||
LS_HIDELIST
|
LS_HIDELIST,
|
||||||
|
HIDE_STATUS,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -29,7 +29,7 @@ extern char *system_block, *vendor_block, *magiskloop;
|
|||||||
static void term_thread(int) {
|
static void term_thread(int) {
|
||||||
LOGD("proc_monitor: running cleanup\n");
|
LOGD("proc_monitor: running cleanup\n");
|
||||||
hide_list.clear(true);
|
hide_list.clear(true);
|
||||||
hide_enabled = 0;
|
hide_enabled = false;
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
sockfd = -1;
|
sockfd = -1;
|
||||||
pthread_mutex_destroy(&list_lock);
|
pthread_mutex_destroy(&list_lock);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user