add legacy get_version & Full get_version

Co-authored-by: Ylarod <me@ylarod.cn>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
Ylarod
2025-11-03 08:31:25 +08:00
committed by ShirkNeko
parent 59339b806a
commit bfed2d700a
3 changed files with 55 additions and 6 deletions

View File

@@ -9,11 +9,12 @@
NativeBridgeNP(getVersion, jint) { NativeBridgeNP(getVersion, jint) {
uint32_t version = get_version(); uint32_t version = get_version();
if (version > INT32_MAX) { if (version > 0) {
LogDebug("Version overflow: %u", version);
}
return (jint)version; return (jint)version;
} }
// try legacy method as fallback
return legacy_get_version();
}
// get VERSION FULL // get VERSION FULL
NativeBridgeNP(getFullVersion, jstring) { NativeBridgeNP(getFullVersion, jstring) {

View File

@@ -27,6 +27,34 @@ extern const char* zako_file_verrcidx2str(uint8_t index);
#endif // __aarch64__ || _M_ARM64 || __arm__ || _M_ARM #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 int fd = -1;
static inline int scan_driver_fd() { static inline int scan_driver_fd() {
@@ -79,6 +107,12 @@ static int ksuctl(unsigned long op, void* arg) {
return ioctl(fd, op, 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}; static struct ksu_get_info_cmd g_version = {0};
struct ksu_get_info_cmd get_info() { struct ksu_get_info_cmd get_info() {
@@ -186,16 +220,27 @@ bool is_kernel_umount_enabled() {
return value != 0; 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) { void get_full_version(char* buff) {
struct ksu_get_full_version_cmd cmd = {0}; struct ksu_get_full_version_cmd cmd = {0};
if (ksuctl(KSU_IOCTL_GET_FULL_VERSION, &cmd) == 0) { if (ksuctl(KSU_IOCTL_GET_FULL_VERSION, &cmd) == 0) {
strncpy(buff, cmd.version_full, KSU_FULL_VERSION_STRING - 1); strncpy(buff, cmd.version_full, KSU_FULL_VERSION_STRING - 1);
buff[KSU_FULL_VERSION_STRING - 1] = '\0'; buff[KSU_FULL_VERSION_STRING - 1] = '\0';
} else { } else {
buff[0] = '\0'; return legacy_get_full_version(buff);
} }
} }
void legacy_get_full_version(char* buff) {
ksuctl_prctl(CMD_GET_VERSION_FULL, buff, NULL);
}
bool is_KPM_enable(void) bool is_KPM_enable(void)
{ {
struct ksu_enable_kpm_cmd cmd = {}; struct ksu_enable_kpm_cmd cmd = {};

View File

@@ -14,6 +14,8 @@
uint32_t get_version(); uint32_t get_version();
int legacy_get_version(void);
bool uid_should_umount(int uid); bool uid_should_umount(int uid);
bool is_safe_mode(); bool is_safe_mode();
@@ -23,6 +25,7 @@ bool is_lkm_mode();
bool is_manager(); bool is_manager();
void get_full_version(char* buff); void get_full_version(char* buff);
void legacy_get_full_version(char* buff);
#define KSU_APP_PROFILE_VER 2 #define KSU_APP_PROFILE_VER 2
#define KSU_MAX_PACKAGE_NAME 256 #define KSU_MAX_PACKAGE_NAME 256