From 3febc5ae7915648826cbff7956eb4b81a4b3b377 Mon Sep 17 00:00:00 2001 From: Rifat Azad Date: Sun, 22 Dec 2024 08:49:45 +0600 Subject: [PATCH] userspace: add susfs lib manager: completed susfs support check prctl syscall --- manager/app/src/main/cpp/jni.cc | 17 ------- manager/app/src/main/cpp/ksu.cc | 2 + manager/app/src/main/cpp/ksu.h | 4 -- .../main/java/com/rifsxd/ksunext/Natives.kt | 2 - .../java/com/rifsxd/ksunext/ui/screen/Home.kt | 14 ++---- .../java/com/rifsxd/ksunext/ui/util/KsuCli.kt | 32 +++++------- .../src/main/jniLibs/arm64-v8a/libsusfs.so | Bin 0 -> 5392 bytes userspace/susfs/.gitignore | 2 + userspace/susfs/jni/Android.mk | 6 +++ userspace/susfs/jni/Application.mk | 3 ++ userspace/susfs/jni/susfs.c | 46 ++++++++++++++++++ 11 files changed, 76 insertions(+), 52 deletions(-) create mode 100755 manager/app/src/main/jniLibs/arm64-v8a/libsusfs.so create mode 100644 userspace/susfs/.gitignore create mode 100644 userspace/susfs/jni/Android.mk create mode 100644 userspace/susfs/jni/Application.mk create mode 100644 userspace/susfs/jni/susfs.c diff --git a/manager/app/src/main/cpp/jni.cc b/manager/app/src/main/cpp/jni.cc index 8077f6f9..f5d13b9b 100644 --- a/manager/app/src/main/cpp/jni.cc +++ b/manager/app/src/main/cpp/jni.cc @@ -10,23 +10,6 @@ #define LOG_TAG "KernelSU-Next" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) -// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1 -extern "C" -JNIEXPORT jstring JNICALL -Java_com_rifsxd_ksunext_Natives_getSusfsVersion(JNIEnv *env, jobject) { - int error = -1; - char susfsVersion[16]; - - error = prctl(KERNEL_SU_OPTION, CMD_SUSFS_SHOW_VERSION, susfsVersion, NULL, &error); - if (!error) { - return env->NewStringUTF(susfsVersion); - LOGD("susfs: found"); - } else { - LOGD("susfs: not foung"); - return env->NewStringUTF("Error fetching version"); - } -} - extern "C" JNIEXPORT jboolean JNICALL Java_com_rifsxd_ksunext_Natives_becomeManager(JNIEnv *env, jobject, jstring pkg) { diff --git a/manager/app/src/main/cpp/ksu.cc b/manager/app/src/main/cpp/ksu.cc index 944c556e..1e798189 100644 --- a/manager/app/src/main/cpp/ksu.cc +++ b/manager/app/src/main/cpp/ksu.cc @@ -10,6 +10,8 @@ #include "ksu.h" +#define KERNEL_SU_OPTION 0xDEADBEEF + #define CMD_GRANT_ROOT 0 #define CMD_BECOME_MANAGER 1 diff --git a/manager/app/src/main/cpp/ksu.h b/manager/app/src/main/cpp/ksu.h index a52207c7..160a9d6f 100644 --- a/manager/app/src/main/cpp/ksu.h +++ b/manager/app/src/main/cpp/ksu.h @@ -7,10 +7,6 @@ #include -#define KERNEL_SU_OPTION 0xDEADBEEF - -#define CMD_SUSFS_SHOW_VERSION 0x555e1 - bool become_manager(const char *); int get_version(); diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/Natives.kt b/manager/app/src/main/java/com/rifsxd/ksunext/Natives.kt index ff27d1ef..8b9d8c6a 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/Natives.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/Natives.kt @@ -30,8 +30,6 @@ object Natives { System.loadLibrary("kernelsu") } - external fun getSusfsVersion(): String - // become root manager, return true if success. external fun becomeManager(pkg: String?): Boolean val version: Int diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt index 1010ddaa..78f08335 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt @@ -268,14 +268,10 @@ private fun StatusCard( style = MaterialTheme.typography.bodyMedium ) Spacer(Modifier.height(4.dp)) - - val suSFS = getSuSFS() - if (suSFS != "Unsupported") { - Text( - text = stringResource(R.string.home_susfs, suSFS), - style = MaterialTheme.typography.bodyMedium - ) - } + Text( + text = stringResource(R.string.home_susfs, getSuSFS()), + style = MaterialTheme.typography.bodyMedium + ) } } @@ -405,7 +401,6 @@ private fun InfoCard() { ) Spacer(Modifier.height(16.dp)) - val suSFS = getSuSFS() if (suSFS != "Unsupported") { InfoCardItem( @@ -414,7 +409,6 @@ private fun InfoCard() { icon = Icons.Filled.SettingsSuggest, ) } - } } } diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt index a344419e..9a234ef6 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/util/KsuCli.kt @@ -120,28 +120,22 @@ fun getModuleCount(): Int { }.getOrElse { return 0 } } -// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1 -fun getSuSFS(): String { - return try { - val sus_version = Natives.getSusfsVersion() - if (sus_version.startsWith("v")) { - "Supported" - } else { - "Unsupported" - } - } catch (e: Exception) { - "Error: ${e.message}" - } +private fun getSuSFSPath(): String { + return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libsusfs.so" +} + +fun getSuSFS(): String { + val shell = getRootShell() + val result = ShellUtils.fastCmd(shell, "${getSuSFSPath()} support") + + return result } -// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1 fun getSuSFSVersion(): String { - return try { - val sus_version = Natives.getSusfsVersion() - sus_version ?: "Unknown version" - } catch (e: Exception) { - "Error: ${e.message}" - } + val shell = getRootShell() + val result = ShellUtils.fastCmd(shell, "${getSuSFSPath()} version") + + return result } fun getSuperuserCount(): Int { diff --git a/manager/app/src/main/jniLibs/arm64-v8a/libsusfs.so b/manager/app/src/main/jniLibs/arm64-v8a/libsusfs.so new file mode 100755 index 0000000000000000000000000000000000000000..c954e3b63c97b4782a0e548ff0810d1442309acd GI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h+_; z`!M>!@$o#-W1NP)?X@9nTT&w5rugShrLIRpoBnlHfw60k9-O;za%c|cTcb6iwQhcF zq`nJqp12+dmK$y4mw0!q^V@2gQXSm|)lurFgc9{G9Q)%&<8JEX&iV27+ErW!Y6on; zAKO*ze+B#O#X63&Dk~@dJcoN|{`MzE>TOr!H5H!~`IX|frLisCha7WG{|{Ylh^ ze0mx6v`@ECf7Yi@qW-c^KY{w|KK&Wguln?7Q4jaJ{u?YZfm`Xg9Z=-?P+|8vfCGVGB>u0&QgAxRa*iCsVNN%HZPg3Xc@VL8jH{%T3OK!f*yyWCr zKK!(yNF?V=u6>w0%E=agJS_Z%9ZF6;`P7@=X>M1Um-}ib>-gMVxrb5it#;O> zov$sB`^%rRsOt*P{|Nj0l=VF8_&jC3dE~Da7WjeuznFC2Mfa=8%l(K3pfS4-PAMD^okeBXkokxykUtz@L~I%>J{ zM3gV(6sq{TWmpxqMT?s{cw-zdd1PL*^Pi2zvCweoi9%8D#D59MrB*6rAZq8)wWFnR zU{lu|?JL?=&*3#P_kXFlll&w4gIJ-nEcU_wi_S<#Mm{F1>_x2k?N!bLg7>cW z^eRF7SCOWiA^s(g2sU%Tl-H;#`Azc6OUTig6?-|?f_Gs%iTIU%g3n+Zj&Wgepc zDPZ5h7n9(ubYztHh3;T`xyR%?lHfH7lnsLZp9tCq^836vVw8JIXd0e4J~klto_tRU z_7BES?ewWj?B!mZ=8N`L_Ow6o{chD>?#-DmX#XDC(%OlC`CcU7k%HfgBz}o2ing={ zVqfJ0Q*A{Og`SUJ#9p`~Sn=D-d&(@^ACr!ZLHi8y#EJja?`8DC10~o$sMGfh@*ktl iK9TQlZ}>Q>QeP6m53w%3-3I=7ll_0 literal 0 HcmV?d00001 diff --git a/userspace/susfs/.gitignore b/userspace/susfs/.gitignore new file mode 100644 index 00000000..720289cc --- /dev/null +++ b/userspace/susfs/.gitignore @@ -0,0 +1,2 @@ +/obj +/libs diff --git a/userspace/susfs/jni/Android.mk b/userspace/susfs/jni/Android.mk new file mode 100644 index 00000000..cab15322 --- /dev/null +++ b/userspace/susfs/jni/Android.mk @@ -0,0 +1,6 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := susfs +LOCAL_SRC_FILES := susfs.c +include $(BUILD_EXECUTABLE) diff --git a/userspace/susfs/jni/Application.mk b/userspace/susfs/jni/Application.mk new file mode 100644 index 00000000..873252b9 --- /dev/null +++ b/userspace/susfs/jni/Application.mk @@ -0,0 +1,3 @@ +APP_ABI := arm64-v8a x86_64 +APP_PLATFORM := android-24 +APP_STL := none diff --git a/userspace/susfs/jni/susfs.c b/userspace/susfs/jni/susfs.c new file mode 100644 index 00000000..976ef804 --- /dev/null +++ b/userspace/susfs/jni/susfs.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +#define KERNEL_SU_OPTION 0xDEADBEEF +#define CMD_SUSFS_SHOW_VERSION 0x555e1 + +int main(int argc, char *argv[]) { + int error = -1; + char version[16]; + + // Check for arguments + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + // If 'version' is given, show version + if (strcmp(argv[1], "version") == 0) { + prctl(KERNEL_SU_OPTION, CMD_SUSFS_SHOW_VERSION, version, NULL, &error); + if (!error) { + printf("%s\n", version); + } else { + fprintf(stderr, "Failed to retrieve version\n"); + } + } + // If 'support' is given, check if version starts with 'v' + else if (strcmp(argv[1], "support") == 0) { + prctl(KERNEL_SU_OPTION, CMD_SUSFS_SHOW_VERSION, version, NULL, &error); + if (!error) { + if (version[0] == 'v') { + printf("Supported\n"); + } else { + printf("Unsupported\n"); + } + } else { + fprintf(stderr, "Failed to retrieve version\n"); + } + } else { + fprintf(stderr, "Invalid argument: %s\n", argv[1]); + return 1; + } + + return 0; +}