From 696c3059b69f13507f932f10a5aea2b1da017412 Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Mon, 3 Nov 2025 12:09:00 +0800 Subject: [PATCH] manager: fix legacy get version Co-authored-by: weishu Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> --- manager/app/src/main/cpp/jni.c | 2 +- manager/app/src/main/cpp/ksu.c | 66 +++++-------------- manager/app/src/main/cpp/ksu.h | 47 ++++++++++++- .../com/sukisu/ultra/ui/screen/Settings.kt | 1 - 4 files changed, 63 insertions(+), 53 deletions(-) diff --git a/manager/app/src/main/cpp/jni.c b/manager/app/src/main/cpp/jni.c index b1c5ab18..b879b4e0 100644 --- a/manager/app/src/main/cpp/jni.c +++ b/manager/app/src/main/cpp/jni.c @@ -13,7 +13,7 @@ NativeBridgeNP(getVersion, jint) { return (jint)version; } // try legacy method as fallback - return legacy_get_version(); + return legacy_get_info().version; } // get VERSION FULL diff --git a/manager/app/src/main/cpp/ksu.c b/manager/app/src/main/cpp/ksu.c index 597fffa7..ec7df527 100644 --- a/manager/app/src/main/cpp/ksu.c +++ b/manager/app/src/main/cpp/ksu.c @@ -2,7 +2,6 @@ // Created by weishu on 2022/12/9. // -#include #include #include #include @@ -12,8 +11,6 @@ #include #include -#include - #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) { diff --git a/manager/app/src/main/cpp/ksu.h b/manager/app/src/main/cpp/ksu.h index 4e692271..9c2c360d 100644 --- a/manager/app/src/main/cpp/ksu.h +++ b/manager/app/src/main/cpp/ksu.h @@ -9,13 +9,47 @@ #include #include #include +#include +#include + +#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 inline 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; +} #define KSU_FULL_VERSION_STRING 255 uint32_t get_version(); -int legacy_get_version(void); - bool uid_should_umount(int uid); bool is_safe_mode(); @@ -260,6 +294,13 @@ struct ksu_enable_uid_scanner_cmd { #define KSU_IOCTL_GET_MANAGERS _IOC(_IOC_READ|_IOC_WRITE, 'K', 104, 0) #define KSU_IOCTL_ENABLE_UID_SCANNER _IOC(_IOC_READ|_IOC_WRITE, 'K', 105, 0) -bool get_allow_list(struct ksu_get_allow_list_cmd*); +bool get_allow_list(struct ksu_get_allow_list_cmd *); + +struct ksu_version_info legacy_get_info(); + +struct ksu_version_info { + int32_t version; + int32_t flags; +}; #endif //KERNELSU_KSU_H \ No newline at end of file diff --git a/manager/app/src/main/java/com/sukisu/ultra/ui/screen/Settings.kt b/manager/app/src/main/java/com/sukisu/ultra/ui/screen/Settings.kt index e3020c9b..4aa55c1c 100644 --- a/manager/app/src/main/java/com/sukisu/ultra/ui/screen/Settings.kt +++ b/manager/app/src/main/java/com/sukisu/ultra/ui/screen/Settings.kt @@ -52,7 +52,6 @@ import com.sukisu.ultra.ui.theme.getCardElevation import com.sukisu.ultra.ui.util.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.time.LocalDateTime