kernel: Rewrite kernle version code management
Co-authored-by: lamadaemon <i@lama.icu> Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
@@ -21,30 +21,45 @@ obj-$(CONFIG_KPM) += kpm/
|
|||||||
|
|
||||||
REPO_OWNER := SukiSU-Ultra
|
REPO_OWNER := SukiSU-Ultra
|
||||||
REPO_NAME := SukiSU-Ultra
|
REPO_NAME := SukiSU-Ultra
|
||||||
REPO_BRANCH := main
|
KSU_API_VERSION_LOCAL := 3.1.6
|
||||||
|
|
||||||
GIT_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git
|
GIT_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git
|
||||||
CURL_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin curl
|
CURL_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin curl
|
||||||
|
|
||||||
KSU_GITHUB_VERSION := $(shell $(CURL_BIN) -sI "https://api.github.com/repos/$(REPO_OWNER)/$(REPO_NAME)/commits?sha=$(REPO_BRANCH)&per_page=1" | grep -i "link:" | sed -n 's/.*page=\([0-9]*\)>; rel="last".*/\1/p')
|
KSU_GITHUB_VERSION := $(shell $(CURL_BIN) -s "https://api.github.com/repos/$(REPO_OWNER)/$(REPO_NAME)/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
|
||||||
|
|
||||||
|
LOCAL_GIT_EXISTS := $(shell test -e $(srctree)/$(src)/../.git && echo 1 || echo 0)
|
||||||
|
|
||||||
|
define get_ksu_api_version
|
||||||
|
$(shell echo $1 | awk -F'[-.]' '{printf "%d%02d%02d", $$1, $$2, $$3}')
|
||||||
|
endef
|
||||||
|
|
||||||
|
define get_ksu_kernel_version
|
||||||
|
v$1-$(shell cd $(srctree)/$(src); $(GIT_BIN) rev-parse --short=8 HEAD)@$(shell cd $(srctree)/$(src); $(GIT_BIN) rev-parse --abbrev-ref HEAD)
|
||||||
|
endef
|
||||||
|
|
||||||
ifeq ($(KSU_GITHUB_VERSION),)
|
ifeq ($(KSU_GITHUB_VERSION),)
|
||||||
ifeq ($(shell test -e $(srctree)/$(src)/../.git; echo $$?),0)
|
ifeq ($(LOCAL_GIT_EXISTS),1)
|
||||||
$(shell cd $(srctree)/$(src); [ -f ../.git/shallow ] && $(GIT_BIN) fetch --unshallow)
|
$(shell cd $(srctree)/$(src); [ -f ../.git/shallow ] && $(GIT_BIN) fetch --unshallow)
|
||||||
KSU_LOCAL_VERSION := $(shell cd $(srctree)/$(src); $(GIT_BIN) rev-list --count $(REPO_BRANCH))
|
KSU_API_VERSION := $(call get_ksu_api_version,$(KSU_API_VERSION_LOCAL))
|
||||||
$(eval KSU_VERSION := $(shell expr 10000 + $(KSU_LOCAL_VERSION) + 700))
|
KSU_KERNEL_VERSION := $(call get_ksu_kernel_version,$(KSU_API_VERSION_LOCAL))
|
||||||
$(info -- SukiSU-Ultra version (local .git): $(KSU_VERSION))
|
$(info -- $(REPO_NAME) version (local .git): $(KSU_KERNEL_VERSION))
|
||||||
|
$(info -- $(REPO_NAME) Formatted version (local .git): $(KSU_API_VERSION))
|
||||||
else
|
else
|
||||||
$(eval KSU_VERSION := 13000)
|
KSU_KERNEL_VERSION := v$(KSU_API_VERSION_LOCAL)-$(REPO_NAME)-unknown@unknown
|
||||||
$(warning -- Could not fetch version online or via local .git! Using fallback version: $(KSU_VERSION))
|
KSU_API_VERSION := $(call get_ksu_api_version,$(KSU_API_VERSION_LOCAL))
|
||||||
|
$(warning -- $(REPO_NAME) version: $(KSU_KERNEL_VERSION))
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
$(eval KSU_VERSION := $(shell expr 10000 + $(KSU_GITHUB_VERSION) + 700))
|
$(shell cd $(srctree)/$(src); [ -f ../.git/shallow ] && $(GIT_BIN) fetch --unshallow)
|
||||||
$(info -- SukiSU-Ultra version (GitHub): $(KSU_VERSION))
|
KSU_API_VERSION := $(call get_ksu_api_version,$(KSU_GITHUB_VERSION))
|
||||||
|
KSU_KERNEL_VERSION := $(call get_ksu_kernel_version,$(KSU_GITHUB_VERSION))
|
||||||
|
$(info -- $(REPO_NAME) version (Github): $(KSU_KERNEL_VERSION))
|
||||||
|
$(info -- $(REPO_NAME) Formatted version (Github): $(KSU_API_VERSION))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(info -- SukiSU-Ultra version: $(KSU_VERSION))
|
ccflags-y += -DKSU_VERSION=\"$(KSU_KERNEL_VERSION)\"
|
||||||
ccflags-y += -DKSU_VERSION=$(KSU_VERSION)
|
ccflags-y += -DKSU_API_VERSION=$(KSU_API_VERSION)
|
||||||
|
|
||||||
ifeq ($(strip $(CONFIG_KSU_MANUAL_HOOK)),y)
|
ifeq ($(strip $(CONFIG_KSU_MANUAL_HOOK)),y)
|
||||||
$(info -- SukiSU: Manual hooking enabled!)
|
$(info -- SukiSU: Manual hooking enabled!)
|
||||||
|
|||||||
@@ -55,6 +55,8 @@
|
|||||||
#include "kpm/kpm.h"
|
#include "kpm/kpm.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char ksu_version_id[KSU_MAX_VERSION_NAME] = KSU_VERSION;
|
||||||
|
|
||||||
#ifdef CONFIG_KSU_SUSFS
|
#ifdef CONFIG_KSU_SUSFS
|
||||||
bool susfs_is_allow_su(void)
|
bool susfs_is_allow_su(void)
|
||||||
{
|
{
|
||||||
@@ -397,7 +399,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
|
|||||||
if (copy_to_user(arg3, &version, sizeof(version))) {
|
if (copy_to_user(arg3, &version, sizeof(version))) {
|
||||||
pr_err("prctl reply error, cmd: %lu\n", arg2);
|
pr_err("prctl reply error, cmd: %lu\n", arg2);
|
||||||
}
|
}
|
||||||
u32 version_flags = 0;
|
u32 version_flags = 2;
|
||||||
#ifdef MODULE
|
#ifdef MODULE
|
||||||
version_flags |= 0x1;
|
version_flags |= 0x1;
|
||||||
#endif
|
#endif
|
||||||
@@ -510,6 +512,14 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg2 == CMD_GET_FULL_VERSION) {
|
||||||
|
if (copy_to_user(arg3, &ksu_version_id, KSU_MAX_VERSION_NAME)) {
|
||||||
|
pr_err("prctl reply error, cmd: %lu\n", arg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_KPM
|
#ifdef CONFIG_KPM
|
||||||
// ADD: 添加KPM模块控制
|
// ADD: 添加KPM模块控制
|
||||||
if(sukisu_is_kpm_control_code(arg2)) {
|
if(sukisu_is_kpm_control_code(arg2)) {
|
||||||
|
|||||||
11
kernel/ksu.h
11
kernel/ksu.h
@@ -4,7 +4,7 @@
|
|||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/workqueue.h>
|
#include <linux/workqueue.h>
|
||||||
|
|
||||||
#define KERNEL_SU_VERSION KSU_VERSION
|
#define KERNEL_SU_VERSION KSU_API_VERSION
|
||||||
#define KERNEL_SU_OPTION 0xDEADBEEF
|
#define KERNEL_SU_OPTION 0xDEADBEEF
|
||||||
|
|
||||||
#define CMD_GRANT_ROOT 0
|
#define CMD_GRANT_ROOT 0
|
||||||
@@ -23,6 +23,9 @@
|
|||||||
#define CMD_UID_SHOULD_UMOUNT 13
|
#define CMD_UID_SHOULD_UMOUNT 13
|
||||||
#define CMD_IS_SU_ENABLED 14
|
#define CMD_IS_SU_ENABLED 14
|
||||||
#define CMD_ENABLE_SU 15
|
#define CMD_ENABLE_SU 15
|
||||||
|
|
||||||
|
#define CMD_GET_FULL_VERSION 30
|
||||||
|
|
||||||
#define CMD_ENABLE_KPM 100
|
#define CMD_ENABLE_KPM 100
|
||||||
#define CMD_HOOK_TYPE 101
|
#define CMD_HOOK_TYPE 101
|
||||||
#define CMD_GET_SUSFS_FEATURE_STATUS 102
|
#define CMD_GET_SUSFS_FEATURE_STATUS 102
|
||||||
@@ -37,6 +40,12 @@
|
|||||||
#define KSU_MAX_GROUPS 32
|
#define KSU_MAX_GROUPS 32
|
||||||
#define KSU_SELINUX_DOMAIN 64
|
#define KSU_SELINUX_DOMAIN 64
|
||||||
|
|
||||||
|
#define KSU_MAX_VERSION_NAME 255
|
||||||
|
|
||||||
|
#ifndef KSU_VERSION
|
||||||
|
#define KSU_VERSION "v0-unknown-00000000@unkown"
|
||||||
|
#endif
|
||||||
|
|
||||||
// SUSFS Functional State Structures
|
// SUSFS Functional State Structures
|
||||||
struct susfs_feature_status {
|
struct susfs_feature_status {
|
||||||
bool status_sus_path;
|
bool status_sus_path;
|
||||||
|
|||||||
Reference in New Issue
Block a user