You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
userspace: add susfs lib
manager: completed susfs support check prctl syscall
This commit is contained in:
@@ -10,23 +10,6 @@
|
|||||||
#define LOG_TAG "KernelSU-Next"
|
#define LOG_TAG "KernelSU-Next"
|
||||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
#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"
|
extern "C"
|
||||||
JNIEXPORT jboolean JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_com_rifsxd_ksunext_Natives_becomeManager(JNIEnv *env, jobject, jstring pkg) {
|
Java_com_rifsxd_ksunext_Natives_becomeManager(JNIEnv *env, jobject, jstring pkg) {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "ksu.h"
|
#include "ksu.h"
|
||||||
|
|
||||||
|
#define KERNEL_SU_OPTION 0xDEADBEEF
|
||||||
|
|
||||||
#define CMD_GRANT_ROOT 0
|
#define CMD_GRANT_ROOT 0
|
||||||
|
|
||||||
#define CMD_BECOME_MANAGER 1
|
#define CMD_BECOME_MANAGER 1
|
||||||
|
|||||||
@@ -7,10 +7,6 @@
|
|||||||
|
|
||||||
#include <linux/capability.h>
|
#include <linux/capability.h>
|
||||||
|
|
||||||
#define KERNEL_SU_OPTION 0xDEADBEEF
|
|
||||||
|
|
||||||
#define CMD_SUSFS_SHOW_VERSION 0x555e1
|
|
||||||
|
|
||||||
bool become_manager(const char *);
|
bool become_manager(const char *);
|
||||||
|
|
||||||
int get_version();
|
int get_version();
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ object Natives {
|
|||||||
System.loadLibrary("kernelsu")
|
System.loadLibrary("kernelsu")
|
||||||
}
|
}
|
||||||
|
|
||||||
external fun getSusfsVersion(): String
|
|
||||||
|
|
||||||
// become root manager, return true if success.
|
// become root manager, return true if success.
|
||||||
external fun becomeManager(pkg: String?): Boolean
|
external fun becomeManager(pkg: String?): Boolean
|
||||||
val version: Int
|
val version: Int
|
||||||
|
|||||||
@@ -268,14 +268,10 @@ private fun StatusCard(
|
|||||||
style = MaterialTheme.typography.bodyMedium
|
style = MaterialTheme.typography.bodyMedium
|
||||||
)
|
)
|
||||||
Spacer(Modifier.height(4.dp))
|
Spacer(Modifier.height(4.dp))
|
||||||
|
Text(
|
||||||
val suSFS = getSuSFS()
|
text = stringResource(R.string.home_susfs, getSuSFS()),
|
||||||
if (suSFS != "Unsupported") {
|
style = MaterialTheme.typography.bodyMedium
|
||||||
Text(
|
)
|
||||||
text = stringResource(R.string.home_susfs, suSFS),
|
|
||||||
style = MaterialTheme.typography.bodyMedium
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,7 +401,6 @@ private fun InfoCard() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
Spacer(Modifier.height(16.dp))
|
Spacer(Modifier.height(16.dp))
|
||||||
|
|
||||||
val suSFS = getSuSFS()
|
val suSFS = getSuSFS()
|
||||||
if (suSFS != "Unsupported") {
|
if (suSFS != "Unsupported") {
|
||||||
InfoCardItem(
|
InfoCardItem(
|
||||||
@@ -414,7 +409,6 @@ private fun InfoCard() {
|
|||||||
icon = Icons.Filled.SettingsSuggest,
|
icon = Icons.Filled.SettingsSuggest,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,28 +120,22 @@ fun getModuleCount(): Int {
|
|||||||
}.getOrElse { return 0 }
|
}.getOrElse { return 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1
|
private fun getSuSFSPath(): String {
|
||||||
fun getSuSFS(): String {
|
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libsusfs.so"
|
||||||
return try {
|
}
|
||||||
val sus_version = Natives.getSusfsVersion()
|
|
||||||
if (sus_version.startsWith("v")) {
|
fun getSuSFS(): String {
|
||||||
"Supported"
|
val shell = getRootShell()
|
||||||
} else {
|
val result = ShellUtils.fastCmd(shell, "${getSuSFSPath()} support")
|
||||||
"Unsupported"
|
|
||||||
}
|
return result
|
||||||
} catch (e: Exception) {
|
|
||||||
"Error: ${e.message}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Try fixing Prctl method to get CMD_SUSFS_SHOW_VERSION 0x555e1
|
|
||||||
fun getSuSFSVersion(): String {
|
fun getSuSFSVersion(): String {
|
||||||
return try {
|
val shell = getRootShell()
|
||||||
val sus_version = Natives.getSusfsVersion()
|
val result = ShellUtils.fastCmd(shell, "${getSuSFSPath()} version")
|
||||||
sus_version ?: "Unknown version"
|
|
||||||
} catch (e: Exception) {
|
return result
|
||||||
"Error: ${e.message}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSuperuserCount(): Int {
|
fun getSuperuserCount(): Int {
|
||||||
|
|||||||
BIN
manager/app/src/main/jniLibs/arm64-v8a/libsusfs.so
Executable file
BIN
manager/app/src/main/jniLibs/arm64-v8a/libsusfs.so
Executable file
Binary file not shown.
2
userspace/susfs/.gitignore
vendored
Normal file
2
userspace/susfs/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/obj
|
||||||
|
/libs
|
||||||
6
userspace/susfs/jni/Android.mk
Normal file
6
userspace/susfs/jni/Android.mk
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := susfs
|
||||||
|
LOCAL_SRC_FILES := susfs.c
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
3
userspace/susfs/jni/Application.mk
Normal file
3
userspace/susfs/jni/Application.mk
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
APP_ABI := arm64-v8a x86_64
|
||||||
|
APP_PLATFORM := android-24
|
||||||
|
APP_STL := none
|
||||||
46
userspace/susfs/jni/susfs.c
Normal file
46
userspace/susfs/jni/susfs.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
|
||||||
|
#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 <version|support>\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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user