You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
add: base for C99 zygiskd
This commit adds the first base for C99 zygiskd, that is not fully working or code-ready.
This commit is contained in:
54
zygiskd-new/root_impl/common.c
Normal file
54
zygiskd-new/root_impl/common.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "kernelsu.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static enum RootImpl ROOT_IMPL = None;
|
||||
|
||||
void root_impls_setup(void) {
|
||||
enum RootImplState ksu_version = ksu_get_kernel_su();
|
||||
|
||||
enum RootImpl impl = None;
|
||||
|
||||
if (ksu_version == Supported) impl = KernelSU;
|
||||
|
||||
ROOT_IMPL = impl;
|
||||
}
|
||||
|
||||
enum RootImpl get_impl(void) {
|
||||
return ROOT_IMPL;
|
||||
}
|
||||
|
||||
bool uid_granted_root(uid_t uid) {
|
||||
switch (get_impl()) {
|
||||
case KernelSU: {
|
||||
return ksu_uid_granted_root(uid);
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool uid_should_umount(uid_t uid) {
|
||||
switch (get_impl()) {
|
||||
case KernelSU: {
|
||||
return ksu_uid_should_umount(uid);
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool uid_is_manager(uid_t uid) {
|
||||
switch (get_impl()) {
|
||||
case KernelSU: {
|
||||
return ksu_uid_is_manager(uid);
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
zygiskd-new/root_impl/common.h
Normal file
22
zygiskd-new/root_impl/common.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include "../constants.h"
|
||||
|
||||
enum RootImpl {
|
||||
None,
|
||||
Multiple, /* INFO: I know. */
|
||||
KernelSU
|
||||
};
|
||||
|
||||
void root_impls_setup(void);
|
||||
|
||||
enum RootImpl get_impl(void);
|
||||
|
||||
bool uid_granted_root(uid_t uid);
|
||||
|
||||
bool uid_should_umount(uid_t uid);
|
||||
|
||||
bool uid_is_manager(uid_t uid);
|
||||
|
||||
#endif /* COMMON_H */
|
||||
68
zygiskd-new/root_impl/kernelsu.c
Normal file
68
zygiskd-new/root_impl/kernelsu.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../constants.h"
|
||||
#include "../utils.h"
|
||||
|
||||
#include "kernelsu.h"
|
||||
|
||||
#define KERNEL_SU_OPTION 0xdeadbeef
|
||||
|
||||
#define CMD_GET_VERSION 2
|
||||
#define CMD_UID_GRANTED_ROOT 12
|
||||
#define CMD_UID_SHOULD_UMOUNT 13
|
||||
|
||||
enum RootImplState ksu_get_kernel_su(void) {
|
||||
int version = 0;
|
||||
prctl(KERNEL_SU_OPTION, CMD_GET_VERSION, &version, 0, 0);
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (version == 0) return Abnormal;
|
||||
|
||||
if (version >= MIN_KSU_VERSION && version <= MAX_KSU_VERSION) return Supported;
|
||||
|
||||
if (version >= 1 && version <= MIN_KSU_VERSION - 1) return TooOld;
|
||||
|
||||
return Abnormal;
|
||||
}
|
||||
|
||||
bool ksu_uid_granted_root(uid_t uid) {
|
||||
uint32_t result = 0;
|
||||
bool granted = false;
|
||||
prctl(KERNEL_SU_OPTION, CMD_UID_GRANTED_ROOT, uid, &granted, &result);
|
||||
|
||||
LOGI("ksu_uid_granted_root: %d", granted);
|
||||
|
||||
if (result != KERNEL_SU_OPTION) return false;
|
||||
|
||||
return granted;
|
||||
}
|
||||
|
||||
bool ksu_uid_should_umount(uid_t uid) {
|
||||
uint32_t result = 0;
|
||||
bool umount = false;
|
||||
prctl(KERNEL_SU_OPTION, CMD_UID_SHOULD_UMOUNT, uid, &umount, &result);
|
||||
|
||||
LOGI("ksu_uid_should_umount: %d", umount);
|
||||
|
||||
if (result != KERNEL_SU_OPTION) return false;
|
||||
|
||||
return umount;
|
||||
}
|
||||
|
||||
bool ksu_uid_is_manager(uid_t uid) {
|
||||
|
||||
struct stat s;
|
||||
if (stat("/data/user_de/0/me.weishu.kernelsu", &s) == 0) {
|
||||
LOGI("ksu_uid_is_manager: %d", uid);
|
||||
|
||||
return s.st_uid == uid;
|
||||
}
|
||||
|
||||
LOGI("ksu_uid_is_manager: false");
|
||||
|
||||
return false;
|
||||
}
|
||||
14
zygiskd-new/root_impl/kernelsu.h
Normal file
14
zygiskd-new/root_impl/kernelsu.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef KERNELSU_H
|
||||
#define KERNELSU_H
|
||||
|
||||
#include "../constants.h"
|
||||
|
||||
enum RootImplState ksu_get_kernel_su(void);
|
||||
|
||||
bool ksu_uid_granted_root(uid_t uid);
|
||||
|
||||
bool ksu_uid_should_umount(uid_t uid);
|
||||
|
||||
bool ksu_uid_is_manager(uid_t uid);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user