diff --git a/Netch/Utils/ShareLink.cs b/Netch/Utils/ShareLink.cs index 7b24f87d..69f4b7fb 100644 --- a/Netch/Utils/ShareLink.cs +++ b/Netch/Utils/ShareLink.cs @@ -516,6 +516,56 @@ namespace Netch.Utils } list.Add(NetchLink); } + else if(text.StartsWith("trojan://")) + { + var data = new Server(); + data.Type = "Trojan"; + + text = text.Replace("/?", "?"); + try + { + if (text.Contains("#")) + { + data.Remark = HttpUtility.UrlDecode(text.Split('#')[1]); + text = text.Split('#')[0]; + } + if (text.Contains("?")) + { + var reg = new Regex(@"^(?.+?)\?(.+)$"); + var regmatch = reg.Match(text); + + if (regmatch.Success) + { + var peer = HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(text).Query).Get("peer")); + + if (peer != null) + data.Host = peer; + + text = regmatch.Groups["data"].Value; + } + else + { + throw new FormatException(); + } + } + var finder = new Regex(@"^trojan://(?.+?)@(?.+):(?\d+)"); + var match = finder.Match(text); + if (!match.Success) + { + throw new FormatException(); + } + + data.Password = match.Groups["psk"].Value; + data.Hostname = match.Groups["server"].Value; + data.Port = int.Parse(match.Groups["port"].Value); + + list.Add(data); + } + catch (FormatException) + { + return null; + } + } } catch (Exception e) {