diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/ShadowsocksFmt.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/ShadowsocksFmt.kt index 61ffee65..610bbb56 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/ShadowsocksFmt.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/ShadowsocksFmt.kt @@ -9,10 +9,16 @@ import java.net.URI object ShadowsocksFmt : FmtBase() { fun parse(str: String): ProfileItem? { + return parseSip002(str) ?: parseLegacy(str) + } + + fun parseSip002(str: String): ProfileItem? { val config = ProfileItem.create(EConfigType.SHADOWSOCKS) val uri = URI(Utils.fixIllegalUrl(str)) - if (uri.idnHost.isEmpty() || uri.userInfo.isEmpty()) return null + if (uri.idnHost.isEmpty()) return null + if (uri.port <= 0) return null + if (uri.userInfo.isNullOrEmpty()) return null config.remarks = Utils.urlDecode(uri.fragment.orEmpty()) config.server = uri.idnHost @@ -42,6 +48,43 @@ object ShadowsocksFmt : FmtBase() { return config } + fun parseLegacy(str: String): ProfileItem? { + val config = ProfileItem.create(EConfigType.SHADOWSOCKS) + var result = str.replace(EConfigType.SHADOWSOCKS.protocolScheme, "") + val indexSplit = result.indexOf("#") + if (indexSplit > 0) { + try { + config.remarks = + Utils.urlDecode(result.substring(indexSplit + 1, result.length)) + } catch (e: Exception) { + e.printStackTrace() + } + + result = result.substring(0, indexSplit) + } + + //part decode + val indexS = result.indexOf("@") + result = if (indexS > 0) { + Utils.decode(result.substring(0, indexS)) + result.substring( + indexS, + result.length + ) + } else { + Utils.decode(result) + } + + val legacyPattern = "^(.+?):(.*)@(.+?):(\\d+?)/?$".toRegex() + val match = legacyPattern.matchEntire(result) ?: return null + + config.server = match.groupValues[3].removeSurrounding("[", "]") + config.serverPort = match.groupValues[4] + config.password = match.groupValues[2] + config.method = match.groupValues[1].lowercase() + + return config + } + fun toUri(config: ProfileItem): String { val pw = "${config.method}:${config.password}" diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/SocksFmt.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/SocksFmt.kt index f8da2dcf..d071eabc 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/SocksFmt.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/fmt/SocksFmt.kt @@ -15,6 +15,7 @@ object SocksFmt : FmtBase() { val uri = URI(Utils.fixIllegalUrl(str)) if (uri.idnHost.isEmpty()) return null + if (uri.port <= 0) return null config.remarks = Utils.urlDecode(uri.fragment.orEmpty()) config.server = uri.idnHost