add: Magisk support; fix: (some) zygiskd code issues

This commit adds Magisk support to Zygiskd C99, and also fixes some code issues of it.
This commit is contained in:
ThePedroo
2024-08-20 19:16:12 -03:00
parent c1e45e9af6
commit a549f0e5ae
14 changed files with 520 additions and 126 deletions

View File

@@ -1,7 +1,11 @@
#include <stdio.h>
#include <sys/types.h>
#include "../utils.h"
#include "kernelsu.h"
#include "apatch.h"
#include "magisk.h"
#include "common.h"
@@ -10,7 +14,36 @@ static enum RootImpl ROOT_IMPL = None;
void root_impls_setup(void) {
if (ksu_get_existence() == Supported) ROOT_IMPL = KernelSU;
else if (apatch_get_existence() == Supported) ROOT_IMPL = APatch;
else if (magisk_get_existence() == Supported) ROOT_IMPL = Magisk;
else ROOT_IMPL = None;
switch (ROOT_IMPL) {
case None: {
LOGI("No root implementation found.\n");
break;
}
case Multiple: {
LOGI("Multiple root implementations found.\n");
break;
}
case KernelSU: {
LOGI("KernelSU root implementation found.\n");
break;
}
case APatch: {
LOGI("APatch root implementation found.\n");
break;
}
case Magisk: {
LOGI("Magisk root implementation found.\n");
break;
}
}
}
enum RootImpl get_impl(void) {
@@ -18,43 +51,52 @@ enum RootImpl get_impl(void) {
}
bool uid_granted_root(uid_t uid) {
// switch (get_impl()) {
// case KernelSU: {
switch (get_impl()) {
case KernelSU: {
return ksu_uid_granted_root(uid);
// }
// case APatch: {
// return apatch_uid_granted_root(uid);
// }
// default: {
// return false;
// }
// }
}
case APatch: {
return apatch_uid_granted_root(uid);
}
case Magisk: {
return magisk_uid_granted_root(uid);
}
default: {
return false;
}
}
}
bool uid_should_umount(uid_t uid) {
// switch (get_impl()) {
// case KernelSU: {
switch (get_impl()) {
case KernelSU: {
return ksu_uid_should_umount(uid);
// }
// case APatch: {
// return apatch_uid_should_umount(uid);
// }
// default: {
// return false;
// }
// }
}
case APatch: {
return apatch_uid_should_umount(uid);
}
case Magisk: {
return magisk_uid_should_umount(uid);
}
default: {
return false;
}
}
}
bool uid_is_manager(uid_t uid) {
// switch (get_impl()) {
// case KernelSU: {
switch (get_impl()) {
case KernelSU: {
return ksu_uid_is_manager(uid);
// }
// case APatch: {
// return apatch_uid_is_manager(uid);
// }
// default: {
// return false;
// }
// }
}
case APatch: {
return apatch_uid_is_manager(uid);
}
case Magisk: {
return magisk_uid_is_manager(uid);
}
default: {
return false;
}
}
}