コード例 #1
0
ファイル: idnmapping.cs プロジェクト: wwkkww1983/ZJCredit
        private static string punycode_decode(string ascii)
        {
            if (ascii.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
            }
            int    length1 = ascii.Length;
            int    num1    = (int)byte.MaxValue;
            string str1    = ascii;
            int    index1  = str1.Length - 1;
            int    num2    = IdnMapping.IsDot(str1[index1]) ? 0 : 1;
            int    num3    = num1 - num2;

            if (length1 > num3)
            {
                string   key      = "Argument_IdnBadNameSize";
                object[] objArray = new object[1];
                int      index2   = 0;
                int      num4     = (int)byte.MaxValue;
                string   str2     = ascii;
                int      index3   = str2.Length - 1;
                int      num5     = IdnMapping.IsDot(str2[index3]) ? 0 : 1;
                // ISSUE: variable of a boxed type
                __Boxed <int> local = (ValueType)(num4 - num5);
                objArray[index2] = (object)local;
                throw new ArgumentException(Environment.GetResourceString(key, objArray), "ascii");
            }
            StringBuilder stringBuilder1 = new StringBuilder(ascii.Length);
            int           num6           = 0;
            int           startIndex     = 0;
            int           index4         = 0;

            while (num6 < ascii.Length)
            {
                num6 = ascii.IndexOf('.', startIndex);
                if (num6 < 0 || num6 > ascii.Length)
                {
                    num6 = ascii.Length;
                }
                if (num6 == startIndex)
                {
                    if (num6 != ascii.Length)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
                    }
                    break;
                }
                if (num6 - startIndex > 63)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
                }
                if (ascii.Length < "xn--".Length + startIndex || !ascii.Substring(startIndex, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase))
                {
                    stringBuilder1.Append(ascii.Substring(startIndex, num6 - startIndex));
                }
                else
                {
                    startIndex += "xn--".Length;
                    int num4 = ascii.LastIndexOf('-', num6 - 1);
                    if (num4 == num6 - 1)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                    }
                    int num5;
                    if (num4 <= startIndex)
                    {
                        num5 = 0;
                    }
                    else
                    {
                        num5 = num4 - startIndex;
                        for (int index2 = startIndex; index2 < startIndex + num5; ++index2)
                        {
                            if ((int)ascii[index2] > (int)sbyte.MaxValue)
                            {
                                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                            }
                            stringBuilder1.Append((int)ascii[index2] < 65 || (int)ascii[index2] > 90 ? ascii[index2] : (char)((int)ascii[index2] - 65 + 97));
                        }
                    }
                    int num7  = startIndex + (num5 > 0 ? num5 + 1 : 0);
                    int num8  = 128;
                    int num9  = 72;
                    int num10 = 0;
                    int num11 = 0;
label_49:
                    while (num7 < num6)
                    {
                        int num12 = num10;
                        int num13 = 1;
                        int num14 = 36;
                        while (num7 < num6)
                        {
                            int num15 = IdnMapping.decode_digit(ascii[num7++]);
                            if (num15 > (134217727 - num10) / num13)
                            {
                                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                            }
                            num10 += num15 * num13;
                            int num16 = num14 <= num9 ? 1 : (num14 >= num9 + 26 ? 26 : num14 - num9);
                            if (num15 >= num16)
                            {
                                if (num13 > 134217727 / (36 - num16))
                                {
                                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                }
                                num13 *= 36 - num16;
                                num14 += 36;
                            }
                            else
                            {
                                num9 = IdnMapping.adapt(num10 - num12, stringBuilder1.Length - index4 - num11 + 1, num12 == 0);
                                if (num10 / (stringBuilder1.Length - index4 - num11 + 1) > 134217727 - num8)
                                {
                                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                }
                                num8 += num10 / (stringBuilder1.Length - index4 - num11 + 1);
                                int num17 = num10 % (stringBuilder1.Length - index4 - num11 + 1);
                                if (num8 < 0 || num8 > 1114111 || num8 >= 55296 && num8 <= 57343)
                                {
                                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                }
                                string str2 = char.ConvertFromUtf32(num8);
                                int    index2;
                                if (num11 > 0)
                                {
                                    int num18 = num17;
                                    index2 = index4;
                                    while (num18 > 0)
                                    {
                                        if (index2 >= stringBuilder1.Length)
                                        {
                                            throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                        }
                                        if (char.IsSurrogate(stringBuilder1[index2]))
                                        {
                                            ++index2;
                                        }
                                        --num18;
                                        ++index2;
                                    }
                                }
                                else
                                {
                                    index2 = index4 + num17;
                                }
                                stringBuilder1.Insert(index2, str2);
                                if (IdnMapping.IsSupplementary(num8))
                                {
                                    ++num11;
                                }
                                num10 = num17 + 1;
                                goto label_49;
                            }
                        }
                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                    }
                    bool         flag         = false;
                    BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder1.ToString(), index4);
                    switch (bidiCategory)
                    {
                    case BidiCategory.RightToLeft:
                    case BidiCategory.RightToLeftArabic:
                        flag = true;
                        break;
                    }
                    for (int index2 = index4; index2 < stringBuilder1.Length; ++index2)
                    {
                        if (!char.IsLowSurrogate(stringBuilder1.ToString(), index2))
                        {
                            bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder1.ToString(), index2);
                            if (flag && bidiCategory == BidiCategory.LeftToRight || !flag && (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic))
                            {
                                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii");
                            }
                        }
                    }
                    if (flag && bidiCategory != BidiCategory.RightToLeft && bidiCategory != BidiCategory.RightToLeftArabic)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii");
                    }
                }
                if (num6 - startIndex > 63)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
                }
                if (num6 != ascii.Length)
                {
                    stringBuilder1.Append('.');
                }
                startIndex = num6 + 1;
                index4     = stringBuilder1.Length;
            }
            int           length2        = stringBuilder1.Length;
            int           num19          = (int)byte.MaxValue;
            StringBuilder stringBuilder2 = stringBuilder1;
            int           index5         = stringBuilder2.Length - 1;
            int           num20          = IdnMapping.IsDot(stringBuilder2[index5]) ? 0 : 1;
            int           num21          = num19 - num20;

            if (length2 > num21)
            {
                string        key            = "Argument_IdnBadNameSize";
                object[]      objArray       = new object[1];
                int           index2         = 0;
                int           num4           = (int)byte.MaxValue;
                StringBuilder stringBuilder3 = stringBuilder1;
                int           index3         = stringBuilder3.Length - 1;
                int           num5           = IdnMapping.IsDot(stringBuilder3[index3]) ? 0 : 1;
                // ISSUE: variable of a boxed type
                __Boxed <int> local = (ValueType)(num4 - num5);
                objArray[index2] = (object)local;
                throw new ArgumentException(Environment.GetResourceString(key, objArray), "ascii");
            }
            return(stringBuilder1.ToString());
        }
コード例 #2
0
        // Token: 0x06002FE3 RID: 12259 RVA: 0x000B7D34 File Offset: 0x000B5F34
        private static string punycode_decode(string ascii)
        {
            if (ascii.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
            }
            if (ascii.Length > 255 - (IdnMapping.IsDot(ascii[ascii.Length - 1]) ? 0 : 1))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", new object[]
                {
                    255 - (IdnMapping.IsDot(ascii[ascii.Length - 1]) ? 0 : 1)
                }), "ascii");
            }
            StringBuilder stringBuilder = new StringBuilder(ascii.Length);
            int           i             = 0;
            int           num           = 0;
            int           num2          = 0;

            while (i < ascii.Length)
            {
                i = ascii.IndexOf('.', num);
                if (i < 0 || i > ascii.Length)
                {
                    i = ascii.Length;
                }
                if (i == num)
                {
                    if (i != ascii.Length)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
                    }
                    break;
                }
                else
                {
                    if (i - num > 63)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
                    }
                    if (ascii.Length < "xn--".Length + num || !ascii.Substring(num, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase))
                    {
                        stringBuilder.Append(ascii.Substring(num, i - num));
                    }
                    else
                    {
                        num += "xn--".Length;
                        int num3 = ascii.LastIndexOf('-', i - 1);
                        if (num3 == i - 1)
                        {
                            throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                        }
                        int num4;
                        if (num3 <= num)
                        {
                            num4 = 0;
                        }
                        else
                        {
                            num4 = num3 - num;
                            for (int j = num; j < num + num4; j++)
                            {
                                if (ascii[j] > '\u007f')
                                {
                                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                }
                                stringBuilder.Append((ascii[j] >= 'A' && ascii[j] <= 'Z') ? (ascii[j] - 'A' + 'a') : ascii[j]);
                            }
                        }
                        int k    = num + ((num4 > 0) ? (num4 + 1) : 0);
                        int num5 = 128;
                        int num6 = 72;
                        int num7 = 0;
                        int num8 = 0;
IL_40D:
                        while (k < i)
                        {
                            int num9  = num7;
                            int num10 = 1;
                            int num11 = 36;
                            while (k < i)
                            {
                                int num12 = IdnMapping.decode_digit(ascii[k++]);
                                if (num12 > (134217727 - num7) / num10)
                                {
                                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                }
                                num7 += num12 * num10;
                                int num13 = (num11 <= num6) ? 1 : ((num11 >= num6 + 26) ? 26 : (num11 - num6));
                                if (num12 >= num13)
                                {
                                    if (num10 > 134217727 / (36 - num13))
                                    {
                                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                    }
                                    num10 *= 36 - num13;
                                    num11 += 36;
                                }
                                else
                                {
                                    num6 = IdnMapping.adapt(num7 - num9, stringBuilder.Length - num2 - num8 + 1, num9 == 0);
                                    if (num7 / (stringBuilder.Length - num2 - num8 + 1) > 134217727 - num5)
                                    {
                                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                    }
                                    num5 += num7 / (stringBuilder.Length - num2 - num8 + 1);
                                    num7 %= stringBuilder.Length - num2 - num8 + 1;
                                    if (num5 < 0 || num5 > 1114111 || (num5 >= 55296 && num5 <= 57343))
                                    {
                                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                    }
                                    string value = char.ConvertFromUtf32(num5);
                                    int    num14;
                                    if (num8 > 0)
                                    {
                                        int l = num7;
                                        num14 = num2;
                                        while (l > 0)
                                        {
                                            if (num14 >= stringBuilder.Length)
                                            {
                                                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                                            }
                                            if (char.IsSurrogate(stringBuilder[num14]))
                                            {
                                                num14++;
                                            }
                                            l--;
                                            num14++;
                                        }
                                    }
                                    else
                                    {
                                        num14 = num2 + num7;
                                    }
                                    stringBuilder.Insert(num14, value);
                                    if (IdnMapping.IsSupplementary(num5))
                                    {
                                        num8++;
                                    }
                                    num7++;
                                    goto IL_40D;
                                }
                            }
                            throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii");
                        }
                        bool         flag         = false;
                        BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder.ToString(), num2);
                        if (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic)
                        {
                            flag = true;
                        }
                        for (int m = num2; m < stringBuilder.Length; m++)
                        {
                            if (!char.IsLowSurrogate(stringBuilder.ToString(), m))
                            {
                                bidiCategory = CharUnicodeInfo.GetBidiCategory(stringBuilder.ToString(), m);
                                if ((flag && bidiCategory == BidiCategory.LeftToRight) || (!flag && (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic)))
                                {
                                    throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii");
                                }
                            }
                        }
                        if (flag && bidiCategory != BidiCategory.RightToLeft && bidiCategory != BidiCategory.RightToLeftArabic)
                        {
                            throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "ascii");
                        }
                    }
                    if (i - num > 63)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "ascii");
                    }
                    if (i != ascii.Length)
                    {
                        stringBuilder.Append('.');
                    }
                    num  = i + 1;
                    num2 = stringBuilder.Length;
                }
            }
            if (stringBuilder.Length > 255 - (IdnMapping.IsDot(stringBuilder[stringBuilder.Length - 1]) ? 0 : 1))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", new object[]
                {
                    255 - (IdnMapping.IsDot(stringBuilder[stringBuilder.Length - 1]) ? 0 : 1)
                }), "ascii");
            }
            return(stringBuilder.ToString());
        }