Fix --remove-modules command

This commit is contained in:
topjohnwu
2020-04-30 01:26:50 -07:00
parent 03c1053871
commit 5fd574a14f
5 changed files with 46 additions and 59 deletions

View File

@@ -19,12 +19,9 @@
using namespace std;
extern vector<string> module_list;
static bool no_secure_dir = false;
static bool pfs_done = false;
extern void auto_start_magiskhide();
/*********
* Setup *
*********/
@@ -139,30 +136,13 @@ static bool magisk_env() {
return true;
}
static void reboot() {
void reboot() {
if (RECOVERY_MODE)
exec_command_sync("/system/bin/reboot", "recovery");
else
exec_command_sync("/system/bin/reboot");
}
void remove_modules() {
LOGI("* Remove all modules and reboot");
auto dir = xopen_dir(MODULEROOT);
int dfd = dirfd(dir.get());
for (dirent *entry; (entry = xreaddir(dir.get()));) {
if (entry->d_type == DT_DIR) {
if (entry->d_name == ".core"sv)
continue;
int modfd = xopenat(dfd, entry->d_name, O_RDONLY | O_CLOEXEC);
close(xopenat(modfd, "remove", O_RDONLY | O_CREAT | O_CLOEXEC));
close(modfd);
}
}
reboot();
}
static bool check_data() {
bool mnt = false;
bool data = false;

View File

@@ -56,6 +56,14 @@ static void *request_handler(void *args) {
close(client);
return nullptr;
}
break;
case REMOVE_MODULES:
if (credential.uid != UID_SHELL && credential.uid != UID_ROOT) {
write_int(client, 1);
close(client);
return nullptr;
}
break;
default:
break;
}
@@ -88,12 +96,8 @@ static void *request_handler(void *args) {
exec_sql(client);
break;
case REMOVE_MODULES:
if (credential.uid == UID_SHELL || credential.uid == UID_ROOT) {
remove_modules();
write_int(client, 0);
} else {
write_int(client, 1);
}
remove_modules();
write_int(client, 0);
close(client);
break;
case GET_PATH:

View File

@@ -686,3 +686,23 @@ void handle_modules() {
mount_modules();
}
void remove_modules() {
LOGI("* Remove all modules and reboot\n");
auto dir = open_dir(MODULEROOT);
if (!dir)
return;
int dfd = dirfd(dir.get());
for (dirent *entry; (entry = xreaddir(dir.get()));) {
if (entry->d_type == DT_DIR) {
if (entry->d_name == ".core"sv)
continue;
int modfd = xopenat(dfd, entry->d_name, O_RDONLY | O_CLOEXEC);
close(xopenat(modfd, "remove", O_RDONLY | O_CREAT | O_CLOEXEC, 0));
close(modfd);
}
}
reboot();
}