mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 22:50:05 +08:00
Fix socksfmt
This commit is contained in:
parent
3aa428b06f
commit
d52ec71bb9
@ -6,28 +6,11 @@ import io.nekohasekai.sagernet.ktx.unUrlSafe
|
||||
import io.nekohasekai.sagernet.ktx.urlSafe
|
||||
import moe.matsuri.nb4a.SingBoxOptions
|
||||
import moe.matsuri.nb4a.utils.NGUtil
|
||||
import moe.matsuri.nb4a.utils.Util
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
|
||||
fun parseSOCKS(link: String): SOCKSBean {
|
||||
if (!link.substringAfter("://").contains(":")) {
|
||||
// v2rayN shit format
|
||||
var url = link.substringAfter("://")
|
||||
if (url.contains("#")) {
|
||||
url = url.substringBeforeLast("#")
|
||||
}
|
||||
url = url.decodeBase64UrlSafe()
|
||||
val httpUrl = "http://$url".toHttpUrlOrNull() ?: error("Invalid v2rayN link content: $url")
|
||||
return SOCKSBean().apply {
|
||||
serverAddress = httpUrl.host
|
||||
serverPort = httpUrl.port
|
||||
username = httpUrl.username.takeIf { it != "null" } ?: ""
|
||||
password = httpUrl.password.takeIf { it != "null" } ?: ""
|
||||
if (link.contains("#")) {
|
||||
name = link.substringAfter("#").unUrlSafe()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val url = ("http://" + link.substringAfter("://")).toHttpUrlOrNull()
|
||||
?: error("Not supported: $link")
|
||||
|
||||
@ -41,7 +24,14 @@ fun parseSOCKS(link: String): SOCKSBean {
|
||||
serverPort = url.port
|
||||
username = url.username
|
||||
password = url.password
|
||||
name = url.fragment
|
||||
// v2rayN fmt
|
||||
if (password.isNullOrBlank() && !username.isNullOrBlank()) {
|
||||
try {
|
||||
val n = username.decodeBase64UrlSafe()
|
||||
username = n.substringBefore(":")
|
||||
password = n.substringAfter(":")
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ object Util {
|
||||
for (flag in flags) {
|
||||
try {
|
||||
ret = Base64.decode(str, flag)
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
if (ret != null) return ret
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user