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 00000000..c954e3b6 Binary files /dev/null and b/manager/app/src/main/jniLibs/arm64-v8a/libsusfs.so differ 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; +}