manager: fix legacy get version
Co-authored-by: weishu <twsxtd@gmail.com> Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// Created by weishu on 2022/12/9.
|
||||
//
|
||||
|
||||
#include <sys/prctl.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -12,8 +11,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "prelude.h"
|
||||
#include "ksu.h"
|
||||
|
||||
@@ -27,34 +24,6 @@ extern const char* zako_file_verrcidx2str(uint8_t index);
|
||||
|
||||
#endif // __aarch64__ || _M_ARM64 || __arm__ || _M_ARM
|
||||
|
||||
#define KERNEL_SU_OPTION 0xDEADBEEF
|
||||
|
||||
#define CMD_GRANT_ROOT 0
|
||||
|
||||
#define CMD_BECOME_MANAGER 1
|
||||
#define CMD_GET_VERSION 2
|
||||
#define CMD_ALLOW_SU 3
|
||||
#define CMD_DENY_SU 4
|
||||
#define CMD_GET_SU_LIST 5
|
||||
#define CMD_GET_DENY_LIST 6
|
||||
#define CMD_CHECK_SAFEMODE 9
|
||||
|
||||
#define CMD_GET_APP_PROFILE 10
|
||||
#define CMD_SET_APP_PROFILE 11
|
||||
|
||||
#define CMD_IS_UID_GRANTED_ROOT 12
|
||||
#define CMD_IS_UID_SHOULD_UMOUNT 13
|
||||
#define CMD_IS_SU_ENABLED 14
|
||||
#define CMD_ENABLE_SU 15
|
||||
|
||||
#define CMD_GET_VERSION_FULL 0xC0FFEE1A
|
||||
|
||||
#define CMD_ENABLE_KPM 100
|
||||
#define CMD_HOOK_TYPE 101
|
||||
#define CMD_DYNAMIC_MANAGER 103
|
||||
#define CMD_GET_MANAGERS 104
|
||||
#define CMD_ENABLE_UID_SCANNER 105
|
||||
|
||||
static int fd = -1;
|
||||
|
||||
static inline int scan_driver_fd() {
|
||||
@@ -107,12 +76,6 @@ static int ksuctl(unsigned long op, void* arg) {
|
||||
return ioctl(fd, op, arg);
|
||||
}
|
||||
|
||||
static bool ksuctl_prctl(int cmd, void* arg1, void* arg2) {
|
||||
int32_t result = 0;
|
||||
int32_t rtn = prctl(KERNEL_SU_OPTION, cmd, arg1, arg2, &result);
|
||||
return result == KERNEL_SU_OPTION && rtn == -1;
|
||||
}
|
||||
|
||||
static struct ksu_get_info_cmd g_version = {0};
|
||||
|
||||
struct ksu_get_info_cmd get_info() {
|
||||
@@ -127,6 +90,14 @@ uint32_t get_version() {
|
||||
return info.version;
|
||||
}
|
||||
|
||||
struct ksu_version_info legacy_get_info()
|
||||
{
|
||||
int32_t version = -1;
|
||||
int32_t flags = 0;
|
||||
ksuctl_prctl(CMD_GET_VERSION, &version, &flags);
|
||||
return (struct ksu_version_info){version, flags};
|
||||
}
|
||||
|
||||
bool get_allow_list(struct ksu_get_allow_list_cmd *cmd) {
|
||||
return ksuctl(KSU_IOCTL_GET_ALLOW_LIST, cmd) == 0;
|
||||
}
|
||||
@@ -138,13 +109,19 @@ bool is_safe_mode() {
|
||||
}
|
||||
|
||||
bool is_lkm_mode() {
|
||||
auto info = get_info();
|
||||
return (info.flags & 0x1) != 0;
|
||||
auto info = get_info();
|
||||
if (info.version > 0) {
|
||||
return (info.flags & 0x1) != 0;
|
||||
}
|
||||
return (legacy_get_info().flags & 0x1) != 0;
|
||||
}
|
||||
|
||||
bool is_manager() {
|
||||
auto info = get_info();
|
||||
return (info.flags & 0x2) != 0;
|
||||
auto info = get_info();
|
||||
if (info.version > 0) {
|
||||
return (info.flags & 0x2) != 0;
|
||||
}
|
||||
return legacy_get_info().version;
|
||||
}
|
||||
|
||||
bool uid_should_umount(int uid) {
|
||||
@@ -220,13 +197,6 @@ bool is_kernel_umount_enabled() {
|
||||
return value != 0;
|
||||
}
|
||||
|
||||
int legacy_get_version() {
|
||||
int32_t version = -1;
|
||||
int32_t flags = 0;
|
||||
ksuctl_prctl(CMD_GET_VERSION, &version, &flags);
|
||||
return version;
|
||||
}
|
||||
|
||||
void get_full_version(char* buff) {
|
||||
struct ksu_get_full_version_cmd cmd = {0};
|
||||
if (ksuctl(KSU_IOCTL_GET_FULL_VERSION, &cmd) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user