mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Fix --remove-modules command
This commit is contained in:
parent
03c1053871
commit
5fd574a14f
@ -19,12 +19,9 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
extern vector<string> module_list;
|
|
||||||
static bool no_secure_dir = false;
|
static bool no_secure_dir = false;
|
||||||
static bool pfs_done = false;
|
static bool pfs_done = false;
|
||||||
|
|
||||||
extern void auto_start_magiskhide();
|
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
* Setup *
|
* Setup *
|
||||||
*********/
|
*********/
|
||||||
@ -139,30 +136,13 @@ static bool magisk_env() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reboot() {
|
void reboot() {
|
||||||
if (RECOVERY_MODE)
|
if (RECOVERY_MODE)
|
||||||
exec_command_sync("/system/bin/reboot", "recovery");
|
exec_command_sync("/system/bin/reboot", "recovery");
|
||||||
else
|
else
|
||||||
exec_command_sync("/system/bin/reboot");
|
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() {
|
static bool check_data() {
|
||||||
bool mnt = false;
|
bool mnt = false;
|
||||||
bool data = false;
|
bool data = false;
|
||||||
|
@ -56,6 +56,14 @@ static void *request_handler(void *args) {
|
|||||||
close(client);
|
close(client);
|
||||||
return nullptr;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -88,12 +96,8 @@ static void *request_handler(void *args) {
|
|||||||
exec_sql(client);
|
exec_sql(client);
|
||||||
break;
|
break;
|
||||||
case REMOVE_MODULES:
|
case REMOVE_MODULES:
|
||||||
if (credential.uid == UID_SHELL || credential.uid == UID_ROOT) {
|
remove_modules();
|
||||||
remove_modules();
|
write_int(client, 0);
|
||||||
write_int(client, 0);
|
|
||||||
} else {
|
|
||||||
write_int(client, 1);
|
|
||||||
}
|
|
||||||
close(client);
|
close(client);
|
||||||
break;
|
break;
|
||||||
case GET_PATH:
|
case GET_PATH:
|
||||||
|
@ -686,3 +686,23 @@ void handle_modules() {
|
|||||||
|
|
||||||
mount_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();
|
||||||
|
}
|
||||||
|
@ -29,46 +29,28 @@ enum {
|
|||||||
DAEMON_LAST
|
DAEMON_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
// daemon.cpp
|
extern int SDK_INT;
|
||||||
|
extern bool RECOVERY_MODE;
|
||||||
|
extern std::vector<std::string> module_list;
|
||||||
|
#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user")
|
||||||
|
|
||||||
int connect_daemon(bool create = false);
|
// Daemon handlers
|
||||||
|
|
||||||
/***************
|
|
||||||
* Boot Stages *
|
|
||||||
***************/
|
|
||||||
|
|
||||||
void unlock_blocks();
|
|
||||||
void post_fs_data(int client);
|
void post_fs_data(int client);
|
||||||
void late_start(int client);
|
void late_start(int client);
|
||||||
void boot_complete(int client);
|
void boot_complete(int client);
|
||||||
void handle_modules();
|
void magiskhide_handler(int client);
|
||||||
|
void su_daemon_handler(int client, struct ucred *credential);
|
||||||
void remove_modules();
|
void remove_modules();
|
||||||
|
|
||||||
/*************
|
// Misc
|
||||||
* Scripting *
|
int connect_daemon(bool create = false);
|
||||||
*************/
|
void auto_start_magiskhide();
|
||||||
|
void unlock_blocks();
|
||||||
|
void handle_modules();
|
||||||
|
void reboot();
|
||||||
|
|
||||||
|
// Scripting
|
||||||
void exec_script(const char *script);
|
void exec_script(const char *script);
|
||||||
void exec_common_script(const char *stage);
|
void exec_common_script(const char *stage);
|
||||||
void exec_module_script(const char *stage, const std::vector<std::string> &module_list);
|
void exec_module_script(const char *stage, const std::vector<std::string> &module_list);
|
||||||
void install_apk(const char *apk);
|
void install_apk(const char *apk);
|
||||||
|
|
||||||
/**************
|
|
||||||
* MagiskHide *
|
|
||||||
**************/
|
|
||||||
|
|
||||||
void magiskhide_handler(int client);
|
|
||||||
|
|
||||||
/*************
|
|
||||||
* Superuser *
|
|
||||||
*************/
|
|
||||||
|
|
||||||
void su_daemon_handler(int client, struct ucred *credential);
|
|
||||||
|
|
||||||
/*********************
|
|
||||||
* Daemon Global Vars
|
|
||||||
*********************/
|
|
||||||
|
|
||||||
extern int SDK_INT;
|
|
||||||
extern bool RECOVERY_MODE;
|
|
||||||
#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user")
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <magisk.hpp>
|
#include <magisk.hpp>
|
||||||
#include <utils.hpp>
|
#include <utils.hpp>
|
||||||
#include <db.hpp>
|
#include <db.hpp>
|
||||||
|
#include <daemon.hpp>
|
||||||
|
|
||||||
#include "magiskhide.hpp"
|
#include "magiskhide.hpp"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user