mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-22 20:20:08 +00:00
@@ -92,3 +92,40 @@ void install_apk(const char *apk) {
|
||||
sprintf(cmds, install_script, apk);
|
||||
exec_command_sync(exec, BBEXEC_CMD, "-c", cmds);
|
||||
}
|
||||
|
||||
[[noreturn]] static void abort(const char *msg) {
|
||||
fprintf(stderr, "%s\n\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
constexpr char install_module_script[] = R"EOF(
|
||||
. /data/adb/magisk/util_functions.sh
|
||||
install_module
|
||||
exit 0
|
||||
)EOF";
|
||||
|
||||
void install_module(const char *file) {
|
||||
if (getuid() != 0)
|
||||
abort("Run this command with root");
|
||||
if (access(DATABIN, F_OK) ||
|
||||
access(DATABIN "/busybox", X_OK) ||
|
||||
access(DATABIN "/util_functions.sh", F_OK))
|
||||
abort("Incomplete Magisk install");
|
||||
if (access(file, F_OK)) {
|
||||
char msg[4096];
|
||||
sprintf(msg, "'%s' does not exist", file);
|
||||
abort(msg);
|
||||
}
|
||||
|
||||
setenv("OUTFD", "1", true);
|
||||
setenv("ZIPFILE", file, true);
|
||||
setenv("ASH_STANDALONE", "1", 1);
|
||||
|
||||
int fd = xopen("/dev/null", O_RDONLY);
|
||||
xdup2(fd, STDERR_FILENO);
|
||||
close(fd);
|
||||
|
||||
const char *argv[] = { BBEXEC_CMD, "-c", install_module_script };
|
||||
execve(argv[0], (char **) argv, environ);
|
||||
abort("Failed to execute BusyBox shell");
|
||||
}
|
||||
|
Reference in New Issue
Block a user