mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-16 16:51:23 +00:00
Fix --remove-modules command
This commit is contained in:
@@ -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;
|
||||
|
@@ -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:
|
||||
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user