Ejemplo n.º 1
0
        public string ImportVmess(string url)
        {
            Dictionary <string, object> VmessProfiles  = Utilities.VmessOutboundTemplateNew();
            Dictionary <string, object> muxSettings    = VmessProfiles["mux"] as Dictionary <string, object>;
            Dictionary <string, object> streamSettings = VmessProfiles["streamSettings"] as Dictionary <string, object>;
            Dictionary <string, object> settings       = VmessProfiles["settings"] as Dictionary <string, object>;
            Dictionary <string, object> vnext          = (settings["vnext"] as IList <object>)[0] as Dictionary <string, object>;
            Dictionary <string, object> UserInfo       = (vnext["users"] as IList <object>)[0] as Dictionary <string, object>;
            Dictionary <string, object> kcpSettings    = streamSettings["kcpSettings"] as Dictionary <string, object>;
            Dictionary <string, object> kcpSettingsT   = kcpSettings["header"] as Dictionary <string, object>;
            Dictionary <string, object> tcpSettings    = streamSettings["tcpSettings"] as Dictionary <string, object>;
            Dictionary <string, object> tcpSettingsT   = tcpSettings["header"] as Dictionary <string, object>;
            Dictionary <string, object> wsSettings     = streamSettings["wsSettings"] as Dictionary <string, object>;
            Dictionary <string, object> wsSettingsT    = wsSettings["headers"] as Dictionary <string, object>;
            Dictionary <string, object> httpSettings   = streamSettings["httpSettings"] as Dictionary <string, object>;
            Dictionary <string, object> quicSettings   = streamSettings["quicSettings"] as Dictionary <string, object>;
            Dictionary <string, object> quicSettingsT  = quicSettings["header"] as Dictionary <string, object>;
            Dictionary <string, object> tlsSettings    = streamSettings["tlsSettings"] as Dictionary <string, object>;

            VmessLink VmessLink = JsonConvert.DeserializeObject <VmessLink>(ExtraUtils.Base64Decode(url.Substring(8)));

            UserInfo["id"]             = VmessLink.id;
            UserInfo["alterId"]        = Convert.ToInt32(VmessLink.aid);
            vnext["address"]           = VmessLink.add;
            vnext["port"]              = Convert.ToInt32(VmessLink.port);
            streamSettings["network"]  = VmessLink.net == "h2" ? "http" : VmessLink.net;
            streamSettings["security"] = VmessLink.tls == "" ? "none" : VmessLink.tls;
            tlsSettings["serverName"]  = VmessLink.add;
            VmessProfiles["tag"]       = VmessLink.ps;
            switch (VmessLink.net)
            {
            case "ws":
                wsSettingsT["host"] = VmessLink.host;
                wsSettings["path"]  = VmessLink.path;
                break;

            case "h2":
                httpSettings["host"] = VmessLink.host.Split(',');
                httpSettings["path"] = VmessLink.path;
                break;

            case "tcp":
                tcpSettingsT["type"] = VmessLink.type;
                break;

            case "kcp":
                kcpSettingsT["type"] = VmessLink.type;
                break;

            case "quic":
                quicSettingsT["type"]   = VmessLink.type;
                quicSettings["securty"] = VmessLink.host;
                quicSettings["key"]     = VmessLink.path;
                break;

            default:
                break;
            }
            profiles.Add(VmessProfiles);
            return(VmessLink.ps);
        }
Ejemplo n.º 2
0
        private void ShareMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (vmessListBox.SelectedIndex >= 0 && vmessListBox.SelectedIndex < profiles.Count)
            {
                Dictionary <string, object> selectedProfile  = profiles[vmessListBox.SelectedIndex];
                Dictionary <string, object> selectedVnext    = ((selectedProfile["settings"] as Dictionary <string, object>)["vnext"] as IList <object>)[0] as Dictionary <string, object>;
                Dictionary <string, object> selectedUserInfo = (selectedVnext["users"] as IList <object>)[0] as Dictionary <string, object>;
                Dictionary <string, object> streamSettings   = selectedProfile["streamSettings"] as Dictionary <string, object>;
                Dictionary <string, object> kcpSettings      = streamSettings["kcpSettings"] as Dictionary <string, object>;
                Dictionary <string, object> kcpSettingsT     = kcpSettings["header"] as Dictionary <string, object>;
                Dictionary <string, object> tcpSettings      = streamSettings["tcpSettings"] as Dictionary <string, object>;
                Dictionary <string, object> tcpSettingsT     = tcpSettings["header"] as Dictionary <string, object>;
                Dictionary <string, object> wsSettings       = streamSettings["wsSettings"] as Dictionary <string, object>;
                Dictionary <string, object> wsSettingsT      = wsSettings["headers"] as Dictionary <string, object>;
                Dictionary <string, object> httpSettings     = streamSettings["httpSettings"] as Dictionary <string, object>;
                Dictionary <string, object> quicSettings     = streamSettings["quicSettings"] as Dictionary <string, object>;
                Dictionary <string, object> quicSettingsT    = quicSettings["header"] as Dictionary <string, object>;
                Dictionary <string, object> tlsSettings      = streamSettings["tlsSettings"] as Dictionary <string, object>;
                VmessLink vlink = new VmessLink();
                vlink.v    = "2";
                vlink.ps   = selectedProfile["tag"].ToString();
                vlink.add  = selectedVnext["address"].ToString();
                vlink.port = selectedVnext["port"].ToString();
                vlink.id   = selectedUserInfo["id"].ToString();
                vlink.aid  = selectedUserInfo["alterId"].ToString();
                vlink.net  = streamSettings["network"].ToString();
                vlink.tls  = streamSettings["security"].ToString();
                vlink.type = "";
                vlink.host = "";
                vlink.path = "";
                switch (streamSettings["network"].ToString())
                {
                case "ws":
                    vlink.host = wsSettingsT["host"].ToString();
                    vlink.path = wsSettings["path"].ToString() == "" ? "/" : wsSettings["path"].ToString();
                    break;

                case "http":
                    vlink.net  = "h2";
                    vlink.host = httpSettings.ContainsKey("host") ? String.Join(",", httpSettings["host"] as object[]) : "";
                    vlink.path = httpSettings["path"].ToString() == "" ? "/" : httpSettings["path"].ToString();
                    break;

                case "tcp":
                    vlink.type = tcpSettingsT["type"].ToString() == "" ? "none" : tcpSettingsT["type"].ToString();
                    break;

                case "kcp":
                    vlink.type = kcpSettingsT["type"].ToString() == "" ? "none" : kcpSettingsT["type"].ToString();
                    break;

                case "quic":
                    vlink.type = quicSettingsT["type"].ToString() == "" ? "none" : quicSettingsT["type"].ToString();
                    vlink.host = quicSettings["securty"].ToString() == "" ? "none" : quicSettings["securty"].ToString();
                    vlink.path = quicSettings["key"].ToString();
                    break;

                default:
                    break;
                }
                var sharejson = Utilities.javaScriptSerializer.Serialize(vlink);
                ExtraUtils.SetClipboardData(ExtraUtils.Base64Encode(sharejson).Insert(0, "vmess://"));
            }
        }