Ejemplo n.º 1
0
 private void UpdateObfsTextBox()
 {
     try
     {
         Obfs.ObfsBase obfs       = (Obfs.ObfsBase)Obfs.ObfsFactory.GetObfs(cmbObfs.Text);
         int[]         properties = obfs.GetObfs()[cmbObfs.Text];
         txtObfsParam.Enabled = properties[2] > 0;
     }
     catch
     {
         txtObfsParam.Enabled = true;
     }
 }
Ejemplo n.º 2
0
 private void ObfsCombo_TextChanged(object sender, EventArgs e)
 {
     Obfs.ObfsBase obfs       = (Obfs.ObfsBase)Obfs.ObfsFactory.GetObfs(ObfsCombo.Text);
     int[]         properties = obfs.GetObfs()[ObfsCombo.Text];
     if (properties[2] > 0)
     {
         textObfsParam.Enabled = true;
     }
     else
     {
         textObfsParam.Enabled = false;
     }
 }
 private void UpdateObfsTextbox()
 {
     try
     {
         Obfs.ObfsBase obfs       = (Obfs.ObfsBase)Obfs.ObfsFactory.GetObfs(ObfsCombo.Text);
         int[]         properties = obfs.GetObfs()[ObfsCombo.Text];
         if (properties[2] > 0)
         {
             TextObfsParam.Enabled = true;
         }
         else
         {
             TextObfsParam.Enabled = false;
         }
     }
     catch
     {
         TextObfsParam.Enabled = true;
     }
 }
Ejemplo n.º 4
0
 private void UpdateProtocolTextbox()
 {
     try
     {
         Obfs.ObfsBase obfs       = (Obfs.ObfsBase)Obfs.ObfsFactory.GetObfs(TCPProtocolComboBox.Text);
         int[]         properties = obfs.GetObfs()[TCPProtocolComboBox.Text];
         if (properties[2] > 0)
         {
             TextProtocolParam.Enabled = true;
         }
         else
         {
             TextProtocolParam.Enabled = false;
         }
     }
     catch
     {
         TextProtocolParam.Enabled = false;
     }
 }
Ejemplo n.º 5
0
        public void ServerFromSS(string ssURL)
        {
            // ss://obfs:protocol:method:passwd@host:port/#remarks
            string[] r1     = Regex.Split(ssURL, "ss://", RegexOptions.IgnoreCase);
            string   base64 = r1[1].ToString();
            string   data   = DecodeBase64(base64);

            if (data.Length == 0)
            {
                throw new FormatException();
            }
            try
            {
                int indexLastAt       = data.LastIndexOf('@');
                int remarkIndexLastAt = data.IndexOf('#', indexLastAt);
                if (remarkIndexLastAt > 0)
                {
                    if (remarkIndexLastAt + 1 < data.Length)
                    {
                        this.remarks_base64 = data.Substring(remarkIndexLastAt + 1);
                    }
                    data = data.Substring(0, remarkIndexLastAt);
                }
                remarkIndexLastAt = data.IndexOf('/', indexLastAt);
                string param = "";
                if (remarkIndexLastAt > 0)
                {
                    if (remarkIndexLastAt + 1 < data.Length)
                    {
                        param = data.Substring(remarkIndexLastAt + 1);
                    }
                    data = data.Substring(0, remarkIndexLastAt);
                }
                //int paramIndexLastAt = param.IndexOf('?', indexLastAt);
                //Dictionary<string, string> params_dict = new Dictionary<string, string>();
                //if (paramIndexLastAt >= 0)
                //{
                //    string[] obfs_params = param.Substring(paramIndexLastAt + 1).Split('&');
                //    foreach (string p in obfs_params)
                //    {
                //        if (p.IndexOf('=') > 0)
                //        {
                //            int index = p.IndexOf('=');
                //            string key, val;
                //            key = p.Substring(0, index);
                //            val = p.Substring(index + 1);
                //            try
                //            {
                //                byte[] b64_bytes = System.Convert.FromBase64String(val);
                //                if (b64_bytes != null)
                //                {
                //                    val = Encoding.UTF8.GetString(b64_bytes);
                //                }
                //            }
                //            catch (FormatException)
                //            {
                //                continue;
                //            }
                //            params_dict[key] = val;
                //        }
                //    }
                //}

                string afterAt        = data.Substring(indexLastAt + 1);
                int    indexLastColon = afterAt.LastIndexOf(':');
                this.server_port = int.Parse(afterAt.Substring(indexLastColon + 1));
                this.server      = afterAt.Substring(0, indexLastColon);

                string beforeAt = data.Substring(0, indexLastAt);
                this.method = "";
                for (bool next = true; next;)
                {
                    string[] parts = beforeAt.Split(new[] { ':' }, 2);
                    if (parts.Length > 1)
                    {
                        try
                        {
                            Obfs.ObfsBase obfs = (Obfs.ObfsBase)Obfs.ObfsFactory.GetObfs(parts[0]);
                            if (obfs.GetObfs().ContainsKey(parts[0]))
                            {
                                int[] p = obfs.GetObfs()[parts[0]];
                                if (p[0] == 1)
                                {
                                    this.protocol = parts[0];
                                }
                                if (p[1] == 1)
                                {
                                    this.obfs = parts[0];
                                }
                            }
                            else
                            {
                                next = false;
                            }
                        }
                        catch
                        {
                            try
                            {
                                IEncryptor encryptor = EncryptorFactory.GetEncryptor(parts[0], "m");
                                encryptor.Dispose();
                                this.method = parts[0];
                                beforeAt    = parts[1];
                            }
                            catch
                            {
                            }
                            break;
                        }
                        beforeAt = parts[1];
                    }
                    else
                    {
                        break;
                    }
                }
                if (this.method.Length == 0)
                {
                    throw new FormatException();
                }
                this.password = beforeAt;
                //if (params_dict.ContainsKey("obfs"))
                //{
                //    this.obfsparam = params_dict["obfs"];
                //}
            }
            catch (IndexOutOfRangeException)
            {
                throw new FormatException();
            }
        }
Ejemplo n.º 6
0
        public Server(string ssURL) : this()
        {
            string[] r1     = Regex.Split(ssURL, "ss://", RegexOptions.IgnoreCase);
            string   base64 = r1[1].ToString();

            byte[] bytes = null;
            string data  = "";

            if (base64.LastIndexOf('@') > 0)
            {
                data = base64;
            }
            else
            {
                for (var i = 0; i < 3; i++)
                {
                    try
                    {
                        bytes = System.Convert.FromBase64String(base64);
                    }
                    catch (FormatException)
                    {
                        base64 += "=";
                    }
                }
                if (bytes != null)
                {
                    data = Encoding.UTF8.GetString(bytes);
                }
            }
            if (data.Length == 0)
            {
                throw new FormatException();
            }
            try
            {
                int indexLastAt       = data.LastIndexOf('@');
                int remarkIndexLastAt = data.IndexOf('#', indexLastAt);
                if (remarkIndexLastAt > 0)
                {
                    if (remarkIndexLastAt + 1 < data.Length)
                    {
                        this.remarks_base64 = data.Substring(remarkIndexLastAt + 1);
                    }
                    data = data.Substring(0, remarkIndexLastAt);
                }
                remarkIndexLastAt = data.IndexOf('/', indexLastAt);
                string param = "";
                if (remarkIndexLastAt > 0)
                {
                    if (remarkIndexLastAt + 1 < data.Length)
                    {
                        param = data.Substring(remarkIndexLastAt + 1);
                    }
                    data = data.Substring(0, remarkIndexLastAt);
                }

                string afterAt        = data.Substring(indexLastAt + 1);
                int    indexLastColon = afterAt.LastIndexOf(':');
                this.server_port = int.Parse(afterAt.Substring(indexLastColon + 1));
                this.server      = afterAt.Substring(0, indexLastColon);

                string   beforeAt = data.Substring(0, indexLastAt);
                string[] parts    = beforeAt.Split(new[] { ':' });
                this.method   = parts[parts.Length - 2];
                this.password = parts[parts.Length - 1];
                if (parts.Length >= 4)
                {
                    this.protocol = parts[parts.Length - 3];
                    this.obfs     = parts[parts.Length - 4];
                    if (param.Length > 0)
                    {
                        this.obfsparam = Encoding.UTF8.GetString(System.Convert.FromBase64String(param.Replace('-', '+').Replace('_', '/')));
                    }
                }
                else if (parts.Length >= 3)
                {
                    string part = parts[parts.Length - 3];
                    try
                    {
                        Obfs.ObfsBase obfs       = (Obfs.ObfsBase)Obfs.ObfsFactory.GetObfs(part);
                        int[]         properties = obfs.GetObfs()[part];
                        if (properties[0] > 0)
                        {
                            this.protocol = part;
                        }
                        else
                        {
                            this.obfs = part;
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
                throw new FormatException();
            }
        }