From 48e3d6ee6049c66c6feebf69fe580777f1916beb Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Wed, 13 May 2020 02:34:54 +0800 Subject: [PATCH] Enhancements Fix import error if VMess links have an empty type field. Add removing Emojis at the beginning of node remarks. --- Netch/Utils/ShareLink.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Netch/Utils/ShareLink.cs b/Netch/Utils/ShareLink.cs index 69f4b7fb..4a2520e7 100644 --- a/Netch/Utils/ShareLink.cs +++ b/Netch/Utils/ShareLink.cs @@ -395,7 +395,7 @@ namespace Netch.Utils } data.FakeType = vmess.type; - if (!Global.FakeTypes.Contains(data.FakeType)) + if (data.FakeType.Length != 0 && !Global.FakeTypes.Contains(data.FakeType)) { Logging.Info(string.Format("不支持的 VMess 伪装类型:{0}", data.FakeType)); return null; @@ -516,7 +516,7 @@ namespace Netch.Utils } list.Add(NetchLink); } - else if(text.StartsWith("trojan://")) + else if (text.StartsWith("trojan://")) { var data = new Server(); data.Type = "Trojan"; @@ -552,7 +552,7 @@ namespace Netch.Utils var match = finder.Match(text); if (!match.Success) { - throw new FormatException(); + throw new FormatException(); } data.Password = match.Groups["psk"].Value; @@ -573,6 +573,16 @@ namespace Netch.Utils return null; } + byte[] emoji_bytes = { 240, 159 }; + foreach (Server node in list) + { + var remark = Encoding.UTF8.GetBytes(node.Remark); + int start_index = 0; + while (remark.Length > start_index + 1 && remark[start_index] == emoji_bytes[0] && remark[start_index + 1] == emoji_bytes[1]) + start_index += 4; + node.Remark = Encoding.UTF8.GetString(remark.Skip(start_index).ToArray()).Trim(); + } + return list; } public static string UnBase64String(string value)