kernel/manager/ksud: Add switch functionality to sulog

Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
ShirkNeko
2025-11-16 16:53:55 +08:00
parent c8020b2066
commit c4d8c49e5c
11 changed files with 135 additions and 11 deletions

View File

@@ -319,6 +319,14 @@ NativeBridge(setEnhancedSecurityEnabled, jboolean, jboolean enabled) {
return set_enhanced_security_enabled(enabled);
}
NativeBridgeNP(isSuLogEnabled, jboolean) {
return is_sulog_enabled();
}
NativeBridge(setSuLogEnabled, jboolean, jboolean enabled) {
return set_sulog_enabled(enabled);
}
NativeBridge(getUserName, jstring, jint uid) {
struct passwd *pw = getpwuid((uid_t) uid);
if (pw && pw->pw_name && pw->pw_name[0] != '\0') {

View File

@@ -231,6 +231,22 @@ bool is_enhanced_security_enabled() {
return value != 0;
}
bool set_sulog_enabled(bool enabled) {
return set_feature(KSU_FEATURE_SULOG, enabled ? 1 : 0);
}
bool is_sulog_enabled() {
uint64_t value = 0;
bool supported = false;
if (!get_feature(KSU_FEATURE_SULOG, &value, &supported)) {
return false;
}
if (!supported) {
return false;
}
return value != 0;
}
void get_full_version(char* buff) {
struct ksu_get_full_version_cmd cmd = {0};
if (ksuctl(KSU_IOCTL_GET_FULL_VERSION, &cmd) == 0) {

View File

@@ -132,6 +132,7 @@ enum ksu_feature_id {
KSU_FEATURE_SU_COMPAT = 0,
KSU_FEATURE_KERNEL_UMOUNT = 1,
KSU_FEATURE_ENHANCED_SECURITY = 2,
KSU_FEATURE_SULOG = 3,
};
// Generic feature API
@@ -211,9 +212,12 @@ bool is_kernel_umount_enabled();
// Enhanced security
bool set_enhanced_security_enabled(bool enabled);
bool is_enhanced_security_enabled();
// Su log
bool set_sulog_enabled(bool enabled);
bool is_sulog_enabled();
// Other command structures
struct ksu_get_full_version_cmd {
char version_full[KSU_FULL_VERSION_STRING]; // Output: full version string

View File

@@ -118,6 +118,15 @@ object Natives {
external fun isEnhancedSecurityEnabled(): Boolean
external fun setEnhancedSecurityEnabled(enabled: Boolean): Boolean
/**
* Su Log can be enabled/disabled.
* 0: disabled
* 1: enabled
* negative : error
*/
external fun isSuLogEnabled(): Boolean
external fun setSuLogEnabled(enabled: Boolean): Boolean
external fun isKPMEnabled(): Boolean
external fun getHookType(): String

View File

@@ -270,6 +270,49 @@ fun SettingScreen(navigator: DestinationsNavigator) {
}
)
var kernelSuLogMode by rememberSaveable {
mutableIntStateOf(
run {
val currentEnabled = Natives.isSuLogEnabled()
val savedPersist = prefs.getInt("kernel_sulog_mode", 0)
if (savedPersist == 2) 2 else if (!currentEnabled) 1 else 0
}
)
}
SuperDropdown(
icon = Icons.Rounded.RemoveCircle,
title = stringResource(id = R.string.settings_disable_sulog),
summary = stringResource(id = R.string.settings_disable_sulog_summary),
items = modeItems,
selectedIndex = kernelSuLogMode,
onSelectedIndexChange = { index ->
when (index) {
// Default: enable and save to persist
0 -> if (Natives.setSuLogEnabled(true)) {
execKsud("feature save", true)
prefs.edit { putInt("kernel_sulog_mode", 0) }
kernelSuLogMode = 0
}
// Temporarily disable: save enabled state first, then disable
1 -> if (Natives.setSuLogEnabled(true)) {
execKsud("feature save", true)
if (Natives.setSuLogEnabled(false)) {
prefs.edit { putInt("kernel_sulog_mode", 0) }
kernelSuLogMode = 1
}
}
// Permanently disable: disable and save
2 -> if (Natives.setSuLogEnabled(false)) {
execKsud("feature save", true)
prefs.edit { putInt("kernel_sulog_mode", 2) }
kernelSuLogMode = 2
}
}
}
)
// 卸载模块开关
var umountChecked by rememberSaveable { mutableStateOf(Natives.isDefaultUmountModules()) }
SwitchItem(
@@ -284,7 +327,6 @@ fun SettingScreen(navigator: DestinationsNavigator) {
}
)
// 强制签名验证开关
var forceSignatureVerification by rememberSaveable {
mutableStateOf(prefs.getBoolean("force_signature_verification", false))
@@ -403,14 +445,16 @@ fun SettingScreen(navigator: DestinationsNavigator) {
// 查看使用日志
KsuIsValid {
SettingItem(
icon = Icons.Filled.Visibility,
title = stringResource(R.string.log_viewer_view_logs),
summary = stringResource(R.string.log_viewer_view_logs_summary),
onClick = {
navigator.navigate(LogViewerScreenDestination)
}
)
if (Natives.isSuLogEnabled()) {
SettingItem(
icon = Icons.Filled.Visibility,
title = stringResource(R.string.log_viewer_view_logs),
summary = stringResource(R.string.log_viewer_view_logs_summary),
onClick = {
navigator.navigate(LogViewerScreenDestination)
}
)
}
}
val lkmMode = Natives.isLkmMode
KsuIsValid {

View File

@@ -751,4 +751,6 @@
<string name="apply_config">应用配置</string>
<string name="config_applied">配置已应用到内核</string>
<string name="group_contains_apps">包含 %1$d 个应用</string>
<string name="settings_disable_sulog">禁用 KernelSU 超级用户访问日志记录</string>
<string name="settings_disable_sulog_summary">禁用超级用户日志记录功能</string>
</resources>

View File

@@ -761,4 +761,6 @@ Important Note:\n
<string name="config_applied">Configuration applied to kernel</string>
<string name="mnt_detach">MNT_DETACH</string>
<string name="group_contains_apps">Contains %d apps</string>
<string name="settings_disable_sulog">Disable KernelSU superuser access logging</string>
<string name="settings_disable_sulog_summary">Disable superuser logging functionality</string>
</resources>