Skip to content

Commit

Permalink
feat(security_features): mod detection version check
Browse files Browse the repository at this point in the history
This feature tells users who are using more recent/latest versions to use earlier versions, because after version 12.81.0.44 (126022), Snapchat now detects changes made to the app
  • Loading branch information
rhunk committed Oct 6, 2024
1 parent 574775f commit beb5217
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.ui.window.Dialog
import androidx.core.net.toUri
import androidx.navigation.NavBackStackEntry
import kotlinx.coroutines.launch
import me.rhunk.snapenhance.common.Constants
import me.rhunk.snapenhance.common.action.EnumAction
import me.rhunk.snapenhance.common.bridge.InternalFileHandleType
import me.rhunk.snapenhance.common.ui.rememberAsyncMutableState
Expand Down Expand Up @@ -60,7 +59,7 @@ class HomeSettings : Routes.Route() {
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(text = text)
Text(text = text, modifier = Modifier.padding(end = 16.dp), fontSize = 14.sp)
Switch(checked = value, onCheckedChange = {
value = it
sharedPreferences.edit().putBoolean(realKey, it).apply()
Expand Down Expand Up @@ -288,6 +287,7 @@ class HomeSettings : Routes.Route() {
PreferenceToggle(context.sharedPreferences, key = "disable_feature_loading", text = "Disable Feature Loading")
PreferenceToggle(context.sharedPreferences, key = "disable_mapper", text = "Disable Auto Mapper")
PreferenceToggle(context.sharedPreferences, key = "disable_sif", text = "Disable Security Features")
PreferenceToggle(context.sharedPreferences, key = "disable_mod_detection_version_check", text = "Disable Mod Detection Version Check")
}
}
Spacer(modifier = Modifier.height(50.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ package me.rhunk.snapenhance.common.config
/*
Due to recent resource obfuscation, some UI features will no longer work because it depends on non obfuscated resources
*/
val RES_OBF_VERSION_CHECK = VersionCheck(maxVersion = ("13.7.0.42" to 157172))
val RES_OBF_VERSION_CHECK = VersionCheck(maxVersion = ("13.7.0.42" to 157172))

/*
After this version, Snapchat will start detecting modifications to their app (to be confirmed)
*/
val MOD_DETECTION_VERSION_CHECK = VersionCheck(maxVersion = ("12.81.0.44 (126022)" to 126023))
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ package me.rhunk.snapenhance.core.features.impl

import android.annotation.SuppressLint
import android.system.Os
import android.widget.TextView
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.NotInterested
import me.rhunk.snapenhance.common.config.MOD_DETECTION_VERSION_CHECK
import me.rhunk.snapenhance.common.config.VersionRequirement
import me.rhunk.snapenhance.common.util.protobuf.ProtoEditor
import me.rhunk.snapenhance.common.util.protobuf.ProtoReader
import me.rhunk.snapenhance.core.event.events.impl.UnaryCallEvent
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.util.ktx.getId
import me.rhunk.snapenhance.core.util.ktx.setObjectField
import java.io.FileDescriptor

class SecurityFeatures : Feature("Security Features") {
private fun transact(option: Int, option2: Long) = kotlin.runCatching { Os.prctl(option, option2, 0, 0, 0) }.getOrNull()
private fun transact(option: Int, option2: Long) = runCatching { Os.prctl(option, option2, 0, 0, 0) }.getOrNull()

private val token by lazy {
transact(0, 0)
Expand Down Expand Up @@ -71,28 +67,18 @@ class SecurityFeatures : Feature("Security Features") {
}
}

val hovaPageTitleId = context.resources.getId("hova_page_title")
val status = getStatus()
val canCheckVersion = context.bridgeClient.getDebugProp("disable_mod_detection_version_check", "false") != "true"
val snapchatVersionCode = context.androidContext.packageManager.getPackageInfo(context.androidContext.packageName, 0).longVersionCode

fun findHovaPageTitle(): TextView? {
return context.mainActivity?.findViewById(hovaPageTitleId)
}

context.coroutineScope.launch {
while (true) {
val status = getStatus()
withContext(Dispatchers.Main) {
val textView = findHovaPageTitle() ?: return@withContext
if (status == null || status == 0) {
textView.text = "SIF not loaded"
textView.textSize = 13F
textView.setTextColor(Color.Red.toArgb())
} else {
textView.setTextColor(Color.Green.toArgb())
val prefix = textView.text.toString().substringBeforeLast(" (")
textView.text = "$prefix (${status})"
}
}
delay(1000)
if (canCheckVersion && MOD_DETECTION_VERSION_CHECK.checkVersion(snapchatVersionCode)?.second == VersionRequirement.OLDER_REQUIRED && (status == null || status < 2)) {
onNextActivityCreate {
context.inAppOverlay.showStatusToast(
icon = Icons.Filled.NotInterested,
text = "SnapEnhance is not compatible with this version of Snapchat without SIF and will result in a ban.\nUse Snapchat ${MOD_DETECTION_VERSION_CHECK.maxVersion?.first ?: "0.0.0"} or older to avoid detections or use test accounts.",
durationMs = 10000,
maxLines = 6
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,12 @@ class InAppOverlay(
text: String,
durationMs: Int = 2000,
showDuration: Boolean = true,
maxLines: Int = 3
) {
showToast(
icon = { Icon(icon, contentDescription = "icon", modifier = Modifier.size(32.dp)) },
text = {
Text(text, modifier = Modifier.fillMaxWidth(), maxLines = 3, overflow = TextOverflow.Ellipsis, lineHeight = 15.sp, fontSize = 15.sp)
Text(text, modifier = Modifier.fillMaxWidth(), maxLines = maxLines, overflow = TextOverflow.Ellipsis, lineHeight = 15.sp, fontSize = 15.sp)
},
durationMs = durationMs,
showDuration = showDuration
Expand Down

0 comments on commit beb5217

Please sign in to comment.