2017-04-06 00:12:29 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <pthread.h>
|
2017-04-07 01:50:02 +02:00
|
|
|
#include <signal.h>
|
2017-04-09 01:25:10 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/wait.h>
|
2017-04-07 01:50:02 +02:00
|
|
|
#include <sys/types.h>
|
2016-12-30 19:44:24 +01:00
|
|
|
|
2017-04-06 00:12:29 +02:00
|
|
|
#include "magisk.h"
|
|
|
|
#include "magiskhide.h"
|
2017-04-09 01:25:10 +02:00
|
|
|
#include "daemon.h"
|
2018-10-28 09:25:31 +01:00
|
|
|
#include "flags.h"
|
2016-12-30 19:44:24 +01:00
|
|
|
|
2018-11-16 06:37:41 +01:00
|
|
|
bool hide_enabled = false;
|
2017-01-01 11:54:13 +01:00
|
|
|
|
2018-11-01 19:08:33 +01:00
|
|
|
[[noreturn]] static void usage(char *arg0) {
|
2017-04-09 01:25:10 +02:00
|
|
|
fprintf(stderr,
|
2018-11-16 06:37:41 +01:00
|
|
|
"MagiskHide v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu)\n\n"
|
2018-11-23 21:47:49 +01:00
|
|
|
"Usage: %s [--option [arguments...] ]\n\n"
|
2017-04-09 01:25:10 +02:00
|
|
|
"Options:\n"
|
2018-11-16 06:37:41 +01:00
|
|
|
" --status Return the status of MagiskHide\n"
|
2017-08-14 19:25:54 +02:00
|
|
|
" --enable Start magiskhide\n"
|
|
|
|
" --disable Stop magiskhide\n"
|
2018-11-23 21:47:49 +01:00
|
|
|
" --add TARGET Add TARGET to the hide list\n"
|
|
|
|
" --rm TARGET Remove TARGET from the hide list\n"
|
2017-08-14 19:25:54 +02:00
|
|
|
" --ls Print out the current hide list\n"
|
2018-11-23 21:47:49 +01:00
|
|
|
"\n"
|
|
|
|
"TARGET can be either a package name or a specific component name\n"
|
|
|
|
"If TARGET is a package name, all components of the app will be targeted\n"
|
|
|
|
"A component name is composed of <pkg>/<cls>\n"
|
2017-04-09 01:25:10 +02:00
|
|
|
, arg0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-11-01 19:08:33 +01:00
|
|
|
void magiskhide_handler(int client) {
|
|
|
|
int req = read_int(client);
|
|
|
|
int res = DAEMON_ERROR;
|
|
|
|
|
|
|
|
switch (req) {
|
|
|
|
case STOP_MAGISKHIDE:
|
|
|
|
case ADD_HIDELIST:
|
|
|
|
case RM_HIDELIST:
|
|
|
|
case LS_HIDELIST:
|
|
|
|
if (!hide_enabled) {
|
|
|
|
write_int(client, HIDE_NOT_ENABLED);
|
|
|
|
close(client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (req) {
|
|
|
|
case LAUNCH_MAGISKHIDE:
|
2018-11-13 08:22:55 +01:00
|
|
|
res = launch_magiskhide(client);
|
2018-11-01 19:08:33 +01:00
|
|
|
break;
|
|
|
|
case STOP_MAGISKHIDE:
|
|
|
|
res = stop_magiskhide();
|
|
|
|
break;
|
|
|
|
case ADD_HIDELIST:
|
|
|
|
res = add_list(client);
|
|
|
|
break;
|
|
|
|
case RM_HIDELIST:
|
|
|
|
res = rm_list(client);
|
|
|
|
break;
|
|
|
|
case LS_HIDELIST:
|
|
|
|
ls_list(client);
|
|
|
|
client = -1;
|
|
|
|
break;
|
2018-11-16 06:37:41 +01:00
|
|
|
case HIDE_STATUS:
|
|
|
|
res = hide_enabled ? HIDE_IS_ENABLED : HIDE_NOT_ENABLED;
|
|
|
|
break;
|
2018-11-01 19:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
write_int(client, res);
|
2017-04-14 21:23:09 +02:00
|
|
|
close(client);
|
2017-04-06 00:12:29 +02:00
|
|
|
}
|
2016-12-30 19:44:24 +01:00
|
|
|
|
2017-04-06 00:12:29 +02:00
|
|
|
int magiskhide_main(int argc, char *argv[]) {
|
2018-11-16 06:37:41 +01:00
|
|
|
if (argc < 2)
|
2017-04-09 01:25:10 +02:00
|
|
|
usage(argv[0]);
|
2018-11-16 06:37:41 +01:00
|
|
|
|
2018-11-01 19:08:33 +01:00
|
|
|
int req;
|
2018-11-16 06:37:41 +01:00
|
|
|
if (strcmp(argv[1], "--enable") == 0)
|
2017-04-09 01:25:10 +02:00
|
|
|
req = LAUNCH_MAGISKHIDE;
|
2018-11-16 06:37:41 +01:00
|
|
|
else if (strcmp(argv[1], "--disable") == 0)
|
2017-04-09 01:25:10 +02:00
|
|
|
req = STOP_MAGISKHIDE;
|
2018-11-16 06:37:41 +01:00
|
|
|
else if (strcmp(argv[1], "--add") == 0 && argc > 2)
|
2017-04-09 01:25:10 +02:00
|
|
|
req = ADD_HIDELIST;
|
2018-11-16 06:37:41 +01:00
|
|
|
else if (strcmp(argv[1], "--rm") == 0 && argc > 2)
|
2017-04-09 01:25:10 +02:00
|
|
|
req = RM_HIDELIST;
|
2018-11-16 06:37:41 +01:00
|
|
|
else if (strcmp(argv[1], "--ls") == 0)
|
2017-09-05 20:25:40 +02:00
|
|
|
req = LS_HIDELIST;
|
2018-11-16 06:37:41 +01:00
|
|
|
else if (strcmp(argv[1], "--status") == 0)
|
|
|
|
req = HIDE_STATUS;
|
|
|
|
else
|
2017-10-10 13:49:15 +02:00
|
|
|
usage(argv[0]);
|
2018-11-01 19:08:33 +01:00
|
|
|
|
2018-11-16 06:37:41 +01:00
|
|
|
// Send request
|
2018-06-16 19:28:29 +02:00
|
|
|
int fd = connect_daemon();
|
2018-11-01 19:08:33 +01:00
|
|
|
write_int(fd, MAGISKHIDE);
|
2017-04-09 01:25:10 +02:00
|
|
|
write_int(fd, req);
|
2018-11-16 06:37:41 +01:00
|
|
|
if (req == ADD_HIDELIST || req == RM_HIDELIST)
|
2017-04-09 01:25:10 +02:00
|
|
|
write_string(fd, argv[2]);
|
2018-11-16 07:49:15 +01:00
|
|
|
if (req == LS_HIDELIST)
|
|
|
|
send_fd(fd, STDOUT_FILENO);
|
2018-11-16 06:37:41 +01:00
|
|
|
|
|
|
|
// Get response
|
2018-02-11 10:23:36 +01:00
|
|
|
int code = read_int(fd);
|
2017-04-21 19:40:07 +02:00
|
|
|
switch (code) {
|
2017-05-05 10:13:26 +02:00
|
|
|
case DAEMON_SUCCESS:
|
|
|
|
break;
|
2018-04-07 20:12:40 +02:00
|
|
|
case LOGCAT_DISABLED:
|
|
|
|
fprintf(stderr, "Logcat is disabled, cannot start MagiskHide\n");
|
2018-11-16 06:37:41 +01:00
|
|
|
break;
|
2017-04-21 19:40:07 +02:00
|
|
|
case HIDE_NOT_ENABLED:
|
2018-11-16 06:37:41 +01:00
|
|
|
fprintf(stderr, "MagiskHide is not enabled\n");
|
|
|
|
break;
|
2017-04-21 19:40:07 +02:00
|
|
|
case HIDE_IS_ENABLED:
|
2018-11-16 06:37:41 +01:00
|
|
|
fprintf(stderr, "MagiskHide is enabled\n");
|
|
|
|
break;
|
2017-04-21 19:40:07 +02:00
|
|
|
case HIDE_ITEM_EXIST:
|
2018-11-23 21:47:49 +01:00
|
|
|
fprintf(stderr, "[%s] already exists in hide list\n", argv[2]);
|
2018-11-16 06:37:41 +01:00
|
|
|
break;
|
2017-04-21 19:40:07 +02:00
|
|
|
case HIDE_ITEM_NOT_EXIST:
|
2018-11-23 21:47:49 +01:00
|
|
|
fprintf(stderr, "[%s] does not exist in hide list\n", argv[2]);
|
2018-11-16 06:37:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Errors */
|
|
|
|
case ROOT_REQUIRED:
|
|
|
|
fprintf(stderr, "Root is required for this operation\n");
|
|
|
|
break;
|
2018-02-11 10:23:36 +01:00
|
|
|
case DAEMON_ERROR:
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Error occured in daemon...\n");
|
2018-11-16 06:37:41 +01:00
|
|
|
return DAEMON_ERROR;
|
2017-09-05 20:25:40 +02:00
|
|
|
}
|
|
|
|
|
2018-11-16 06:37:41 +01:00
|
|
|
return req == HIDE_STATUS ? (code == HIDE_IS_ENABLED ? 0 : 1) : code != DAEMON_SUCCESS;
|
2017-04-06 00:12:29 +02:00
|
|
|
}
|