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()); }
// 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()); }
private static string punycode_encode(string unicode) { if (unicode.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } StringBuilder stringBuilder = new StringBuilder(unicode.Length); int num1 = 0; int num2 = 0; int startIndex = 0; while (num1 < unicode.Length) { num1 = unicode.IndexOfAny(IdnMapping.M_Dots, num2); if (num1 < 0) { num1 = unicode.Length; } if (num1 == num2) { if (num1 != unicode.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } break; } stringBuilder.Append("xn--"); bool flag = false; switch (CharUnicodeInfo.GetBidiCategory(unicode, num2)) { case BidiCategory.RightToLeft: case BidiCategory.RightToLeftArabic: flag = true; int index1 = num1 - 1; if (char.IsLowSurrogate(unicode, index1)) { --index1; } switch (CharUnicodeInfo.GetBidiCategory(unicode, index1)) { case BidiCategory.RightToLeft: case BidiCategory.RightToLeftArabic: break; default: throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } } int num3 = 0; for (int index2 = num2; index2 < num1; ++index2) { BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(unicode, index2); if (flag && bidiCategory == BidiCategory.LeftToRight) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (!flag && (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (IdnMapping.basic((uint)unicode[index2])) { stringBuilder.Append(IdnMapping.encode_basic(unicode[index2])); ++num3; } else if (char.IsSurrogatePair(unicode, index2)) { ++index2; } } int num4 = num3; if (num4 == num1 - num2) { stringBuilder.Remove(startIndex, "xn--".Length); } else { if (unicode.Length - num2 >= "xn--".Length && unicode.Substring(num2, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "unicode"); } int num5 = 0; if (num4 > 0) { stringBuilder.Append('-'); } int num6 = 128; int num7 = 0; int num8 = 72; while (num3 < num1 - num2) { int cTest = 134217727; int index2 = num2; while (index2 < num1) { int utf32 = char.ConvertToUtf32(unicode, index2); if (utf32 >= num6 && utf32 < cTest) { cTest = utf32; } index2 += IdnMapping.IsSupplementary(utf32) ? 2 : 1; } int delta = num7 + (cTest - num6) * (num3 - num5 + 1); int num9 = cTest; int index3 = num2; while (index3 < num1) { int utf32 = char.ConvertToUtf32(unicode, index3); if (utf32 < num9) { ++delta; } if (utf32 == num9) { int d = delta; int num10 = 36; while (true) { int num11 = num10 <= num8 ? 1 : (num10 >= num8 + 26 ? 26 : num10 - num8); if (d >= num11) { stringBuilder.Append(IdnMapping.encode_digit(num11 + (d - num11) % (36 - num11))); d = (d - num11) / (36 - num11); num10 += 36; } else { break; } } stringBuilder.Append(IdnMapping.encode_digit(d)); num8 = IdnMapping.adapt(delta, num3 - num5 + 1, num3 == num4); delta = 0; ++num3; if (IdnMapping.IsSupplementary(cTest)) { ++num3; ++num5; } } index3 += IdnMapping.IsSupplementary(utf32) ? 2 : 1; } num7 = delta + 1; num6 = num9 + 1; } } if (stringBuilder.Length - startIndex > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (num1 != unicode.Length) { stringBuilder.Append('.'); } num2 = num1 + 1; startIndex = stringBuilder.Length; } int length = stringBuilder.Length; int num12 = (int)byte.MaxValue; string str1 = unicode; int index4 = str1.Length - 1; int num13 = IdnMapping.IsDot(str1[index4]) ? 0 : 1; int num14 = num12 - num13; if (length > num14) { string key = "Argument_IdnBadNameSize"; object[] objArray = new object[1]; int index1 = 0; int num3 = (int)byte.MaxValue; string str2 = unicode; int index2 = str2.Length - 1; int num4 = IdnMapping.IsDot(str2[index2]) ? 0 : 1; // ISSUE: variable of a boxed type __Boxed <int> local = (ValueType)(num3 - num4); objArray[index1] = (object)local; throw new ArgumentException(Environment.GetResourceString(key, objArray), "unicode"); } return(stringBuilder.ToString()); }
// Token: 0x06002FE2 RID: 12258 RVA: 0x000B7924 File Offset: 0x000B5B24 private static string punycode_encode(string unicode) { if (unicode.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } StringBuilder stringBuilder = new StringBuilder(unicode.Length); int i = 0; int num = 0; int num2 = 0; while (i < unicode.Length) { i = unicode.IndexOfAny(IdnMapping.M_Dots, num); if (i < 0) { i = unicode.Length; } if (i == num) { if (i != unicode.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } break; } else { stringBuilder.Append("xn--"); bool flag = false; BidiCategory bidiCategory = CharUnicodeInfo.GetBidiCategory(unicode, num); if (bidiCategory == BidiCategory.RightToLeft || bidiCategory == BidiCategory.RightToLeftArabic) { flag = true; int num3 = i - 1; if (char.IsLowSurrogate(unicode, num3)) { num3--; } bidiCategory = CharUnicodeInfo.GetBidiCategory(unicode, num3); if (bidiCategory != BidiCategory.RightToLeft && bidiCategory != BidiCategory.RightToLeftArabic) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } } int j = 0; for (int k = num; k < i; k++) { BidiCategory bidiCategory2 = CharUnicodeInfo.GetBidiCategory(unicode, k); if (flag && bidiCategory2 == BidiCategory.LeftToRight) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (!flag && (bidiCategory2 == BidiCategory.RightToLeft || bidiCategory2 == BidiCategory.RightToLeftArabic)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadBidi"), "unicode"); } if (IdnMapping.basic((uint)unicode[k])) { stringBuilder.Append(IdnMapping.encode_basic(unicode[k])); j++; } else if (char.IsSurrogatePair(unicode, k)) { k++; } } int num4 = j; if (num4 == i - num) { stringBuilder.Remove(num2, "xn--".Length); } else { if (unicode.Length - num >= "xn--".Length && unicode.Substring(num, "xn--".Length).Equals("xn--", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "unicode"); } int num5 = 0; if (num4 > 0) { stringBuilder.Append('-'); } int num6 = 128; int num7 = 0; int num8 = 72; while (j < i - num) { int num9 = 134217727; int num10; for (int l = num; l < i; l += (IdnMapping.IsSupplementary(num10) ? 2 : 1)) { num10 = char.ConvertToUtf32(unicode, l); if (num10 >= num6 && num10 < num9) { num9 = num10; } } num7 += (num9 - num6) * (j - num5 + 1); num6 = num9; for (int l = num; l < i; l += (IdnMapping.IsSupplementary(num10) ? 2 : 1)) { num10 = char.ConvertToUtf32(unicode, l); if (num10 < num6) { num7++; } if (num10 == num6) { int num11 = num7; int num12 = 36; for (;;) { int num13 = (num12 <= num8) ? 1 : ((num12 >= num8 + 26) ? 26 : (num12 - num8)); if (num11 < num13) { break; } stringBuilder.Append(IdnMapping.encode_digit(num13 + (num11 - num13) % (36 - num13))); num11 = (num11 - num13) / (36 - num13); num12 += 36; } stringBuilder.Append(IdnMapping.encode_digit(num11)); num8 = IdnMapping.adapt(num7, j - num5 + 1, j == num4); num7 = 0; j++; if (IdnMapping.IsSupplementary(num9)) { j++; num5++; } } } num7++; num6++; } } if (stringBuilder.Length - num2 > 63) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadLabelSize"), "unicode"); } if (i != unicode.Length) { stringBuilder.Append('.'); } num = i + 1; num2 = stringBuilder.Length; } } if (stringBuilder.Length > 255 - (IdnMapping.IsDot(unicode[unicode.Length - 1]) ? 0 : 1)) { throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadNameSize", new object[] { 255 - (IdnMapping.IsDot(unicode[unicode.Length - 1]) ? 0 : 1) }), "unicode"); } return(stringBuilder.ToString()); }