feat(core/security_features): better explanation of login response

This commit is contained in:
rhunk
2024-08-16 12:57:45 +02:00
parent ef1566add2
commit 47efdf165d
5 changed files with 70 additions and 14 deletions

View File

@@ -103,7 +103,7 @@ class RemoteSharedLibraryManager(
0,
Intent().apply {
action = Intent.ACTION_VIEW
data = "https://github.com/SnapEnhance/resources".toUri()
data = "https://codeberg.org/SnapEnhance/resources".toUri()
flags = Intent.FLAG_ACTIVITY_NEW_TASK
},
PendingIntent.FLAG_UPDATE_CURRENT

View File

@@ -178,6 +178,11 @@ class HomeRootSection : Routes.Route() {
.fillMaxWidth()
.padding(all = 10.dp)
) {
ExternalLinkIcon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_codeberg),
link = "https://codeberg.org/SnapEnhance/SnapEnhance"
)
ExternalLinkIcon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_telegram),
link = "https://t.me/snapenhance"
@@ -189,8 +194,8 @@ class HomeRootSection : Routes.Route() {
)
ExternalLinkIcon(
size = 36.dp,
modifier = Modifier.offset(y = (-2).dp),
size = 38.dp,
modifier = Modifier.offset(x = (-3).dp, y = (-3).dp),
imageVector = Icons.AutoMirrored.Default.Help,
link = "https://github.com/rhunk/SnapEnhance/wiki"
)

View File

@@ -0,0 +1,11 @@
<vector xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="4.233" android:viewportWidth="4.233" android:width="24dp">
<path android:pathData="M2.1744,1.1041c-0.0055,0 -0.0106,0.0019 -0.0141,0.0051s-0.0049,0.0073 -0.0038,0.0113l0.8154,3.0565a2.1166,2.1166 135,0 0,0.9561 -0.8198l-1.7375,-2.2463c-0.0034,-0.0042 -0.0095,-0.0068 -0.0161,-0.0068z" android:strokeColor="#00000000" android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient android:endX="3.5352" android:endY="3.8199" android:startX="2.1744" android:startY="1.1041" android:type="linear">
<item android:color="#00000000" android:offset="0"/>
<item android:color="#4C000000" android:offset="0.495"/>
</gradient>
</aapt:attr>
</path>
<path android:fillColor="#ffffff" android:pathData="M2.113,0.12C0.944,0.12 -0.004,1.067 -0.004,2.236c0,0.398 0.112,0.787 0.323,1.124l1.765,-2.282c0.013,-0.016 0.045,-0.016 0.057,0l1.765,2.282c0.211,-0.337 0.323,-0.727 0.323,-1.124C4.23,1.067 3.282,0.12 2.113,0.12z"/>
</vector>

View File

@@ -30,7 +30,7 @@ android {
standardOutput = gitHash
}
buildConfigField("String", "GIT_HASH", "\"${gitHash.toString(Charsets.UTF_8).trim()}\"")
buildConfigField("String", "SIF_ENDPOINT", "\"${properties["debug_sif_endpoint"]?.toString() ?: "https://raw.githubusercontent.com/SnapEnhance/resources/main/sif"}\"")
buildConfigField("String", "SIF_ENDPOINT", "\"${properties["debug_sif_endpoint"]?.toString() ?: "https://codeberg.org/SnapEnhance/resources/raw/branch/main/sif"}\"")
}
compileOptions {

View File

@@ -5,11 +5,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -18,22 +14,66 @@ import androidx.compose.ui.unit.sp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
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.setObjectField
import java.io.FileDescriptor
class SecurityFeatures : Feature("Security Features") {
private fun transact(option: Int) = Os.prctl(option, 0, 0, 0, 0)
private fun transact(option: Int, option2: Long) = kotlin.runCatching { Os.prctl(option, option2, 0, 0, 0) }.getOrNull()
private val token by lazy {
runCatching { transact(0) }.getOrNull()
transact(0, 0)
}
private fun getStatus() = token?.run {
transact(this).toString(2).padStart(32, '0').count { it == '1' }
transact(this, 0)?.toString(2)?.padStart(32, '0')?.count { it == '1' }
}
override fun init() {
token // pre init token
context.event.subscribe(UnaryCallEvent::class) { event ->
if (!event.uri.contains("/Login")) return@subscribe
// intercept login response
event.addResponseCallback {
val response = ProtoReader(buffer)
val isBlocked = when {
event.uri.contains("TLv") -> response.getVarInt(1) == 14L
else -> response.getVarInt(1) == 16L
}
val errorDataIndex = when {
response.contains(11) -> 11
response.contains(10) -> 10
response.contains(8) -> 8
else -> return@addResponseCallback
}
if (isBlocked) {
val status = transact(token ?: return@addResponseCallback, 1)?.let {
val buffer = ByteArray(8192)
val fd = FileDescriptor().apply {
setObjectField("descriptor", it)
}
val read = Os.read(fd, buffer, 0, buffer.size)
Os.close(fd)
buffer.copyOfRange(0, read).decodeToString()
}!!
buffer = ProtoEditor(buffer).apply {
edit(errorDataIndex) {
remove(1)
addString(1, status)
}
}.toByteArray()
}
}
}
context.inAppOverlay.addCustomComposable {
var statusText by remember {
mutableStateOf("")
@@ -49,10 +89,10 @@ class SecurityFeatures : Feature("Security Features") {
withContext(Dispatchers.Main) {
if (status == null || status == 0) {
textColor = Color.Red
statusText = "sif not loaded. Can't get status"
statusText = "SIF not loaded!"
} else {
textColor = Color.Green
statusText = "sif = $status"
statusText = "SIF = $status"
}
}
delay(1000)