From 2e711c3ac9d6710f2dad6e76d8db0a9744a42dc4 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 15:13:13 +0800 Subject: [PATCH 01/21] 3 --- kernel/kpm/kpm.c | 12 +++++++----- kernel/kpm/kpm.h | 29 ++++++++++------------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index bc5530e9..da5f517f 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -71,10 +71,12 @@ int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { return -1; } -void sukisu_kpm_print_list(void) { +int sukisu_kpm_control(void __user* name, void __user* args) { + return -1; } -void sukisu_kpm_vesion(void) { +int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { + return -1; } EXPORT_SYMBOL(sukisu_kpm_load_module_path); @@ -82,8 +84,8 @@ EXPORT_SYMBOL(sukisu_kpm_unload_module); EXPORT_SYMBOL(sukisu_kpm_num); EXPORT_SYMBOL(sukisu_kpm_info); EXPORT_SYMBOL(sukisu_kpm_list); -EXPORT_SYMBOL(sukisu_kpm_print_list); EXPORT_SYMBOL(sukisu_kpm_version); +EXPORT_SYMBOL(sukisu_kpm_control); int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5) @@ -123,8 +125,8 @@ int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5 return sukisu_kpm_info((const char*) &kernel_name_buffer, (char __user*) arg5); } else if(arg3 == SUKISU_KPM_LIST) { return sukisu_kpm_list((char __user*) arg4, (unsigned int) arg5); - } else if(arg3 == SUKISU_KPM_PRINT) { - sukisu_kpm_print_list(); + } else if(arg3 == SUKISU_KPM_VERSION) { + return sukisu_kpm_version((char __user*) arg4, (unsigned int) arg5); } return 0; } diff --git a/kernel/kpm/kpm.h b/kernel/kpm/kpm.h index 0f558683..83145f97 100644 --- a/kernel/kpm/kpm.h +++ b/kernel/kpm/kpm.h @@ -10,44 +10,35 @@ int sukisu_is_kpm_control_code(unsigned long arg2); // 控制代码 -// prctl(xxx, xxx, 1, "PATH", "ARGS") +// prctl(xxx, 28, "PATH", "ARGS") // success return 0, error return -N #define SUKISU_KPM_LOAD 28 -// prctl(xxx, xxx, 2, "NAME") +// prctl(xxx, 29, "NAME") // success return 0, error return -N #define SUKISU_KPM_UNLOAD 29 -// num = prctl(xxx, xxx, 3) +// num = prctl(xxx, 30) // error return -N // success return +num or 0 #define SUKISU_KPM_NUM 30 -// prctl(xxx, xxx, 4, Buffer, BufferSize) +// prctl(xxx, 31, Buffer, BufferSize) // success return +out, error return -N #define SUKISU_KPM_LIST 31 -// prctl(xxx, xxx, 5, "NAME", Buffer[256]) +// prctl(xxx, 32, "NAME", Buffer[256]) // success return +out, error return -N #define SUKISU_KPM_INFO 32 -// prctl(xxx, xxx, 6, "NAME", "ARGS") +// prctl(xxx, 33, "NAME", "ARGS") // success return KPM's result value // error return -N #define SUKISU_KPM_CONTROL 33 -// prctl(xxx, xxx, 7) -// success will printf to stdout and return 0 -// error will return -1 -#define SUKISU_KPM_PRINT 34 - -#define SUKISU_KPM_VERSION 35 - - -/* A64 instructions are always 32 bits. */ -#define AARCH64_INSN_SIZE 4 - -#define AARCH64_INSN_IMM_MOVNZ AARCH64_INSN_IMM_MAX -#define AARCH64_INSN_IMM_MOVK AARCH64_INSN_IMM_16 +// prctl(xxx, 34, buffer, bufferSize) +// success return KPM's result value +// error return -N +#define SUKISU_KPM_VERSION 34 #endif \ No newline at end of file From 6b3d2bef128733c9c05c43b7023f0a06829fc272 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 15:22:30 +0800 Subject: [PATCH 02/21] 1 --- kernel/kpm/kpm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index da5f517f..7832f486 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -127,6 +127,8 @@ int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5 return sukisu_kpm_list((char __user*) arg4, (unsigned int) arg5); } else if(arg3 == SUKISU_KPM_VERSION) { return sukisu_kpm_version((char __user*) arg4, (unsigned int) arg5); + } else if(arg3 == SUKISU_KPM_CONTROL) { + return sukisu_kpm_control((char __user*) arg4, (char __user*) arg5); } return 0; } From 9de2c09a27ffb9bf7200dc51b7b6b4b36c1dbdf0 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 15:40:28 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0kpmmgr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- userspace/kpmmgr/jni/kpmmgr.c | 48 +++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/userspace/kpmmgr/jni/kpmmgr.c b/userspace/kpmmgr/jni/kpmmgr.c index ff0a07e1..f594c722 100644 --- a/userspace/kpmmgr/jni/kpmmgr.c +++ b/userspace/kpmmgr/jni/kpmmgr.c @@ -13,13 +13,36 @@ #define CMD_KPM_CONTROL_MAX 7 // 控制代码 -#define SUKISU_KPM_LOAD 1 -#define SUKISU_KPM_UNLOAD 2 -#define SUKISU_KPM_NUM 3 -#define SUKISU_KPM_LIST 4 -#define SUKISU_KPM_INFO 5 -#define SUKISU_KPM_CONTROL 6 -#define SUKISU_KPM_PRINT 7 +// prctl(xxx, 28, "PATH", "ARGS") +// success return 0, error return -N +#define SUKISU_KPM_LOAD 28 + +// prctl(xxx, 29, "NAME") +// success return 0, error return -N +#define SUKISU_KPM_UNLOAD 29 + +// num = prctl(xxx, 30) +// error return -N +// success return +num or 0 +#define SUKISU_KPM_NUM 30 + +// prctl(xxx, 31, Buffer, BufferSize) +// success return +out, error return -N +#define SUKISU_KPM_LIST 31 + +// prctl(xxx, 32, "NAME", Buffer[256]) +// success return +out, error return -N +#define SUKISU_KPM_INFO 32 + +// prctl(xxx, 33, "NAME", "ARGS") +// success return KPM's result value +// error return -N +#define SUKISU_KPM_CONTROL 33 + +// prctl(xxx, 34, buffer, bufferSize) +// success return KPM's result value +// error return -N +#define SUKISU_KPM_VERSION 34 #define CONTROL_CODE(n) (CMD_KPM_CONTROL + n - 1) @@ -32,7 +55,7 @@ void print_usage(const char *prog) { printf(" list List loaded KPM modules\n"); printf(" info Get info of a KPM module\n"); printf(" control Send control command to a KPM module\n"); - printf(" print Print KPM module list to stdout\n"); + printf(" version Print KPM Loader version\n"); } int main(int argc, char *argv[]) { @@ -72,9 +95,12 @@ int main(int argc, char *argv[]) { } else if (strcmp(argv[1], "control") == 0 && argc >= 4) { // 控制 KPM 模块 ret = prctl(KSU_OPTIONS, CONTROL_CODE(SUKISU_KPM_CONTROL), argv[2], argv[3], &out); - } else if (strcmp(argv[1], "print") == 0) { - // 在 stdout 输出 KPM 列表 - ret = prctl(KSU_OPTIONS, CONTROL_CODE(SUKISU_KPM_PRINT), NULL, NULL, &out); + } else if (strcmp(argv[1], "version") == 0) { + char buffer[1024] = {0}; + ret = prctl(KSU_OPTIONS, CONTROL_CODE(SUKISU_KPM_VERSION), buffer, sizeof(buffer), &out); + if (ret >= 0) { + printf("%s", buffer); + } } else { print_usage(argv[0]); return 1; From b668378e23e85423c2fcf0f3d239946b794720d6 Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Mon, 31 Mar 2025 15:52:57 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=91=BD=E4=BB=A4=E4=BB=A5?= =?UTF-8?q?=E8=8E=B7=E5=8F=96KPM=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shirkneko/zako/sukisu/ui/util/KsuCli.kt | 4 ++-- .../zako/sukisu/ui/viewmodel/KpmViewModel.kt | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KsuCli.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KsuCli.kt index fe873201..cf4c4c01 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KsuCli.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KsuCli.kt @@ -528,9 +528,9 @@ fun controlKpmModule(name: String, args: String? = null): String { return result } -fun printKpmModules(): String { +fun getKpmVersion(): String { val shell = getRootShell() - val cmd = "${getKpmmgrPath()} print" + val cmd = "${getKpmmgrPath()} version" val result = ShellUtils.fastCmd(shell, cmd) return result } diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/viewmodel/KpmViewModel.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/viewmodel/KpmViewModel.kt index 9f430cfd..803c3222 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/viewmodel/KpmViewModel.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/viewmodel/KpmViewModel.kt @@ -50,21 +50,16 @@ class KpmViewModel : ViewModel() { val modules = parseModuleList(moduleInfo) moduleList = modules + + // 获取 KPM 版本信息 + val kpmVersion = getKpmVersion() + Log.d("KsuCli", "KPM Version: $kpmVersion") } finally { isRefreshing = false } } } - private fun getInstalledKernelPatches(): List { - return try { - val output = printKpmModules() - parseModuleList(output) - } catch (e: Exception) { - emptyList() - } - } - private fun parseModuleList(output: String): List { return output.split("\n").mapNotNull { line -> if (line.isBlank()) return@mapNotNull null From 18876e8a69ca993849b0cc340960ae98ce45adb1 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 16:00:09 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dkpmmgr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- userspace/kpmmgr/jni/kpmmgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/userspace/kpmmgr/jni/kpmmgr.c b/userspace/kpmmgr/jni/kpmmgr.c index f594c722..2c0237bc 100644 --- a/userspace/kpmmgr/jni/kpmmgr.c +++ b/userspace/kpmmgr/jni/kpmmgr.c @@ -44,7 +44,7 @@ // error return -N #define SUKISU_KPM_VERSION 34 -#define CONTROL_CODE(n) (CMD_KPM_CONTROL + n - 1) +#define CONTROL_CODE(n) (n) void print_usage(const char *prog) { printf("Usage: %s [args]\n", prog); From 5a522a1489874349297b0058376ca298bd9fa6af Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 16:01:22 +0800 Subject: [PATCH 06/21] kpmmgr --- userspace/kpmmgr/jni/kpmmgr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/userspace/kpmmgr/jni/kpmmgr.c b/userspace/kpmmgr/jni/kpmmgr.c index 2c0237bc..57159457 100644 --- a/userspace/kpmmgr/jni/kpmmgr.c +++ b/userspace/kpmmgr/jni/kpmmgr.c @@ -82,14 +82,14 @@ int main(int argc, char *argv[]) { // 获取模块列表 char buffer[1024] = {0}; ret = prctl(KSU_OPTIONS, CONTROL_CODE(SUKISU_KPM_LIST), buffer, sizeof(buffer), &out); - if (ret >= 0) { + if (out >= 0) { printf("%s", buffer); } } else if (strcmp(argv[1], "info") == 0 && argc >= 3) { // 获取指定模块信息 char buffer[256] = {0}; ret = prctl(KSU_OPTIONS, CONTROL_CODE(SUKISU_KPM_INFO), argv[2], buffer, &out); - if (ret >= 0) { + if (out >= 0) { printf("%s\n", buffer); } } else if (strcmp(argv[1], "control") == 0 && argc >= 4) { @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) { } else if (strcmp(argv[1], "version") == 0) { char buffer[1024] = {0}; ret = prctl(KSU_OPTIONS, CONTROL_CODE(SUKISU_KPM_VERSION), buffer, sizeof(buffer), &out); - if (ret >= 0) { + if (out >= 0) { printf("%s", buffer); } } else { From df943250ac4ca4548a454bfa7c2a0399a51d65ae Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 16:07:29 +0800 Subject: [PATCH 07/21] 3 --- kernel/kpm/kpm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 7832f486..badcbecd 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -46,35 +46,42 @@ // ============================================================================================ +__attribute__((noinline)) int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. return -1; } +__attribute__((noinline)) int sukisu_kpm_unload_module(const char* name, void* ptr) { // This is a KPM module stub. return -1; } +__attribute__((noinline)) int sukisu_kpm_num(void) { // This is a KPM module stub. return 0; } +__attribute__((noinline)) int sukisu_kpm_info(const char* name, void __user* out) { // This is a KPM module stub. return -1; } +__attribute__((noinline)) int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. return -1; } +__attribute__((noinline)) int sukisu_kpm_control(void __user* name, void __user* args) { return -1; } +__attribute__((noinline)) int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { return -1; } @@ -87,7 +94,7 @@ EXPORT_SYMBOL(sukisu_kpm_list); EXPORT_SYMBOL(sukisu_kpm_version); EXPORT_SYMBOL(sukisu_kpm_control); - +__attribute__((noinline)) int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5) { if(arg3 == SUKISU_KPM_LOAD) { From fb8906e3716928725d470615db90dfd43dc27d52 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 16:19:52 +0800 Subject: [PATCH 08/21] 4 --- kernel/kpm/kpm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index badcbecd..83556acd 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -46,42 +46,42 @@ // ============================================================================================ -__attribute__((noinline)) +noinline int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. return -1; } -__attribute__((noinline)) +noinline int sukisu_kpm_unload_module(const char* name, void* ptr) { // This is a KPM module stub. return -1; } -__attribute__((noinline)) +noinline int sukisu_kpm_num(void) { // This is a KPM module stub. return 0; } -__attribute__((noinline)) +noinline int sukisu_kpm_info(const char* name, void __user* out) { // This is a KPM module stub. return -1; } -__attribute__((noinline)) +noinline int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. return -1; } -__attribute__((noinline)) +noinline int sukisu_kpm_control(void __user* name, void __user* args) { return -1; } -__attribute__((noinline)) +noinline int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { return -1; } @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sukisu_kpm_list); EXPORT_SYMBOL(sukisu_kpm_version); EXPORT_SYMBOL(sukisu_kpm_control); -__attribute__((noinline)) +noinline int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5) { if(arg3 == SUKISU_KPM_LOAD) { From 593cbaa0675e0ee1f39be6c3714a70525d67f745 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 16:55:51 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A3=B3=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E9=98=B2=E6=AD=A2=E8=A2=ABinline=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/kpm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 83556acd..56d47315 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -49,40 +49,49 @@ noinline int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. + printk("KPM: Stub function called (sukisu_kpm_load_module_path).\n"); return -1; } noinline int sukisu_kpm_unload_module(const char* name, void* ptr) { // This is a KPM module stub. + printk("KPM: Stub function called (sukisu_kpm_unload_module).\n"); return -1; } noinline int sukisu_kpm_num(void) { // This is a KPM module stub. + printk("KPM: Stub function called (sukisu_kpm_num).\n"); return 0; } noinline int sukisu_kpm_info(const char* name, void __user* out) { // This is a KPM module stub. + printk("KPM: Stub function called (sukisu_kpm_info).\n"); return -1; } noinline int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. + printk("KPM: Stub function called (sukisu_kpm_list).\n"); return -1; } noinline int sukisu_kpm_control(void __user* name, void __user* args) { + // This is a KPM module stub. + printk("KPM: Stub function called (sukisu_kpm_control).\n"); return -1; } noinline int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { + // This is a KPM module stub. + printk("KPM: Stub function called (sukisu_kpm_version).\n"); return -1; } From dec9a72b41f8991abfe7791c022f232902808cf3 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 17:17:21 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A3=B3=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BF=A1=E6=81=AF=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/kpm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 56d47315..668d8209 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -49,14 +49,14 @@ noinline int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. - printk("KPM: Stub function called (sukisu_kpm_load_module_path).\n"); + printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr); return -1; } noinline int sukisu_kpm_unload_module(const char* name, void* ptr) { // This is a KPM module stub. - printk("KPM: Stub function called (sukisu_kpm_unload_module).\n"); + printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); return -1; } @@ -70,28 +70,28 @@ int sukisu_kpm_num(void) { noinline int sukisu_kpm_info(const char* name, void __user* out) { // This is a KPM module stub. - printk("KPM: Stub function called (sukisu_kpm_info).\n"); + printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); return -1; } noinline int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. - printk("KPM: Stub function called (sukisu_kpm_list).\n"); + printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize); return -1; } noinline int sukisu_kpm_control(void __user* name, void __user* args) { // This is a KPM module stub. - printk("KPM: Stub function called (sukisu_kpm_control).\n"); + printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); return -1; } noinline int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. - printk("KPM: Stub function called (sukisu_kpm_version).\n"); + printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize); return -1; } @@ -116,7 +116,7 @@ int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5 strncpy_from_user((char*)&kernel_load_path, (const char __user *)arg4, 255); if(arg5 != 0) { - strncpy_from_user((char*)&kernel_args_buffer, (const char __user *)arg4, 255); + strncpy_from_user((char*)&kernel_args_buffer, (const char __user *)arg5, 255); } return sukisu_kpm_load_module_path((const char*)&kernel_load_path, (const char*) &kernel_args_buffer, NULL); } else if(arg3 == SUKISU_KPM_UNLOAD) { From c739bf6bfb14c9da672ef7c3632bdfd708c2921d Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Mon, 31 Mar 2025 17:30:51 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=B8=BA=20SukiSU=20Ultra=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3=E6=8F=90=E7=A4=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=B8=BA=20SukiSU=20beta=E7=89=88=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/app/src/main/res/values-zh-rCN/strings.xml | 2 +- manager/app/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manager/app/src/main/res/values-zh-rCN/strings.xml b/manager/app/src/main/res/values-zh-rCN/strings.xml index 4ef8ade1..1e350a03 100644 --- a/manager/app/src/main/res/values-zh-rCN/strings.xml +++ b/manager/app/src/main/res/values-zh-rCN/strings.xml @@ -180,7 +180,7 @@ 不允许授予 %s 超级用户权限 禁用 su 兼容性 临时禁止任何应用程序通过 su 命令获取 Root 权限(现有的 Root 进程不受影响) - 你正在使用的是 MKSU 第三方管理器 + 你正在使用的是 SukiSU beta版管理器 确定要安装选择的 %d 个模块吗? 确定要安装以下 %1$d 个模块吗?\n\n%2$s 更多设置 diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml index 0a1c37db..9caafe45 100644 --- a/manager/app/src/main/res/values/strings.xml +++ b/manager/app/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - SukiSU + SukiSU Ultra Home Not installed Click to install @@ -181,7 +181,7 @@ Granting superuser to %s is not allowed Disable su compatibility Temporarily disable any applications from obtaining root privileges via the ⁠su command (existing root processes will not be affected). - You are using the MKSU third-party manager + You are using the SukiSU beta manager Are you sure you want to install the selected %d modules? Sure you want to install the following %1$d modules? \n\n%2$s more settings From 1b06f7d3172a713f070c4e31875c91823ddf562f Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 18:08:09 +0800 Subject: [PATCH 12/21] =?UTF-8?q?=E5=85=B3=E6=8E=89=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=AF=B9=E5=A3=B3=E5=87=BD=E6=95=B0=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/kpm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 668d8209..8f3d3114 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -46,6 +46,8 @@ // ============================================================================================ +#pragma GCC optimize ("O0") + noinline int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. From 9446296daa0cb11f5d08caf1f88a68fffaead4ad Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 18:19:55 +0800 Subject: [PATCH 13/21] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E5=AF=B9=E5=A3=B3=E5=87=BD=E6=95=B0=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/kpm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 8f3d3114..74fa59fb 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -46,9 +46,8 @@ // ============================================================================================ -#pragma GCC optimize ("O0") - noinline +__attribute__((optimize("O0"))) int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr); @@ -56,6 +55,7 @@ int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { } noinline +__attribute__((optimize("O0"))) int sukisu_kpm_unload_module(const char* name, void* ptr) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); @@ -63,6 +63,7 @@ int sukisu_kpm_unload_module(const char* name, void* ptr) { } noinline +__attribute__((optimize("O0"))) int sukisu_kpm_num(void) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_num).\n"); @@ -70,6 +71,7 @@ int sukisu_kpm_num(void) { } noinline +__attribute__((optimize("O0"))) int sukisu_kpm_info(const char* name, void __user* out) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); @@ -77,6 +79,7 @@ int sukisu_kpm_info(const char* name, void __user* out) { } noinline +__attribute__((optimize("O0"))) int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize); @@ -84,6 +87,7 @@ int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { } noinline +__attribute__((optimize("O0"))) int sukisu_kpm_control(void __user* name, void __user* args) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); @@ -91,6 +95,7 @@ int sukisu_kpm_control(void __user* name, void __user* args) { } noinline +__attribute__((optimize("O0"))) int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize); @@ -106,6 +111,7 @@ EXPORT_SYMBOL(sukisu_kpm_version); EXPORT_SYMBOL(sukisu_kpm_control); noinline +__attribute__((optimize("O0"))) int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5) { if(arg3 == SUKISU_KPM_LOAD) { From 47ba174fb134b279f68327bd355d772e22bce63e Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 18:31:21 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=94=AF=E6=8C=81clang?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/kpm.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 74fa59fb..f6d65b2a 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -44,10 +44,20 @@ #include "kpm.h" #include "compact.h" +#ifndef NO_OPTIMIZE +#if defined(__GNUC__) && !defined(__clang__) + #define NO_OPTIMIZE __attribute__((optimize("O0"))) +#elif defined(__clang__) + #define NO_OPTIMIZE __attribute__((optnone)) +#else + #define NO_OPTIMIZE +#endif +#endif + // ============================================================================================ noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr); @@ -55,7 +65,7 @@ int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { } noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_kpm_unload_module(const char* name, void* ptr) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); @@ -63,7 +73,7 @@ int sukisu_kpm_unload_module(const char* name, void* ptr) { } noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_kpm_num(void) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_num).\n"); @@ -71,7 +81,7 @@ int sukisu_kpm_num(void) { } noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_kpm_info(const char* name, void __user* out) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); @@ -79,7 +89,7 @@ int sukisu_kpm_info(const char* name, void __user* out) { } noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize); @@ -87,7 +97,7 @@ int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { } noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_kpm_control(void __user* name, void __user* args) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); @@ -95,7 +105,7 @@ int sukisu_kpm_control(void __user* name, void __user* args) { } noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize); @@ -111,7 +121,7 @@ EXPORT_SYMBOL(sukisu_kpm_version); EXPORT_SYMBOL(sukisu_kpm_control); noinline -__attribute__((optimize("O0"))) +NO_OPTIMIZE int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5) { if(arg3 == SUKISU_KPM_LOAD) { From 3e928365de0f9e56204f031799174502d4097bed Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 18:51:20 +0800 Subject: [PATCH 15/21] 1 --- kernel/kpm/Makefile | 4 +++- kernel/kpm/kpm.c | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/kpm/Makefile b/kernel/kpm/Makefile index 10cf7d44..fb1d7b4f 100644 --- a/kernel/kpm/Makefile +++ b/kernel/kpm/Makefile @@ -1,2 +1,4 @@ obj-y += kpm.o -obj-y += compact.o \ No newline at end of file +obj-y += compact.o + +ccflags-y += -fno-lto \ No newline at end of file diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index f6d65b2a..87ec9bec 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -61,6 +61,7 @@ NO_OPTIMIZE int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr); + __asm__ volatile("nop"); // 精确控制循环不被优化 return -1; } @@ -69,6 +70,7 @@ NO_OPTIMIZE int sukisu_kpm_unload_module(const char* name, void* ptr) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); + __asm__ volatile("nop"); // 精确控制循环不被优化 return -1; } @@ -77,6 +79,7 @@ NO_OPTIMIZE int sukisu_kpm_num(void) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_num).\n"); + __asm__ volatile("nop"); // 精确控制循环不被优化 return 0; } @@ -85,6 +88,7 @@ NO_OPTIMIZE int sukisu_kpm_info(const char* name, void __user* out) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); + __asm__ volatile("nop"); // 精确控制循环不被优化 return -1; } @@ -101,6 +105,7 @@ NO_OPTIMIZE int sukisu_kpm_control(void __user* name, void __user* args) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); + __asm__ volatile("nop"); // 精确控制循环不被优化 return -1; } @@ -109,6 +114,7 @@ NO_OPTIMIZE int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { // This is a KPM module stub. printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize); + __asm__ volatile("nop"); // 精确控制循环不被优化 return -1; } @@ -124,6 +130,7 @@ noinline NO_OPTIMIZE int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5) { + __asm__ volatile("nop"); // 精确控制循环不被优化 if(arg3 == SUKISU_KPM_LOAD) { char kernel_load_path[256] = { 0 }; char kernel_args_buffer[256] = { 0 }; @@ -164,6 +171,7 @@ int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5 } else if(arg3 == SUKISU_KPM_CONTROL) { return sukisu_kpm_control((char __user*) arg4, (char __user*) arg5); } + __asm__ volatile("nop"); // 精确控制循环不被优化 return 0; } From 00d7de52763a8359cdb5d256a2108148e444b3ae Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 19:07:07 +0800 Subject: [PATCH 16/21] 1 --- kernel/kpm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/kpm/Makefile b/kernel/kpm/Makefile index fb1d7b4f..e0a8ce1a 100644 --- a/kernel/kpm/Makefile +++ b/kernel/kpm/Makefile @@ -1,4 +1,4 @@ obj-y += kpm.o obj-y += compact.o -ccflags-y += -fno-lto \ No newline at end of file +ccflags-y += -flto=thin \ No newline at end of file From 079f74d960a87dfbf52418e9c0f812f694fc3a31 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 19:47:22 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E5=A4=84=E7=90=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/core_hook.c | 5 +-- kernel/kpm/kpm.c | 88 ++++++++++++++++++++++++---------------------- kernel/kpm/kpm.h | 2 +- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/kernel/core_hook.c b/kernel/core_hook.c index 2f2c090c..86b73f52 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -419,10 +419,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3, pr_info("KPM: calling before arg2=%d\n", (int) arg2); - res = sukisu_handle_kpm(arg2, arg3, arg4); - copy_to_user(result, &res, sizeof(res)); - - pr_info("KPM: calling before arg2=%d res=%d\n", (int) arg2, (int) res); + res = sukisu_handle_kpm(arg2, arg3, arg4, arg5); return 0; } diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 87ec9bec..8dd28d1e 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -58,64 +58,69 @@ noinline NO_OPTIMIZE -int sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr) { +void sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr, void __user* result) { // This is a KPM module stub. + int res = -1; printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr); __asm__ volatile("nop"); // 精确控制循环不被优化 - return -1; + copy_to_user(result, &res, sizeof(res)); } noinline NO_OPTIMIZE -int sukisu_kpm_unload_module(const char* name, void* ptr) { +void sukisu_kpm_unload_module(const char* name, void* ptr, void __user* result) { // This is a KPM module stub. + int res = -1; printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); __asm__ volatile("nop"); // 精确控制循环不被优化 - return -1; + copy_to_user(result, &res, sizeof(res)); } noinline NO_OPTIMIZE -int sukisu_kpm_num(void) { +void sukisu_kpm_num(void __user* result) { // This is a KPM module stub. + int res = 0; printk("KPM: Stub function called (sukisu_kpm_num).\n"); __asm__ volatile("nop"); // 精确控制循环不被优化 - return 0; + copy_to_user(result, &res, sizeof(res)); } noinline NO_OPTIMIZE -int sukisu_kpm_info(const char* name, void __user* out) { +void sukisu_kpm_info(const char* name, void __user* out, void __user* result) { // This is a KPM module stub. + int res = -1; printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); __asm__ volatile("nop"); // 精确控制循环不被优化 - return -1; + copy_to_user(result, &res, sizeof(res)); } noinline NO_OPTIMIZE -int sukisu_kpm_list(void __user* out, unsigned int bufferSize) { +void sukisu_kpm_list(void __user* out, unsigned int bufferSize, void __user* result) { // This is a KPM module stub. + int res = -1; printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize); - return -1; + copy_to_user(result, &res, sizeof(res)); } noinline NO_OPTIMIZE -int sukisu_kpm_control(void __user* name, void __user* args) { +void sukisu_kpm_control(void __user* name, void __user* args, void __user* result) { // This is a KPM module stub. + int res = -1; printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); __asm__ volatile("nop"); // 精确控制循环不被优化 - return -1; + copy_to_user(result, &res, sizeof(res)); } noinline NO_OPTIMIZE -int sukisu_kpm_version(void __user* out, unsigned int bufferSize) { - // This is a KPM module stub. +void sukisu_kpm_version(void __user* out, unsigned int bufferSize, void __user* result) { + int res = -1; printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize); - __asm__ volatile("nop"); // 精确控制循环不被优化 - return -1; + copy_to_user(result, &res, sizeof(res)); } EXPORT_SYMBOL(sukisu_kpm_load_module_path); @@ -127,55 +132,52 @@ EXPORT_SYMBOL(sukisu_kpm_version); EXPORT_SYMBOL(sukisu_kpm_control); noinline -NO_OPTIMIZE -int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5) +int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) { - __asm__ volatile("nop"); // 精确控制循环不被优化 - if(arg3 == SUKISU_KPM_LOAD) { + if(arg2 == SUKISU_KPM_LOAD) { char kernel_load_path[256] = { 0 }; char kernel_args_buffer[256] = { 0 }; - if(arg4 == 0) { + if(arg3 == 0) { return -1; } - strncpy_from_user((char*)&kernel_load_path, (const char __user *)arg4, 255); - if(arg5 != 0) { - strncpy_from_user((char*)&kernel_args_buffer, (const char __user *)arg5, 255); + strncpy_from_user((char*)&kernel_load_path, (const char __user *)arg3, 255); + if(arg4 != 0) { + strncpy_from_user((char*)&kernel_args_buffer, (const char __user *)arg4, 255); } - return sukisu_kpm_load_module_path((const char*)&kernel_load_path, (const char*) &kernel_args_buffer, NULL); - } else if(arg3 == SUKISU_KPM_UNLOAD) { + sukisu_kpm_load_module_path((const char*)&kernel_load_path, (const char*) &kernel_args_buffer, NULL, (void __user*) arg5); + } else if(arg2 == SUKISU_KPM_UNLOAD) { char kernel_name_buffer[256] = { 0 }; - if(arg4 == 0) { + if(arg3 == 0) { return -1; } - strncpy_from_user((char*)&kernel_name_buffer, (const char __user *)arg4, 255); - return sukisu_kpm_unload_module((const char*) &kernel_name_buffer, NULL); - } else if(arg3 == SUKISU_KPM_NUM) { - return sukisu_kpm_num(); - } else if(arg3 == SUKISU_KPM_INFO) { + strncpy_from_user((char*)&kernel_name_buffer, (const char __user *)arg3, 255); + sukisu_kpm_unload_module((const char*) &kernel_name_buffer, NULL, (void __user*) arg5); + } else if(arg2 == SUKISU_KPM_NUM) { + sukisu_kpm_num((void __user*) arg5); + } else if(arg2 == SUKISU_KPM_INFO) { char kernel_name_buffer[256] = { 0 }; - if(arg4 == 0 || arg5 == 0) { + if(arg3 == 0 || arg4 == 0) { return -1; } - strncpy_from_user((char*)&kernel_name_buffer, (const char __user *)arg4, 255); - return sukisu_kpm_info((const char*) &kernel_name_buffer, (char __user*) arg5); - } else if(arg3 == SUKISU_KPM_LIST) { - return sukisu_kpm_list((char __user*) arg4, (unsigned int) arg5); - } else if(arg3 == SUKISU_KPM_VERSION) { - return sukisu_kpm_version((char __user*) arg4, (unsigned int) arg5); - } else if(arg3 == SUKISU_KPM_CONTROL) { - return sukisu_kpm_control((char __user*) arg4, (char __user*) arg5); + strncpy_from_user((char*)&kernel_name_buffer, (const char __user *)arg3, 255); + sukisu_kpm_info((const char*) &kernel_name_buffer, (char __user*) arg4, (void __user*) arg5); + } else if(arg2 == SUKISU_KPM_LIST) { + sukisu_kpm_list((char __user*) arg3, (unsigned int) arg4, (void __user*) arg5); + } else if(arg2 == SUKISU_KPM_VERSION) { + sukisu_kpm_version((char __user*) arg3, (unsigned int) arg4, (void __user*) arg5); + } else if(arg2 == SUKISU_KPM_CONTROL) { + sukisu_kpm_control((char __user*) arg3, (char __user*) arg4, (void __user*) arg5); } - __asm__ volatile("nop"); // 精确控制循环不被优化 return 0; } -int sukisu_is_kpm_control_code(unsigned long arg2) { +void sukisu_is_kpm_control_code(unsigned long arg2) { return (arg2 >= CMD_KPM_CONTROL && arg2 <= CMD_KPM_CONTROL_MAX) ? 1 : 0; } diff --git a/kernel/kpm/kpm.h b/kernel/kpm/kpm.h index 83145f97..f9f98848 100644 --- a/kernel/kpm/kpm.h +++ b/kernel/kpm/kpm.h @@ -1,7 +1,7 @@ #ifndef ___SUKISU_KPM_H #define ___SUKISU_KPM_H -int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5); +int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); int sukisu_is_kpm_control_code(unsigned long arg2); // KPM控制代码 From 9c902fb2644e55821a706f3cfbb8918dbfd65041 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 20:24:56 +0800 Subject: [PATCH 18/21] 2 --- kernel/kpm/kpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index 8dd28d1e..f646a641 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -177,7 +177,7 @@ int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, unsigned long arg4 return 0; } -void sukisu_is_kpm_control_code(unsigned long arg2) { +int sukisu_is_kpm_control_code(unsigned long arg2) { return (arg2 >= CMD_KPM_CONTROL && arg2 <= CMD_KPM_CONTROL_MAX) ? 1 : 0; } From a7c557222ca9183c9ceede080f9669b82c0e948d Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Mon, 31 Mar 2025 20:27:28 +0800 Subject: [PATCH 19/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMakefile=E4=B8=ADKPM?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E4=BF=A1=E6=81=AF=E7=9A=84=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/Makefile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index e5ab794c..57afa1ce 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -18,12 +18,6 @@ obj-$(CONFIG_KSU) += kernelsu.o obj-$(CONFIG_KPM) += kpm/ -ifeq ($(CONFIG_KPM),y) -$(info -- KPM is enabled) -else -$(info -- KPM is disabled) -endif - # .git is a text file while the module is imported by 'git submodule add'. ifeq ($(shell test -e $(srctree)/$(src)/../.git; echo $$?),0) @@ -56,6 +50,11 @@ $(info -- KernelSU Manager signature hash: $(KSU_EXPECTED_HASH)) $(info -- Supported Unofficial Manager: 5ec1cff (GKI) ShirkNeko udochina (GKI and KPM)) KERNEL_VERSION := $(VERSION).$(PATCHLEVEL) $(info -- KERNEL_VERSION: $(KERNEL_VERSION)) +ifeq ($(CONFIG_KPM),y) +$(info -- KPM is enabled) +else +$(info -- KPM is disabled) +endif ccflags-y += -DEXPECTED_SIZE=$(KSU_EXPECTED_SIZE) From e7cef05c6a07cfb1e5e3aef18df67d6135d62907 Mon Sep 17 00:00:00 2001 From: liankong Date: Mon, 31 Mar 2025 20:28:26 +0800 Subject: [PATCH 20/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/kpm/kpm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/kpm/kpm.c b/kernel/kpm/kpm.c index f646a641..39c09ad1 100644 --- a/kernel/kpm/kpm.c +++ b/kernel/kpm/kpm.c @@ -63,7 +63,7 @@ void sukisu_kpm_load_module_path(const char* path, const char* args, void* ptr, int res = -1; printk("KPM: Stub function called (sukisu_kpm_load_module_path). path=%s args=%s ptr=%p\n", path, args, ptr); __asm__ volatile("nop"); // 精确控制循环不被优化 - copy_to_user(result, &res, sizeof(res)); + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline @@ -73,7 +73,7 @@ void sukisu_kpm_unload_module(const char* name, void* ptr, void __user* result) int res = -1; printk("KPM: Stub function called (sukisu_kpm_unload_module). name=%s ptr=%p\n", name, ptr); __asm__ volatile("nop"); // 精确控制循环不被优化 - copy_to_user(result, &res, sizeof(res)); + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline @@ -83,7 +83,7 @@ void sukisu_kpm_num(void __user* result) { int res = 0; printk("KPM: Stub function called (sukisu_kpm_num).\n"); __asm__ volatile("nop"); // 精确控制循环不被优化 - copy_to_user(result, &res, sizeof(res)); + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline @@ -93,7 +93,7 @@ void sukisu_kpm_info(const char* name, void __user* out, void __user* result) { int res = -1; printk("KPM: Stub function called (sukisu_kpm_info). name=%s buffer=%p\n", name, out); __asm__ volatile("nop"); // 精确控制循环不被优化 - copy_to_user(result, &res, sizeof(res)); + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline @@ -102,7 +102,7 @@ void sukisu_kpm_list(void __user* out, unsigned int bufferSize, void __user* res // This is a KPM module stub. int res = -1; printk("KPM: Stub function called (sukisu_kpm_list). buffer=%p size=%d\n", out, bufferSize); - copy_to_user(result, &res, sizeof(res)); + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline @@ -112,7 +112,7 @@ void sukisu_kpm_control(void __user* name, void __user* args, void __user* resul int res = -1; printk("KPM: Stub function called (sukisu_kpm_control). name=%p args=%p\n", name, args); __asm__ volatile("nop"); // 精确控制循环不被优化 - copy_to_user(result, &res, sizeof(res)); + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } noinline @@ -120,7 +120,7 @@ NO_OPTIMIZE void sukisu_kpm_version(void __user* out, unsigned int bufferSize, void __user* result) { int res = -1; printk("KPM: Stub function called (sukisu_kpm_version). buffer=%p size=%d\n", out, bufferSize); - copy_to_user(result, &res, sizeof(res)); + if(copy_to_user(result, &res, sizeof(res)) < 1) printk("KPM: Copy to user faild."); } EXPORT_SYMBOL(sukisu_kpm_load_module_path); From 37b00d49c816ad490d5867b529dab4c78e19f8c9 Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Mon, 31 Mar 2025 22:11:52 +0800 Subject: [PATCH 21/21] =?UTF-8?q?=E6=B7=BB=E5=8A=A0KPM=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9B=B8=E5=85=B3UI=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shirkneko/zako/sukisu/ui/screen/Home.kt | 37 +++++ .../shirkneko/zako/sukisu/ui/screen/kpm.kt | 144 ++++++++++++------ .../zako/sukisu/ui/util/KernelConfigUtils.kt | 15 ++ .../src/main/res/values-zh-rCN/strings.xml | 5 + manager/app/src/main/res/values/strings.xml | 9 +- 5 files changed, 158 insertions(+), 52 deletions(-) create mode 100644 manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KernelConfigUtils.kt diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt index 5e0c162d..4b34f607 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/Home.kt @@ -51,6 +51,7 @@ import androidx.compose.animation.shrinkVertically import androidx.compose.runtime.saveable.rememberSaveable import shirkneko.zako.sukisu.ui.theme.CardConfig import androidx.core.content.edit +import shirkneko.zako.sukisu.ui.util.KernelConfigUtils.isKpmEnabled @OptIn(ExperimentalMaterial3Api::class) @Destination(start = true) @@ -157,6 +158,7 @@ fun HomeScreen(navigator: DestinationsNavigator) { if (!isSimpleMode) { DonateCard() LearnMoreCard() + ContributionCard() } Spacer(Modifier) @@ -347,6 +349,15 @@ private fun StatusCard( style = MaterialTheme.typography.bodyMedium ) } + Spacer(modifier = Modifier.height(4.dp)) + + if (isKpmEnabled()) { + val kpmVersion = getKpmVersion() + Text( + text = stringResource(R.string.home_kpm_version, kpmVersion), + style = MaterialTheme.typography.bodyMedium + ) + } } } @@ -404,6 +415,32 @@ fun WarningCard( } } } +@Composable +fun ContributionCard() { + ElevatedCard( + colors = getCardColors(MaterialTheme.colorScheme.secondaryContainer), + elevation = CardDefaults.cardElevation(defaultElevation = getCardElevation()) + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(24.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Column { + Text( + text = stringResource(R.string.home_ContributionCard_kernelsu), + style = MaterialTheme.typography.titleSmall + ) + Spacer(Modifier.height(4.dp)) + Text( + text = stringResource(R.string.home_click_to_ContributionCard_kernelsu), + style = MaterialTheme.typography.bodyMedium + ) + } + } + } +} @Composable fun LearnMoreCard() { diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/kpm.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/kpm.kt index ecbc59a6..7054a447 100644 --- a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/kpm.kt +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/screen/kpm.kt @@ -1,6 +1,7 @@ package shirkneko.zako.sukisu.ui.screen import android.app.Activity.RESULT_OK +import android.content.Context import android.content.Intent import android.util.Log import androidx.activity.compose.rememberLauncherForActivityResult @@ -35,7 +36,15 @@ import shirkneko.zako.sukisu.ui.viewmodel.KpmViewModel import shirkneko.zako.sukisu.ui.util.loadKpmModule import shirkneko.zako.sukisu.ui.util.unloadKpmModule import java.io.File +import androidx.core.content.edit +import shirkneko.zako.sukisu.ui.theme.ThemeConfig + +/** + * KPM 管理界面 + * 以下内核模块功能由KernelPatch开发,经过修改后加入SukiSU Ultra的内核模块功能 + * 开发者:Shirkneko, Liaokong + */ @OptIn(ExperimentalMaterial3Api::class) @Destination @Composable @@ -48,6 +57,11 @@ fun KpmScreen( val snackBarHost = remember { SnackbarHostState() } val confirmDialog = rememberConfirmDialog() val loadingDialog = rememberLoadingDialog() + val cardColor = if (!ThemeConfig.useDynamicColor) { + ThemeConfig.currentTheme.ButtonContrast + } else { + MaterialTheme.colorScheme.secondaryContainer + } val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) @@ -116,6 +130,9 @@ fun KpmScreen( viewModel.fetchModuleList() } } + // 使用 SharedPreferences 存储声明是否关闭的状态 + val sharedPreferences = context.getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + var isNoticeClosed by remember { mutableStateOf(sharedPreferences.getBoolean("is_notice_closed", false)) } Scaffold( topBar = { @@ -151,69 +168,96 @@ fun KpmScreen( ) }, text = { Text(stringResource(R.string.kpm_install)) }, - containerColor = MaterialTheme.colorScheme.secondaryContainer, + containerColor = cardColor.copy(alpha = 1f), contentColor = MaterialTheme.colorScheme.onSecondaryContainer ) }, snackbarHost = { SnackbarHost(snackBarHost) } ) { padding -> - PullToRefreshBox( - onRefresh = { viewModel.fetchModuleList() }, - isRefreshing = viewModel.isRefreshing, - modifier = Modifier.padding(padding) - ) { - if (viewModel.moduleList.isEmpty()) { - Box( - modifier = Modifier.fillMaxSize(), - contentAlignment = Alignment.Center + Column(modifier = Modifier.padding(padding)) { + if (!isNoticeClosed) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically ) { Text( - stringResource(R.string.kpm_empty), + text = stringResource(R.string.kernel_module_notice), + modifier = Modifier.weight(1f), textAlign = TextAlign.Center ) + IconButton(onClick = { + isNoticeClosed = true + sharedPreferences.edit() { putBoolean("is_notice_closed", true) } + }) { + Icon( + imageVector = Icons.Outlined.Close, + contentDescription = stringResource(R.string.close_notice) + ) + } } - } else { - LazyColumn( - modifier = Modifier.fillMaxSize(), - contentPadding = PaddingValues(16.dp), - verticalArrangement = Arrangement.spacedBy(16.dp) - ) { - items(viewModel.moduleList) { module -> - val kpmUninstallConfirm = String.format(kpmUninstallConfirmTemplate, module.name) - KpmModuleItem( - module = module, - onUninstall = { - scope.launch { - val confirmResult = confirmDialog.awaitConfirm( - title = kpmUninstall, - content = kpmUninstallConfirm, - confirm = uninstall, - dismiss = cancel - ) - if (confirmResult == ConfirmResult.Confirmed) { - val success = loadingDialog.withLoading { - unloadKpmModule(module.id) - } - Log.d("KsuCli", "unloadKpmModule result: $success") - if (success == "success") { - viewModel.fetchModuleList() - snackBarHost.showSnackbar( - message = kpmUninstallSuccess, - duration = SnackbarDuration.Long - ) - } else { - snackBarHost.showSnackbar( - message = kpmUninstallFailed, - duration = SnackbarDuration.Long - ) + } + + PullToRefreshBox( + onRefresh = { viewModel.fetchModuleList() }, + isRefreshing = viewModel.isRefreshing, + modifier = Modifier + ) { + if (viewModel.moduleList.isEmpty()) { + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + Text( + stringResource(R.string.kpm_empty), + textAlign = TextAlign.Center + ) + } + } else { + LazyColumn( + modifier = Modifier.fillMaxSize(), + contentPadding = PaddingValues(16.dp), + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + items(viewModel.moduleList) { module -> + val kpmUninstallConfirm = String.format(kpmUninstallConfirmTemplate, module.name) + KpmModuleItem( + module = module, + onUninstall = { + scope.launch { + val confirmResult = confirmDialog.awaitConfirm( + title = kpmUninstall, + content = kpmUninstallConfirm, + confirm = uninstall, + dismiss = cancel + ) + if (confirmResult == ConfirmResult.Confirmed) { + val success = loadingDialog.withLoading { + unloadKpmModule(module.id) + } + Log.d("KsuCli", "unloadKpmModule result: $success") + if (success == "success") { + viewModel.fetchModuleList() + snackBarHost.showSnackbar( + message = kpmUninstallSuccess, + duration = SnackbarDuration.Long + ) + } else { + snackBarHost.showSnackbar( + message = kpmUninstallFailed, + duration = SnackbarDuration.Long + ) + } } } + }, + onControl = { + viewModel.loadModuleDetail(module.id) } - }, - onControl = { - viewModel.loadModuleDetail(module.id) - } - ) + ) + } } } } diff --git a/manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KernelConfigUtils.kt b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KernelConfigUtils.kt new file mode 100644 index 00000000..ba32d3df --- /dev/null +++ b/manager/app/src/main/java/shirkneko/zako/sukisu/ui/util/KernelConfigUtils.kt @@ -0,0 +1,15 @@ +package shirkneko.zako.sukisu.ui.util + +import java.io.File + +object KernelConfigUtils { + + fun isKpmEnabled(): Boolean { + return try { + val config = File("/proc/config.gz").readText() + config.contains("CONFIG_KPM=y") + } catch (e: Exception) { + false + } + } +} \ No newline at end of file diff --git a/manager/app/src/main/res/values-zh-rCN/strings.xml b/manager/app/src/main/res/values-zh-rCN/strings.xml index 1e350a03..7a345adc 100644 --- a/manager/app/src/main/res/values-zh-rCN/strings.xml +++ b/manager/app/src/main/res/values-zh-rCN/strings.xml @@ -234,4 +234,9 @@ 确认安装吗? 安装kpm模块成功 安装kpm模块失败 + KPM 版本: %s + 关闭 + 以下内核模块功能由KernelPatch开发,经过修改后加入SukiSU Ultra的内核模块功能 + SukiSU Ultra展望 + SukiSU Ultra未来将会成为一个相对独立的KSU分支,但是依然感谢官方KernelSU和MKSU等做出的贡献 \ No newline at end of file diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml index 9caafe45..861e94c3 100644 --- a/manager/app/src/main/res/values/strings.xml +++ b/manager/app/src/main/res/values/strings.xml @@ -236,6 +236,11 @@ Confirm installation? Installation of kpm module successful Installation of kpm module failed - kpm 参数 - kpm 控制 + kpm parameters + kpm control + KPM Version: %s + close + The following kernel module functions were developed by KernelPatch and modified to include the kernel module functions of SukiSU Ultra + SukiSU Ultra Look forward to + SukiSU Ultra will be a relatively independent branch of KSU in the future, but thanks to the official KernelSU and MKSU etc. for their contributions!