From b312534d067c550b576130aba5e5eb3d5a83cf12 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Thu, 30 Jan 2020 17:06:11 +0800 Subject: [PATCH] Fix a bug Clean up codes. --- Netch/Utils/ShareLink.cs | 181 +-------------------------------------- 1 file changed, 2 insertions(+), 179 deletions(-) diff --git a/Netch/Utils/ShareLink.cs b/Netch/Utils/ShareLink.cs index a796133a..9ad90936 100644 --- a/Netch/Utils/ShareLink.cs +++ b/Netch/Utils/ShareLink.cs @@ -47,7 +47,7 @@ namespace Netch.Utils foreach (var line in text.GetLines()) { var servers = ParseLine(line); - if (line != null) + if (servers != null) { list.AddRange(servers); } @@ -109,110 +109,7 @@ namespace Netch.Utils { var data = new Server(); data.Type = "SS"; - /* - try - { - if(!text.Contains("/?")) - { - var finder = new Regex(@"ss://(?[A-Za-z0-9+-/=_]+)(?:#(?\S+))?", RegexOptions.IgnoreCase); - var parser = new Regex(@"^((?.+?):(?.*)@(?.+?):(?\d+?))$", RegexOptions.IgnoreCase); - var match = finder.Match(text); - if (!match.Success) - { - throw new FormatException(); - } - - var base64 = match.Groups["base64"].Value.TrimEnd('/'); - var tag = match.Groups["tag"].Value; - if (!String.IsNullOrEmpty(tag)) - { - data.Remark = HttpUtility.UrlDecode(tag); - } - - match = parser.Match(URLSafeBase64Decode(base64)); - if (!match.Success) - { - throw new FormatException(); - } - - data.Address = match.Groups["hostname"].Value; - data.Port = int.Parse(match.Groups["port"].Value); - data.Password = match.Groups["password"].Value; - data.EncryptMethod = match.Groups["method"].Value; - } - else - { - if (text.Contains("#")) - { - data.Remark = HttpUtility.UrlDecode(text.Split('#')[1]); - text = text.Split('#')[0]; - } - var finder = new Regex(@"ss://(?.+?)@(?.+?):(?\d+?)/\?plugin=(?.+)"); - var parser = new Regex(@"^(?.+?):(?.+)$"); - var match = finder.Match(text); - if (!match.Success) - { - throw new FormatException(); - } - - data.Address = match.Groups["server"].Value; - data.Port = int.Parse(match.Groups["port"].Value); - var plugins = HttpUtility.UrlDecode(match.Groups["plugin"].Value).Split(';'); - if (plugins[0] == "obfs-local") - plugins[0] = "simple-obfs"; - - var base64 = URLSafeBase64Decode(match.Groups["base64"].Value); - match = parser.Match(base64); - if (!match.Success) - { - throw new FormatException(); - } - - data.EncryptMethod = match.Groups["method"].Value; - data.Password = match.Groups["password"].Value; - data.Plugin = plugins[0]; - data.PluginOption = plugins[1]; - } - - if (!Global.EncryptMethods.SS.Contains(data.EncryptMethod)) - { - Logging.Info(String.Format("不支持的 SS 加密方式:{0}", data.EncryptMethod)); - return null; - } - - list.Add(data); - } - catch (FormatException) - { - try - { - var uri = new Uri(text); - var userinfo = URLSafeBase64Decode(uri.UserInfo).Split(new char[] { ':' }, 2); - if (userinfo.Length != 2) - { - return null; - } - - data.Remark = uri.GetComponents(UriComponents.Fragment, UriFormat.Unescaped); - data.Address = uri.IdnHost; - data.Port = uri.Port; - data.Password = userinfo[1]; - data.EncryptMethod = userinfo[0]; - - if (!Global.EncryptMethods.SS.Contains(data.EncryptMethod)) - { - Logging.Info(String.Format("不支持的 SS 加密方式:{0}", data.EncryptMethod)); - return null; - } - - list.Add(data); - } - catch (UriFormatException) - { - return null; - } - } - */ + text = text.Replace("/?", "?"); try { @@ -337,81 +234,7 @@ namespace Netch.Utils data.Type = "SSR"; text = text.Substring(6); - /* - var shadowsocksr = URLSafeBase64Decode(text).Split(':'); - if (shadowsocksr.Length > 6) - { - var buff = ""; - - for (int i = 0; i < shadowsocksr.Length - 5; i++) - { - buff += shadowsocksr[i]; - buff += ":"; - } - - data.Address = buff.Substring(0, buff.Length - 1).Trim(); - } - else - { - data.Address = shadowsocksr[0]; - } - data.Port = int.Parse(shadowsocksr[shadowsocksr.Length - 5]); - data.Protocol = shadowsocksr[shadowsocksr.Length - 4]; - if (!Global.Protocols.Contains(data.Protocol)) - { - Logging.Info(String.Format("不支持的 SSR 协议:{0}", data.Protocol)); - return null; - } - - data.EncryptMethod = shadowsocksr[shadowsocksr.Length - 3]; - if (!Global.EncryptMethods.SSR.Contains(data.EncryptMethod)) - { - Logging.Info(String.Format("不支持的 SSR 加密方式:{0}", data.EncryptMethod)); - return null; - } - - data.OBFS = shadowsocksr[shadowsocksr.Length - 2]; - if (!Global.OBFSs.Contains(data.OBFS)) - { - Logging.Info(String.Format("不支持的 SSR 混淆:{0}", data.OBFS)); - return null; - } - - var info = shadowsocksr[shadowsocksr.Length - 1].Split('/'); - data.Password = URLSafeBase64Decode(info[0]); - - var dict = new Dictionary(); - if (info.Length > 1 && info[1].Length > 1) - { - foreach (var str in info[1].Substring(1).Split('&')) - { - var splited = str.Split('='); - - dict.Add(splited[0], splited[1]); - } - } - - if (dict.ContainsKey("remarks")) - { - data.Remark = URLSafeBase64Decode(dict["remarks"]); - } - - if (dict.ContainsKey("protoparam")) - { - data.ProtocolParam = URLSafeBase64Decode(dict["protoparam"]); - } - - if (dict.ContainsKey("obfsparam")) - { - data.OBFSParam = URLSafeBase64Decode(dict["obfsparam"]); - } - - if (data.EncryptMethod != "none" && data.Protocol == "origin" && data.OBFS == "plain") - { - data.Type = "SS"; - } - */ var parser = new Regex(@"^(?.+):(?(-?\d+?)):(?.+?):(?.+?):(?.+?):(?.+?)/\?(?.*)$"); var match = parser.Match(URLSafeBase64Decode(text));