manager: new zygisk detection method implemented and deprecated old method

Currently only supports ReZygisk and soon ZygiskNext will hopefully follow (ZN users will have issues detecting zygisk injections until then)
This commit is contained in:
Rifat Azad
2025-07-01 21:44:07 +06:00
parent 9733b92d30
commit d1aad01df3
10 changed files with 47 additions and 36 deletions

View File

@@ -320,3 +320,9 @@ JNIEXPORT jboolean JNICALL
Java_com_rifsxd_ksunext_Natives_setSuEnabled(JNIEnv *env, jobject thiz, jboolean enabled) { Java_com_rifsxd_ksunext_Natives_setSuEnabled(JNIEnv *env, jobject thiz, jboolean enabled) {
return set_su_enabled(enabled); return set_su_enabled(enabled);
} }
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_rifsxd_ksunext_Natives_isZygiskEnabled(JNIEnv *env, jobject) {
return is_zygisk_enabled();
}

View File

@@ -6,6 +6,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "ksu.h" #include "ksu.h"
@@ -113,3 +114,7 @@ bool is_su_enabled() {
ksuctl(CMD_IS_SU_ENABLED, &enabled, nullptr); ksuctl(CMD_IS_SU_ENABLED, &enabled, nullptr);
return enabled; return enabled;
} }
bool is_zygisk_enabled() {
return !!getenv("ZYGISK_ENABLED");
}

View File

@@ -87,4 +87,6 @@ bool set_su_enabled(bool enabled);
bool is_su_enabled(); bool is_su_enabled();
bool is_zygisk_enabled();
#endif //KERNELSU_KSU_H #endif //KERNELSU_KSU_H

View File

@@ -73,6 +73,11 @@ object Natives {
*/ */
external fun getHookMode(): String? external fun getHookMode(): String?
/**
* Check if Zygisk injection is enabled in the environment.
*/
external fun isZygiskEnabled(): Boolean
/** /**
* Get the profile of the given package. * Get the profile of the given package.
* @param key usually the package name * @param key usually the package name

View File

@@ -34,6 +34,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.intl.Locale import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.toUpperCase import androidx.compose.ui.text.toUpperCase
@@ -141,6 +142,7 @@ fun HomeScreen(navigator: DestinationsNavigator) {
@Composable @Composable
private fun SuperuserCard() { private fun SuperuserCard() {
val count = getSuperuserCount()
ElevatedCard( ElevatedCard(
colors = CardDefaults.elevatedCardColors( colors = CardDefaults.elevatedCardColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer containerColor = MaterialTheme.colorScheme.secondaryContainer
@@ -157,11 +159,11 @@ private fun SuperuserCard() {
verticalArrangement = Arrangement.spacedBy(4.dp) verticalArrangement = Arrangement.spacedBy(4.dp)
) { ) {
Text( Text(
text = stringResource(R.string.home_superuser_count), text = pluralStringResource(R.plurals.home_superuser_count, count),
style = MaterialTheme.typography.bodySmall style = MaterialTheme.typography.bodySmall
) )
Text( Text(
text = getSuperuserCount().toString(), text = count.toString(),
style = MaterialTheme.typography.titleMedium, style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.SemiBold fontWeight = FontWeight.SemiBold
) )
@@ -172,6 +174,7 @@ private fun SuperuserCard() {
@Composable @Composable
private fun ModuleCard() { private fun ModuleCard() {
val count = getModuleCount()
ElevatedCard( ElevatedCard(
colors = CardDefaults.elevatedCardColors( colors = CardDefaults.elevatedCardColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer containerColor = MaterialTheme.colorScheme.secondaryContainer
@@ -188,11 +191,11 @@ private fun ModuleCard() {
verticalArrangement = Arrangement.spacedBy(4.dp) verticalArrangement = Arrangement.spacedBy(4.dp)
) { ) {
Text( Text(
text = stringResource(R.string.home_module_count), text = pluralStringResource(R.plurals.home_module_count, count),
style = MaterialTheme.typography.bodySmall style = MaterialTheme.typography.bodySmall
) )
Text( Text(
text = getModuleCount().toString(), text = count.toString(),
style = MaterialTheme.typography.titleMedium, style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.SemiBold fontWeight = FontWeight.SemiBold
) )
@@ -645,6 +648,15 @@ private fun InfoCard(autoExpand: Boolean = false) {
icon = painterResource(R.drawable.ic_sus), icon = painterResource(R.drawable.ic_sus),
) )
} }
Spacer(Modifier.height(16.dp))
if (Natives.isZygiskEnabled()) {
InfoCardItem(
label = stringResource(R.string.zygisk_status),
content = stringResource(R.string.enabled),
icon = Icons.Filled.Vaccines
)
}
} }
if (!expanded) { if (!expanded) {

View File

@@ -823,7 +823,7 @@ fun ModuleItem(
) )
} }
val filterZygiskModules = zygiskAvailable() || !module.zygiskRequired val filterZygiskModules = Natives.isZygiskEnabled() || !module.zygiskRequired
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
developerOptionsEnabled = prefs.getBoolean("enable_developer_options", false) developerOptionsEnabled = prefs.getBoolean("enable_developer_options", false)
@@ -867,7 +867,7 @@ fun ModuleItem(
) )
) )
} }
if (!zygiskAvailable() && module.zygiskRequired && !module.remove) { if (!Natives.isZygiskEnabled() && module.zygiskRequired && !module.remove) {
LabelItem( LabelItem(
text = stringResource(R.string.zygisk_required), text = stringResource(R.string.zygisk_required),
style = LabelItemDefaults.style.copy( style = LabelItemDefaults.style.copy(

View File

@@ -641,31 +641,6 @@ fun zygiskRequired(dir: File): Boolean {
return result return result
} }
fun zygiskAvailable(): Boolean {
val shell = getRootShell()
val zygiskLib = "libzygisk.so"
val rezygisk64 = "/data/adb/modules/rezygisk/lib64/$zygiskLib"
val rezygisk = "/data/adb/modules/rezygisk/lib/$zygiskLib"
val zygiskNext64 = "/data/adb/modules/zygisksu/lib64/$zygiskLib"
val zygiskNext = "/data/adb/modules/zygisksu/lib/$zygiskLib"
val cmdRezygisk64 = "[ -f \"$rezygisk64\" ]"
if (ShellUtils.fastCmdResult(shell, cmdRezygisk64)) {
return true
}
val cmdZygiskNext64 = "[ -f \"$zygiskNext64\" ]"
if (ShellUtils.fastCmdResult(shell, cmdZygiskNext64)) {
return true
}
val cmdRezygisk = "[ -f \"$rezygisk\" ]"
if (ShellUtils.fastCmdResult(shell, cmdRezygisk)) {
return true
}
val cmdZygiskNext = "[ -f \"$zygiskNext\" ]"
return ShellUtils.fastCmdResult(shell, cmdZygiskNext)
}
fun setAppProfileTemplate(id: String, template: String): Boolean { fun setAppProfileTemplate(id: String, template: String): Boolean {
val shell = getRootShell() val shell = getRootShell()
val escapedTemplate = template.replace("\"", "\\\"") val escapedTemplate = template.replace("\"", "\\\"")

View File

@@ -22,7 +22,6 @@ import com.rifsxd.ksunext.ui.util.HanziToPinyin
import com.rifsxd.ksunext.ui.util.listModules import com.rifsxd.ksunext.ui.util.listModules
import com.rifsxd.ksunext.ui.util.getModuleSize import com.rifsxd.ksunext.ui.util.getModuleSize
import com.rifsxd.ksunext.ui.util.zygiskRequired import com.rifsxd.ksunext.ui.util.zygiskRequired
import com.rifsxd.ksunext.ui.util.zygiskAvailable
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject

View File

@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="22dp"
android:height="24dp" android:height="22dp"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24">
<path <path

View File

@@ -16,8 +16,6 @@
<string name="lkm_alternative_suggestion">Install GKI kernel or integrate KernelSU Next to your device.</string> <string name="lkm_alternative_suggestion">Install GKI kernel or integrate KernelSU Next to your device.</string>
<string name="home_working">Working</string> <string name="home_working">Working</string>
<string name="home_working_version">Version: %d</string> <string name="home_working_version">Version: %d</string>
<string name="home_superuser_count">Superuser(s)</string>
<string name="home_module_count">Module(s)</string>
<string name="home_module_update_count">Updates: %d</string> <string name="home_module_update_count">Updates: %d</string>
<string name="home_failure">KernelSU Next v2 signature not found in kernel! [ !KSU_NEXT || != size/hash ]</string> <string name="home_failure">KernelSU Next v2 signature not found in kernel! [ !KSU_NEXT || != size/hash ]</string>
<string name="home_failure_tip">Ask your kernel developer to integrate KernelSU Next!</string> <string name="home_failure_tip">Ask your kernel developer to integrate KernelSU Next!</string>
@@ -225,4 +223,13 @@
<string name="developer">Developer</string> <string name="developer">Developer</string>
<string name="sucompat_disabled">SUCOMPAT DISABLED</string> <string name="sucompat_disabled">SUCOMPAT DISABLED</string>
<string name="zygisk_required">Zygisk required</string> <string name="zygisk_required">Zygisk required</string>
<string name="zygisk_status">Zygisk injection</string>
<plurals name="home_superuser_count">
<item quantity="one">Superuser</item>
<item quantity="other">Superusers</item>
</plurals>
<plurals name="home_module_count">
<item quantity="one">Module</item>
<item quantity="other">Modules</item>
</plurals>
</resources> </resources>