private IServer ParseSSProtocol(string protocol) { Regex regex = new Regex(@"^(.+?):(.+?)@(.+?):((?:[0-9]{1}|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])+?)$"); var match = regex.Match(protocol); if (!match.Success) { AppLogProxy.AppLog.WriteLog <SubscribeUpdater>(string.Format("该SS订阅信息无法解析, Protocol: {0}", protocol)); return(null); } string algorithm = match.Groups[1].Value; string password = match.Groups[2].Value; string host = match.Groups[3].Value; int port = Convert.ToInt32(match.Groups[4].Value); if (!EncryptionCenter.IsSupport(algorithm)) { AppLogProxy.AppLog.WriteLog <SubscribeUpdater>(string.Format("该SS加密方案无法支持, Protocol: {0}", protocol)); return(null); } ShadowsockServer server = new ShadowsockServer(); server.Protocol.Name = "origin"; server.Algorithm = algorithm; server.Host = host; server.Port = port; return(server); }
private void DeserializeServers(Configuration config, IList datas) { foreach (IDictionary data in datas) { if (!data.Contains("ServerType")) { continue; } ServerType type; if (!Enum.TryParse <ServerType>(data["ServerType"] as string, out type)) { continue; } IServer server = null; switch (type) { case ServerType.Shadowsocks: server = new ShadowsockServer(); break; case ServerType.Vmess: server = new VmessServer(); break; } if (server == null) { AppLogProxy.AppLog.WriteLog <CustomJsonSerializer>(string.Format("无法识别的ServerType: {0}", type)); continue; } Type serverType = server.GetType(); PropertyInfo[] properties = serverType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (PropertyInfo property in properties) { WritePropertyValue(server, property, data); } config.Servers.Add(server); } }
private IServer ParseSSRProtocol(string protocol) { string param = ""; { int paramSplit = protocol.IndexOf("/?"); if (paramSplit >= 0) { param = protocol.Substring(paramSplit + 2); protocol = protocol.Substring(0, paramSplit); } string[] baseParams = protocol.Split(':'); if (baseParams.Length != 6) { AppLogProxy.AppLog.WriteLog <SubscribeUpdater>(string.Format("该SSR订阅信息无法解析,因为参数个数不对(需要6个), Protocol: {0}", protocol)); return(null); } try { ShadowsockServer server = new ShadowsockServer(); server.Host = baseParams[0]; server.Port = Convert.ToInt32(baseParams[1]); server.Protocol.Name = (string.IsNullOrWhiteSpace(baseParams[2]) ? "origin" : baseParams[2]).Replace("_compatible", ""); server.Algorithm = baseParams[3]; server.Obscure.Name = (string.IsNullOrWhiteSpace(baseParams[4]) ? "plain" : baseParams[4]).Replace("_compatible", ""); server.Password = Utils.FrmUrlSafeBase64(baseParams[5]); if (!string.IsNullOrWhiteSpace(param)) { ParseSSRParameters(server, param); } return(server); } catch (Exception ex) { AppLogProxy.AppLog.WriteLog <SubscribeUpdater>(string.Format("该SSR订阅信息无法解析,因为参数类型不正确, Protocol: {0}", protocol), ex); return(null); } } }
private void ParseSSRParameters(ShadowsockServer server, string data) { string[] param = data.Split('&'); foreach (string paramData in param) { if (string.IsNullOrWhiteSpace(paramData)) { continue; } int split = paramData.IndexOf('='); if (split < 1) { continue; } string key = paramData.Substring(0, split).ToLower(); string value = paramData.Substring(split + 1); switch (key) { case "protoparam": server.Protocol.Parameter = Utils.FrmUrlSafeBase64(value); break; case "obfsparam": server.Obscure.Parameter = Utils.FrmUrlSafeBase64(value); break; case "remarks": server.Describe = Utils.FrmUrlSafeBase64(value); break; } } }