// Token: 0x06002B0B RID: 11019 RVA: 0x0009FB40 File Offset: 0x0009DD40 public static byte[] DecodeHexString(string hexString) { if (hexString == null) { throw new ArgumentNullException("hexString"); } bool flag = false; int i = 0; int num = hexString.Length; if (num >= 2 && hexString[0] == '0' && (hexString[1] == 'x' || hexString[1] == 'X')) { num = hexString.Length - 2; i = 2; } if (num % 2 != 0 && num % 3 != 2) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHexFormat")); } byte[] array; if (num >= 3 && hexString[i + 2] == ' ') { flag = true; array = new byte[num / 3 + 1]; } else { array = new byte[num / 2]; } int num2 = 0; while (i < hexString.Length) { int num3 = Hex.ConvertHexDigit(hexString[i]); int num4 = Hex.ConvertHexDigit(hexString[i + 1]); array[num2] = (byte)(num4 | num3 << 4); if (flag) { i++; } i += 2; num2++; } return(array); }
// Converts %XX and %uYYYY to the actual characters (I.e. Unesacpes any escape characters present in the URL) private String UnescapeURL(String url) { StringBuilder intermediate = StringBuilderCache.Acquire(url.Length); int Rindex = 0; // index into temp that gives the rest of the string to be processed int index; int braIndex = -1; int ketIndex = -1; braIndex = url.IndexOf('[', Rindex); if (braIndex != -1) { ketIndex = url.IndexOf(']', braIndex); } do { index = url.IndexOf('%', Rindex); if (index == -1) { intermediate = intermediate.Append(url, Rindex, (url.Length - Rindex)); break; } // if we hit a '%' in the middle of an IPv6 address, dont process that if (index > braIndex && index < ketIndex) { intermediate = intermediate.Append(url, Rindex, (ketIndex - Rindex + 1)); Rindex = ketIndex + 1; continue; } if (url.Length - index < 2) // Check that there is at least 1 char after the '%' { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } if (url[index + 1] == 'u' || url[index + 1] == 'U') { if (url.Length - index < 6) // example: "%u004d" is 6 chars long { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } // We have a unicode character specified in hex try { char c = (char)(Hex.ConvertHexDigit(url[index + 2]) << 12 | Hex.ConvertHexDigit(url[index + 3]) << 8 | Hex.ConvertHexDigit(url[index + 4]) << 4 | Hex.ConvertHexDigit(url[index + 5])); intermediate = intermediate.Append(url, Rindex, index - Rindex); intermediate = intermediate.Append(c); } catch (ArgumentException) // Hex.ConvertHexDigit can throw an "out of range" ArgumentException { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } Rindex = index + 6; //update the 'seen' length } else { // we have a hex character. if (url.Length - index < 3) // example: "%4d" is 3 chars long { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } try { char c = (char)(Hex.ConvertHexDigit(url[index + 1]) << 4 | Hex.ConvertHexDigit(url[index + 2])); intermediate = intermediate.Append(url, Rindex, index - Rindex); intermediate = intermediate.Append(c); } catch (ArgumentException) // Hex.ConvertHexDigit can throw an "out of range" ArgumentException { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } Rindex = index + 3; // update the 'seen' length } }while (true); return(StringBuilderCache.GetStringAndRelease(intermediate)); }
private string UnescapeURL(string url) { StringBuilder stringBuilder = StringBuilderCache.Acquire(url.Length); int startIndex1 = 0; int num1 = -1; int startIndex2 = url.IndexOf('[', startIndex1); if (startIndex2 != -1) { num1 = url.IndexOf(']', startIndex2); } while (true) { int num2 = url.IndexOf('%', startIndex1); if (num2 != -1) { if (num2 > startIndex2 && num2 < num1) { stringBuilder = stringBuilder.Append(url, startIndex1, num1 - startIndex1 + 1); startIndex1 = num1 + 1; } else if (url.Length - num2 >= 2) { if ((int)url[num2 + 1] == 117 || (int)url[num2 + 1] == 85) { if (url.Length - num2 >= 6) { try { char ch = (char)(Hex.ConvertHexDigit(url[num2 + 2]) << 12 | Hex.ConvertHexDigit(url[num2 + 3]) << 8 | Hex.ConvertHexDigit(url[num2 + 4]) << 4 | Hex.ConvertHexDigit(url[num2 + 5])); stringBuilder = stringBuilder.Append(url, startIndex1, num2 - startIndex1).Append(ch); } catch (ArgumentException ex) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } startIndex1 = num2 + 6; } else { goto label_10; } } else if (url.Length - num2 >= 3) { try { char ch = (char)(Hex.ConvertHexDigit(url[num2 + 1]) << 4 | Hex.ConvertHexDigit(url[num2 + 2])); stringBuilder = stringBuilder.Append(url, startIndex1, num2 - startIndex1).Append(ch); } catch (ArgumentException ex) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } startIndex1 = num2 + 3; } else { goto label_15; } } else { goto label_7; } } else { break; } } return(StringBuilderCache.GetStringAndRelease(stringBuilder.Append(url, startIndex1, url.Length - startIndex1))); label_7: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); label_10: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); label_15: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); }
void ParseString(String url, bool parsed) { if (url == null) { throw new ArgumentNullException("url"); } if (url.Length == 0) { throw new FormatException(Environment.GetResourceString("Format_StringZeroLength")); } int index; String temp = url; String intermediate = ""; // If there are any hex or unicode characters in the url, translate those // into the proper character. if (!parsed) { do { index = temp.IndexOf('%'); if (index == -1) { intermediate += temp; break; } if (temp.Length - index < 1) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } if (temp[index + 1] == 'u' || temp[index + 1] == 'U') { if (temp.Length - index < 5) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } // We have a unicode character specified in hex char c = (char)(Hex.ConvertHexDigit(temp[index + 2]) << 12 | Hex.ConvertHexDigit(temp[index + 3]) << 8 | Hex.ConvertHexDigit(temp[index + 4]) << 4 | Hex.ConvertHexDigit(temp[index + 5])); intermediate += temp.Substring(0, index) + c; temp = temp.Substring(index + 6); } else { // we have a hex character. if (temp.Length - index < 2) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } char c = (char)(Hex.ConvertHexDigit(temp[index + 1]) << 4 | Hex.ConvertHexDigit(temp[index + 2])); intermediate += temp.Substring(0, index) + c; temp = temp.Substring(index + 3); } } while (true); temp = intermediate; url = temp; } // Search for the end of the protocol info and grab the actual protocol string // ex. http://www.microsoft.com/complus would have a protocol string of http index = temp.IndexOf(':'); if (index == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } else if (index != -1 && temp.Length > index + 1) { if (String.Compare(temp.Substring(0, index), "file", true, CultureInfo.InvariantCulture) == 0) { m_protocol = "file"; temp = temp.Substring(index + 1); } else if (temp[index + 1] != '\\') { if (temp.Length > index + 2 && temp[index + 1] == '/' && temp[index + 2] == '/') { m_protocol = url.Substring(0, index); for (int i = 0; i < m_protocol.Length; ++i) { char c = m_protocol[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { continue; } else { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } } temp = url.Substring(index + 3); } else { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } } else { m_protocol = m_defaultProtocol; temp = url; } } else { m_protocol = m_defaultProtocol; temp = url; } // Parse out the site info. // In the general case we parse of the site and create a SiteString out of it // (which supports our wildcarding scheme). In the case of files we don't support // wildcarding and furthermore SiteString doesn't like ':' and '|' which can appear // in file urls so we just keep that info in a separate string and set the // SiteString to null. // // ex. http://www.microsoft.com/complus -> m_siteString = "www.microsoft.com" m_localSite = null // ex. file:///c:/complus/mscorlib.dll -> m_siteString = null m_localSite = "c:" // ex. file:///c|/complus/mscorlib.dll -> m_siteString = null m_localSite = "c:" bool fileProtocol; if (String.Compare(m_protocol, "file", true, CultureInfo.InvariantCulture) == 0) { index = temp.IndexOfAny(m_fileEnd); fileProtocol = true; if (String.Compare(temp, 0, "\\\\?\\", 0, 4, true, CultureInfo.InvariantCulture) == 0 || String.Compare(temp, 0, "\\\\.\\", 0, 4, true, CultureInfo.InvariantCulture) == 0) { temp = temp.Substring(4); } } else { index = temp.IndexOfAny(m_siteEnd); fileProtocol = false; } temp = temp.Replace('\\', '/'); // If we find a '/' in the first character of the string and we are using the 'file' // protocol, just ignore it. if (fileProtocol) { // Remove any '/' before the local site information. // ex. file://///d:/complus // ex. file:///d:/complus temp = temp.TrimStart(new char[] { '/' }); index = temp.IndexOfAny(m_fileEnd, 0); if (index != -1 && ((index == 2 && temp[index - 1] != ':' && temp[index - 1] != '|') || index != 2) && index != temp.Length - 1) { int tempIndex = temp.Substring(index + 1).IndexOfAny(m_fileEnd); if (tempIndex != -1) { index = tempIndex + index + 1; } else { index = -1; } } } // Check if there is a port number and parse that out. if (index != -1 && temp[index] == ':') { int tempIndex = temp.IndexOf('/'); if (tempIndex == -1) { m_port = Int32.Parse(temp.Substring(index + 1)); if (m_port < 0) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } temp = temp.Substring(0, index); index = -1; } else { m_port = Int32.Parse(temp.Substring(index + 1, tempIndex - index - 1)); temp = temp.Substring(0, index) + temp.Substring(tempIndex); } } if (index == -1) { if (fileProtocol) { String localSite = temp; int i; bool spacesAllowed; if (localSite[0] == '\\' && localSite[1] == '\\') { spacesAllowed = true; i = 2; } else { i = 0; spacesAllowed = false; } bool useSmallCharToUpper = true; for (; i < localSite.Length; ++i) { char c = localSite[i]; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c == '-') || (c == '/') || (c == ':') || (c == '|') || (c == '.') || (c == '*') || (c == '$') || (spacesAllowed && c == ' ')) { continue; } else { useSmallCharToUpper = false; break; } } if (useSmallCharToUpper) { localSite = String.SmallCharToUpper(localSite); } else { localSite = localSite.ToUpper(CultureInfo.InvariantCulture); } m_siteString = null; m_localSite = new LocalSiteString(localSite); if (localSite[localSite.Length - 1] == '*') { m_directory = new DirectoryString("*", false); } else { m_directory = new DirectoryString(); } } else { m_localSite = null; m_siteString = new SiteString(temp); m_directory = new DirectoryString(); } } else { String site = temp.Substring(0, index); if (fileProtocol) { String localSite = site; int i; bool spacesAllowed; if (localSite[0] == '\\' && localSite[1] == '\\') { spacesAllowed = true; i = 2; } else { i = 0; spacesAllowed = false; } bool useSmallCharToUpper = true; for (; i < localSite.Length; ++i) { char c = localSite[i]; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '-' && c <= ':') || (c == '|') || (c == '$') || (c == '_') || (spacesAllowed && c == ' ')) { continue; } else { useSmallCharToUpper = false; break; } } if (useSmallCharToUpper) { localSite = String.SmallCharToUpper(localSite); } else { localSite = localSite.ToUpper(CultureInfo.InvariantCulture); } m_siteString = null; m_localSite = new LocalSiteString(localSite); } else { m_localSite = null; m_siteString = new SiteString(site); } // Finally we parse out the directory string // ex. http://www.microsoft.com/complus -> m_directory = "complus" String directoryString = temp.Substring(index + 1); if (directoryString.Length == 0) { m_directory = new DirectoryString(); } else { m_directory = new DirectoryString(directoryString, fileProtocol); } } String builtUrl; if (fileProtocol) { String directory = m_directory.ToString(); String localSite = m_localSite.ToString(); builtUrl = "file://" + localSite; if (directory != null && !directory.Equals("") && (!directory.Equals("*") || localSite.IndexOf('*') == -1)) { builtUrl += "/" + directory; } } else { builtUrl = m_protocol + "://" + m_siteString.ToString(); if (m_port != -1) { builtUrl += ":" + m_port; } builtUrl += "/" + m_directory.ToString(); } m_fullurl = builtUrl; }
// Token: 0x06002B5E RID: 11102 RVA: 0x000A1688 File Offset: 0x0009F888 private string UnescapeURL(string url) { StringBuilder stringBuilder = StringBuilderCache.Acquire(url.Length); int num = 0; int num2 = -1; int num3 = -1; num2 = url.IndexOf('[', num); if (num2 != -1) { num3 = url.IndexOf(']', num2); } for (;;) { int num4 = url.IndexOf('%', num); if (num4 == -1) { break; } if (num4 > num2 && num4 < num3) { stringBuilder = stringBuilder.Append(url, num, num3 - num + 1); num = num3 + 1; } else { if (url.Length - num4 < 2) { goto Block_5; } if (url[num4 + 1] == 'u' || url[num4 + 1] == 'U') { if (url.Length - num4 < 6) { goto Block_7; } try { char value = (char)(Hex.ConvertHexDigit(url[num4 + 2]) << 12 | Hex.ConvertHexDigit(url[num4 + 3]) << 8 | Hex.ConvertHexDigit(url[num4 + 4]) << 4 | Hex.ConvertHexDigit(url[num4 + 5])); stringBuilder = stringBuilder.Append(url, num, num4 - num); stringBuilder = stringBuilder.Append(value); } catch (ArgumentException) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } num = num4 + 6; } else { if (url.Length - num4 < 3) { goto Block_9; } try { char value2 = (char)(Hex.ConvertHexDigit(url[num4 + 1]) << 4 | Hex.ConvertHexDigit(url[num4 + 2])); stringBuilder = stringBuilder.Append(url, num, num4 - num); stringBuilder = stringBuilder.Append(value2); } catch (ArgumentException) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } num = num4 + 3; } } } stringBuilder = stringBuilder.Append(url, num, url.Length - num); return(StringBuilderCache.GetStringAndRelease(stringBuilder)); Block_5: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); Block_7: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); Block_9: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); }
private string UnescapeURL(string url) { StringBuilder builder = new StringBuilder(url.Length); int startIndex = 0; int index = -1; int num4 = -1; index = url.IndexOf('[', startIndex); if (index != -1) { num4 = url.IndexOf(']', index); } while (true) { int num2 = url.IndexOf('%', startIndex); if (num2 == -1) { return(builder.Append(url, startIndex, url.Length - startIndex).ToString()); } if ((num2 > index) && (num2 < num4)) { builder = builder.Append(url, startIndex, (num4 - startIndex) + 1); startIndex = num4 + 1; } else { if ((url.Length - num2) < 2) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } if ((url[num2 + 1] == 'u') || (url[num2 + 1] == 'U')) { if ((url.Length - num2) < 6) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } try { char ch = (char)((((Hex.ConvertHexDigit(url[num2 + 2]) << 12) | (Hex.ConvertHexDigit(url[num2 + 3]) << 8)) | (Hex.ConvertHexDigit(url[num2 + 4]) << 4)) | Hex.ConvertHexDigit(url[num2 + 5])); builder = builder.Append(url, startIndex, num2 - startIndex).Append(ch); } catch (ArgumentException) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } startIndex = num2 + 6; } else { if ((url.Length - num2) < 3) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } try { char ch2 = (char)((Hex.ConvertHexDigit(url[num2 + 1]) << 4) | Hex.ConvertHexDigit(url[num2 + 2])); builder = builder.Append(url, startIndex, num2 - startIndex).Append(ch2); } catch (ArgumentException) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } startIndex = num2 + 3; } } } }
void ParseString(String url, bool parsed) { if (url == null) { throw new ArgumentNullException("url"); } if (url.Length == 0) { throw new FormatException(Environment.GetResourceString("Format_StringZeroLength")); } int index; String temp = url; String intermediate = ""; // If there are any hex or unicode characters in the url, translate those // into the proper character. if (!parsed) { do { index = temp.IndexOf('%'); if (index == -1) { intermediate += temp; break; } if (temp.Length - index < 1) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } if (temp[index + 1] == 'u') { if (temp.Length - index < 5) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } // We have a unicode character specified in hex char c = (char)(Hex.ConvertHexDigit(temp[index + 2]) << 12 | Hex.ConvertHexDigit(temp[index + 3]) << 8 | Hex.ConvertHexDigit(temp[index + 4]) << 4 | Hex.ConvertHexDigit(temp[index + 5])); intermediate += temp.Substring(0, index) + c; temp = temp.Substring(index + 6); } else { // we have a hex character. if (temp.Length - index < 2) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } char c = (char)(Hex.ConvertHexDigit(temp[index + 1]) << 4 | Hex.ConvertHexDigit(temp[index + 2])); intermediate += temp.Substring(0, index) + c; temp = temp.Substring(index + 3); } } while (true); temp = intermediate; url = temp; } // Search for the end of the protocol info and grab the actual protocol string // ex. http://www.microsoft.com/complus would have a protocol string of http index = temp.IndexOf(':'); if (index == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } else if (index != -1 && temp.Length > index + 1) { if (String.Compare(temp.Substring(0, index), "file", true, CultureInfo.InvariantCulture) == 0) { m_protocol = "file"; temp = temp.Substring(index + 1); } else if (temp[index + 1] != '\\') { if (temp.Length > index + 2 && #if !PLATFORM_UNIX temp[index + 1] == '/' && temp[index + 2] == '/') #else // UNIX style "file:/home/me" is allowed, so account for that temp[index + 1] == '/') #endif // !PLATFORM_UNIX { m_protocol = url.Substring(0, index); for (int i = 0; i < m_protocol.Length; ++i) { char c = m_protocol[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { continue; } else { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } } #if !PLATFORM_UNIX temp = url.Substring(index + 3); #else // In UNIX, we don't know how many characters we'll have to skip past. // Skip past \, /, and : // for (int j = index; j < url.Length; j++) { if (url[j] != '\\' && url[j] != '/' && url[j] != ':') { index = j; break; } } if (index < url.Length) { temp = url.Substring(index); } else { temp = url.Substring(m_protocol.Length); } #endif // !PLATFORM_UNIX } else { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUrl")); } } else { m_protocol = m_defaultProtocol; temp = url; } }