mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 13:35:27 +00:00
Use wrapper script on system with APEX
Thanks to moving libandroidicu.so to APEX runtime linker namespace, we need a wrapper to link against libsqlite.so on Q
This commit is contained in:
parent
0c7a95bdf6
commit
a385e5cd92
@ -8,17 +8,19 @@
|
||||
#include <selinux.h>
|
||||
#include <utils.h>
|
||||
|
||||
static int (*applet_main[]) (int, char *[]) =
|
||||
{ magisk_main, su_client_main, resetprop_main, magiskhide_main, nullptr };
|
||||
using namespace std::literals;
|
||||
|
||||
[[noreturn]] static void call_applets(int argc, char *argv[]) {
|
||||
static int (*applet_main[]) (int, char *[]) =
|
||||
{ su_client_main, resetprop_main, magiskhide_main, nullptr };
|
||||
|
||||
[[noreturn]] static void call_applet(int argc, char **argv) {
|
||||
// Applets
|
||||
for (int i = 0; applet_names[i]; ++i) {
|
||||
if (strcmp(basename(argv[0]), applet_names[i]) == 0) {
|
||||
exit((*applet_main[i])(argc, argv));
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "%s: applet not found\n", argv[0]);
|
||||
fprintf(stderr, "%s: applet not found\n", basename(argv[0]));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -28,11 +30,24 @@ int main(int argc, char *argv[]) {
|
||||
cmdline_logging();
|
||||
init_argv0(argc, argv);
|
||||
|
||||
if ((strcmp(basename(argv[0]), "magisk") == 0 && argc > 1 && argv[1][0] != '-')) {
|
||||
if (basename(argv[0]) == "magisk.bin"sv) {
|
||||
if (argc == 1)
|
||||
return 1;
|
||||
// Running through wrapper
|
||||
--argc;
|
||||
++argv;
|
||||
}
|
||||
|
||||
call_applets(argc, argv);
|
||||
if (basename(argv[0]) == "magisk"sv) {
|
||||
if (argc > 1 && argv[1][0] != '-') {
|
||||
// Calling applet via magisk [applet] args
|
||||
--argc;
|
||||
++argv;
|
||||
} else {
|
||||
return magisk_main(argc, argv);
|
||||
}
|
||||
}
|
||||
|
||||
call_applet(argc, argv);
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,10 @@
|
||||
#include "binaries.h"
|
||||
#ifdef USE_64BIT
|
||||
#include "binaries_arch64.h"
|
||||
#define LIBNAME "lib64"
|
||||
#else
|
||||
#include "binaries_arch.h"
|
||||
#define LIBNAME "lib"
|
||||
#endif
|
||||
#include "magiskrc.h"
|
||||
|
||||
@ -560,6 +562,11 @@ static inline void patch_socket_name(const char *path) {
|
||||
munmap(buf, size);
|
||||
}
|
||||
|
||||
static const char wrapper[] =
|
||||
"#!/system/bin/sh\n"
|
||||
"export LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH:/apex/com.android.runtime/" LIBNAME "\"\n"
|
||||
"exec /sbin/magisk.bin \"$0\" \"$@\"\n";
|
||||
|
||||
void MagiskInit::setup_overlay() {
|
||||
char path[128];
|
||||
int fd;
|
||||
@ -583,8 +590,17 @@ void MagiskInit::setup_overlay() {
|
||||
fd = xopen("/sbin/magiskinit", O_WRONLY | O_CREAT, 0755);
|
||||
write(fd, self.buf, self.sz);
|
||||
close(fd);
|
||||
if (access("/system/apex", F_OK) == 0) {
|
||||
dump_magisk("/sbin/magisk.bin", 0755);
|
||||
patch_socket_name("/sbin/magisk.bin");
|
||||
setfilecon("/sbin/magisk.bin", "u:object_r:" SEPOL_FILE_DOMAIN ":s0");
|
||||
fd = xopen("/sbin/magisk", O_WRONLY | O_CREAT, 0755);
|
||||
write(fd, wrapper, sizeof(wrapper) - 1);
|
||||
close(fd);
|
||||
} else {
|
||||
dump_magisk("/sbin/magisk", 0755);
|
||||
patch_socket_name("/sbin/magisk");
|
||||
}
|
||||
setfilecon("/sbin/magisk", "u:object_r:" SEPOL_FILE_DOMAIN ":s0");
|
||||
setfilecon("/sbin/magiskinit", "u:object_r:" SEPOL_FILE_DOMAIN ":s0");
|
||||
|
||||
|
@ -19,14 +19,13 @@
|
||||
#define MODULEUPGRADE SECURE_DIR "/modules_update"
|
||||
#define DATABIN SECURE_DIR "/magisk"
|
||||
#define MAGISKDB SECURE_DIR "/magisk.db"
|
||||
#define SIMPLEMOUNT SECURE_DIR "/magisk_simple"
|
||||
#define BOOTCOUNT SECURE_DIR "/.boot_count"
|
||||
#define MANAGERAPK DATABIN "/magisk.apk"
|
||||
|
||||
// Legacy crap
|
||||
#define LEGACYCORE MODULEROOT "/.core"
|
||||
|
||||
constexpr const char *applet_names[] = { "magisk", "su", "resetprop", "magiskhide", nullptr };
|
||||
constexpr const char *applet_names[] = { "su", "resetprop", "magiskhide", nullptr };
|
||||
|
||||
// Multi-call entrypoints
|
||||
int magisk_main(int argc, char *argv[]);
|
||||
|
Loading…
Reference in New Issue
Block a user