Files
2026-06-04 11:42:34 +02:00

1424 lines
34 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
namespace Mono.Security
{
// Token: 0x020000EB RID: 235
internal class Uri
{
// Token: 0x06000B9A RID: 2970 RVA: 0x000336F0 File Offset: 0x000318F0
public Uri(string uriString)
: this(uriString, false)
{
}
// Token: 0x06000B9B RID: 2971 RVA: 0x000336FC File Offset: 0x000318FC
public Uri(string uriString, bool dontEscape)
{
this.scheme = string.Empty;
this.host = string.Empty;
this.port = -1;
this.path = string.Empty;
this.query = string.Empty;
this.fragment = string.Empty;
this.userinfo = string.Empty;
this.reduce = true;
base..ctor();
this.userEscaped = dontEscape;
this.source = uriString;
this.Parse();
}
// Token: 0x06000B9C RID: 2972 RVA: 0x00033774 File Offset: 0x00031974
public Uri(string uriString, bool dontEscape, bool reduce)
{
this.scheme = string.Empty;
this.host = string.Empty;
this.port = -1;
this.path = string.Empty;
this.query = string.Empty;
this.fragment = string.Empty;
this.userinfo = string.Empty;
this.reduce = true;
base..ctor();
this.userEscaped = dontEscape;
this.source = uriString;
this.reduce = reduce;
this.Parse();
}
// Token: 0x06000B9D RID: 2973 RVA: 0x000337F4 File Offset: 0x000319F4
public Uri(Uri baseUri, string relativeUri)
: this(baseUri, relativeUri, false)
{
}
// Token: 0x06000B9E RID: 2974 RVA: 0x00033800 File Offset: 0x00031A00
public Uri(Uri baseUri, string relativeUri, bool dontEscape)
{
this.scheme = string.Empty;
this.host = string.Empty;
this.port = -1;
this.path = string.Empty;
this.query = string.Empty;
this.fragment = string.Empty;
this.userinfo = string.Empty;
this.reduce = true;
base..ctor();
if (baseUri == null)
{
throw new NullReferenceException("baseUri");
}
this.userEscaped = dontEscape;
if (relativeUri == null)
{
throw new NullReferenceException("relativeUri");
}
if (relativeUri.StartsWith("\\\\"))
{
this.source = relativeUri;
this.Parse();
return;
}
int num = relativeUri.IndexOf(':');
if (num != -1)
{
int num2 = relativeUri.IndexOfAny(new char[] { '/', '\\', '?' });
if (num2 > num || num2 < 0)
{
this.source = relativeUri;
this.Parse();
return;
}
}
this.scheme = baseUri.scheme;
this.host = baseUri.host;
this.port = baseUri.port;
this.userinfo = baseUri.userinfo;
this.isUnc = baseUri.isUnc;
this.isUnixFilePath = baseUri.isUnixFilePath;
this.isOpaquePart = baseUri.isOpaquePart;
if (relativeUri == string.Empty)
{
this.path = baseUri.path;
this.query = baseUri.query;
this.fragment = baseUri.fragment;
return;
}
num = relativeUri.IndexOf('#');
if (num != -1)
{
this.fragment = relativeUri.Substring(num);
relativeUri = relativeUri.Substring(0, num);
}
num = relativeUri.IndexOf('?');
if (num != -1)
{
this.query = relativeUri.Substring(num);
if (!this.userEscaped)
{
this.query = Uri.EscapeString(this.query);
}
relativeUri = relativeUri.Substring(0, num);
}
if (relativeUri.Length > 0 && relativeUri[0] == '/')
{
if (relativeUri.Length > 1 && relativeUri[1] == '/')
{
this.source = this.scheme + ':' + relativeUri;
this.Parse();
return;
}
this.path = relativeUri;
if (!this.userEscaped)
{
this.path = Uri.EscapeString(this.path);
}
return;
}
else
{
this.path = baseUri.path;
if (relativeUri.Length > 0 || this.query.Length > 0)
{
num = this.path.LastIndexOf('/');
if (num >= 0)
{
this.path = this.path.Substring(0, num + 1);
}
}
if (relativeUri.Length == 0)
{
return;
}
this.path += relativeUri;
int num3 = 0;
for (;;)
{
num = this.path.IndexOf("./", num3);
if (num == -1)
{
break;
}
if (num == 0)
{
this.path = this.path.Remove(0, 2);
}
else if (this.path[num - 1] != '.')
{
this.path = this.path.Remove(num, 2);
}
else
{
num3 = num + 1;
}
}
if (this.path.Length > 1 && this.path[this.path.Length - 1] == '.' && this.path[this.path.Length - 2] == '/')
{
this.path = this.path.Remove(this.path.Length - 1, 1);
}
num3 = 0;
for (;;)
{
num = this.path.IndexOf("/../", num3);
if (num == -1)
{
break;
}
if (num == 0)
{
num3 = 3;
}
else
{
int num4 = this.path.LastIndexOf('/', num - 1);
if (num4 == -1)
{
num3 = num + 1;
}
else if (this.path.Substring(num4 + 1, num - num4 - 1) != "..")
{
this.path = this.path.Remove(num4 + 1, num - num4 + 3);
}
else
{
num3 = num + 1;
}
}
}
if (this.path.Length > 3 && this.path.EndsWith("/.."))
{
num = this.path.LastIndexOf('/', this.path.Length - 4);
if (num != -1 && this.path.Substring(num + 1, this.path.Length - num - 4) != "..")
{
this.path = this.path.Remove(num + 1, this.path.Length - num - 1);
}
}
if (!this.userEscaped)
{
this.path = Uri.EscapeString(this.path);
}
return;
}
}
// Token: 0x170001A7 RID: 423
// (get) Token: 0x06000BA0 RID: 2976 RVA: 0x00033E64 File Offset: 0x00032064
public string AbsolutePath
{
get
{
return this.path;
}
}
// Token: 0x170001A8 RID: 424
// (get) Token: 0x06000BA1 RID: 2977 RVA: 0x00033E6C File Offset: 0x0003206C
public string AbsoluteUri
{
get
{
if (this.cachedAbsoluteUri == null)
{
this.cachedAbsoluteUri = this.GetLeftPart(UriPartial.Path) + this.query + this.fragment;
}
return this.cachedAbsoluteUri;
}
}
// Token: 0x170001A9 RID: 425
// (get) Token: 0x06000BA2 RID: 2978 RVA: 0x00033EA0 File Offset: 0x000320A0
public string Authority
{
get
{
return (Uri.GetDefaultPort(this.scheme) != this.port) ? (this.host + ":" + this.port) : this.host;
}
}
// Token: 0x170001AA RID: 426
// (get) Token: 0x06000BA3 RID: 2979 RVA: 0x00033EEC File Offset: 0x000320EC
public string Fragment
{
get
{
return this.fragment;
}
}
// Token: 0x170001AB RID: 427
// (get) Token: 0x06000BA4 RID: 2980 RVA: 0x00033EF4 File Offset: 0x000320F4
public string Host
{
get
{
return this.host;
}
}
// Token: 0x170001AC RID: 428
// (get) Token: 0x06000BA5 RID: 2981 RVA: 0x00033EFC File Offset: 0x000320FC
public bool IsDefaultPort
{
get
{
return Uri.GetDefaultPort(this.scheme) == this.port;
}
}
// Token: 0x170001AD RID: 429
// (get) Token: 0x06000BA6 RID: 2982 RVA: 0x00033F14 File Offset: 0x00032114
public bool IsFile
{
get
{
return this.scheme == Uri.UriSchemeFile;
}
}
// Token: 0x170001AE RID: 430
// (get) Token: 0x06000BA7 RID: 2983 RVA: 0x00033F28 File Offset: 0x00032128
public bool IsLoopback
{
get
{
return !(this.host == string.Empty) && (this.host == "loopback" || this.host == "localhost");
}
}
// Token: 0x170001AF RID: 431
// (get) Token: 0x06000BA8 RID: 2984 RVA: 0x00033F7C File Offset: 0x0003217C
public bool IsUnc
{
get
{
return this.isUnc;
}
}
// Token: 0x170001B0 RID: 432
// (get) Token: 0x06000BA9 RID: 2985 RVA: 0x00033F84 File Offset: 0x00032184
public string LocalPath
{
get
{
if (this.cachedLocalPath != null)
{
return this.cachedLocalPath;
}
if (!this.IsFile)
{
return this.AbsolutePath;
}
bool flag = this.path.Length > 3 && this.path[1] == ':' && (this.path[2] == '\\' || this.path[2] == '/');
if (!this.IsUnc)
{
string text = this.Unescape(this.path);
if (Path.DirectorySeparatorChar == '\\' || flag)
{
this.cachedLocalPath = text.Replace('/', '\\');
}
else
{
this.cachedLocalPath = text;
}
}
else if (this.path.Length > 1 && this.path[1] == ':')
{
this.cachedLocalPath = this.Unescape(this.path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));
}
else if (Path.DirectorySeparatorChar == '\\')
{
this.cachedLocalPath = "\\\\" + this.Unescape(this.host + this.path.Replace('/', '\\'));
}
else
{
this.cachedLocalPath = this.Unescape(this.path);
}
if (this.cachedLocalPath == string.Empty)
{
this.cachedLocalPath = Path.DirectorySeparatorChar.ToString();
}
return this.cachedLocalPath;
}
}
// Token: 0x170001B1 RID: 433
// (get) Token: 0x06000BAA RID: 2986 RVA: 0x0003411C File Offset: 0x0003231C
public string PathAndQuery
{
get
{
return this.path + this.query;
}
}
// Token: 0x170001B2 RID: 434
// (get) Token: 0x06000BAB RID: 2987 RVA: 0x00034130 File Offset: 0x00032330
public int Port
{
get
{
return this.port;
}
}
// Token: 0x170001B3 RID: 435
// (get) Token: 0x06000BAC RID: 2988 RVA: 0x00034138 File Offset: 0x00032338
public string Query
{
get
{
return this.query;
}
}
// Token: 0x170001B4 RID: 436
// (get) Token: 0x06000BAD RID: 2989 RVA: 0x00034140 File Offset: 0x00032340
public string Scheme
{
get
{
return this.scheme;
}
}
// Token: 0x170001B5 RID: 437
// (get) Token: 0x06000BAE RID: 2990 RVA: 0x00034148 File Offset: 0x00032348
public string[] Segments
{
get
{
if (this.segments != null)
{
return this.segments;
}
if (this.path.Length == 0)
{
this.segments = new string[0];
return this.segments;
}
string[] array = this.path.Split(new char[] { '/' });
this.segments = array;
bool flag = this.path.EndsWith("/");
if (array.Length > 0 && flag)
{
string[] array2 = new string[array.Length - 1];
Array.Copy(array, 0, array2, 0, array.Length - 1);
array = array2;
}
int i = 0;
if (this.IsFile && this.path.Length > 1 && this.path[1] == ':')
{
string[] array3 = new string[array.Length + 1];
Array.Copy(array, 1, array3, 2, array.Length - 1);
array = array3;
array[0] = this.path.Substring(0, 2);
array[1] = string.Empty;
i++;
}
int num = array.Length;
while (i < num)
{
if (i != num - 1 || flag)
{
string[] array4 = array;
int num2 = i;
array4[num2] += '/';
}
i++;
}
this.segments = array;
return this.segments;
}
}
// Token: 0x170001B6 RID: 438
// (get) Token: 0x06000BAF RID: 2991 RVA: 0x00034298 File Offset: 0x00032498
public bool UserEscaped
{
get
{
return this.userEscaped;
}
}
// Token: 0x170001B7 RID: 439
// (get) Token: 0x06000BB0 RID: 2992 RVA: 0x000342A0 File Offset: 0x000324A0
public string UserInfo
{
get
{
return this.userinfo;
}
}
// Token: 0x06000BB1 RID: 2993 RVA: 0x000342A8 File Offset: 0x000324A8
internal static bool IsIPv4Address(string name)
{
string[] array = name.Split(new char[] { '.' });
if (array.Length != 4)
{
return false;
}
for (int i = 0; i < 4; i++)
{
try
{
int num = int.Parse(array[i], CultureInfo.InvariantCulture);
if (num < 0 || num > 255)
{
return false;
}
}
catch (Exception)
{
return false;
}
}
return true;
}
// Token: 0x06000BB2 RID: 2994 RVA: 0x0003433C File Offset: 0x0003253C
internal static bool IsDomainAddress(string name)
{
int length = name.Length;
if (name[length - 1] == '.')
{
return false;
}
int num = 0;
for (int i = 0; i < length; i++)
{
char c = name[i];
if (num == 0)
{
if (!char.IsLetterOrDigit(c))
{
return false;
}
}
else if (c == '.')
{
num = 0;
}
else if (!char.IsLetterOrDigit(c) && c != '-' && c != '_')
{
return false;
}
if (++num == 64)
{
return false;
}
}
return true;
}
// Token: 0x06000BB3 RID: 2995 RVA: 0x000343D4 File Offset: 0x000325D4
public static bool CheckSchemeName(string schemeName)
{
if (schemeName == null || schemeName.Length == 0)
{
return false;
}
if (!char.IsLetter(schemeName[0]))
{
return false;
}
int length = schemeName.Length;
for (int i = 1; i < length; i++)
{
char c = schemeName[i];
if (!char.IsLetterOrDigit(c) && c != '.' && c != '+' && c != '-')
{
return false;
}
}
return true;
}
// Token: 0x06000BB4 RID: 2996 RVA: 0x00034450 File Offset: 0x00032650
public override bool Equals(object comparant)
{
if (comparant == null)
{
return false;
}
Uri uri = comparant as Uri;
if (uri == null)
{
string text = comparant as string;
if (text == null)
{
return false;
}
uri = new Uri(text);
}
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
return this.scheme.ToLower(invariantCulture) == uri.scheme.ToLower(invariantCulture) && this.userinfo.ToLower(invariantCulture) == uri.userinfo.ToLower(invariantCulture) && this.host.ToLower(invariantCulture) == uri.host.ToLower(invariantCulture) && this.port == uri.port && this.path == uri.path && this.query.ToLower(invariantCulture) == uri.query.ToLower(invariantCulture);
}
// Token: 0x06000BB5 RID: 2997 RVA: 0x0003453C File Offset: 0x0003273C
public override int GetHashCode()
{
if (this.cachedHashCode == 0)
{
this.cachedHashCode = this.scheme.GetHashCode() + this.userinfo.GetHashCode() + this.host.GetHashCode() + this.port + this.path.GetHashCode() + this.query.GetHashCode();
}
return this.cachedHashCode;
}
// Token: 0x06000BB6 RID: 2998 RVA: 0x000345A4 File Offset: 0x000327A4
public string GetLeftPart(UriPartial part)
{
switch (part)
{
case UriPartial.Scheme:
return this.scheme + this.GetOpaqueWiseSchemeDelimiter();
case UriPartial.Authority:
{
if (this.host == string.Empty || this.scheme == Uri.UriSchemeMailto || this.scheme == Uri.UriSchemeNews)
{
return string.Empty;
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(this.scheme);
stringBuilder.Append(this.GetOpaqueWiseSchemeDelimiter());
if (this.path.Length > 1 && this.path[1] == ':' && Uri.UriSchemeFile == this.scheme)
{
stringBuilder.Append('/');
}
if (this.userinfo.Length > 0)
{
stringBuilder.Append(this.userinfo).Append('@');
}
stringBuilder.Append(this.host);
int num = Uri.GetDefaultPort(this.scheme);
if (this.port != -1 && this.port != num)
{
stringBuilder.Append(':').Append(this.port);
}
return stringBuilder.ToString();
}
case UriPartial.Path:
{
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.Append(this.scheme);
stringBuilder2.Append(this.GetOpaqueWiseSchemeDelimiter());
if (this.path.Length > 1 && this.path[1] == ':' && Uri.UriSchemeFile == this.scheme)
{
stringBuilder2.Append('/');
}
if (this.userinfo.Length > 0)
{
stringBuilder2.Append(this.userinfo).Append('@');
}
stringBuilder2.Append(this.host);
int num = Uri.GetDefaultPort(this.scheme);
if (this.port != -1 && this.port != num)
{
stringBuilder2.Append(':').Append(this.port);
}
stringBuilder2.Append(this.path);
return stringBuilder2.ToString();
}
default:
return null;
}
}
// Token: 0x06000BB7 RID: 2999 RVA: 0x000347D8 File Offset: 0x000329D8
public static int FromHex(char digit)
{
if ('0' <= digit && digit <= '9')
{
return (int)(digit - '0');
}
if ('a' <= digit && digit <= 'f')
{
return (int)(digit - 'a' + '\n');
}
if ('A' <= digit && digit <= 'F')
{
return (int)(digit - 'A' + '\n');
}
throw new ArgumentException("digit");
}
// Token: 0x06000BB8 RID: 3000 RVA: 0x00034834 File Offset: 0x00032A34
public static string HexEscape(char character)
{
if (character > 'ÿ')
{
throw new ArgumentOutOfRangeException("character");
}
return "%" + Uri.hexUpperChars[(int)((character & 'ð') >> 4)] + Uri.hexUpperChars[(int)(character & '\u000f')];
}
// Token: 0x06000BB9 RID: 3001 RVA: 0x0003488C File Offset: 0x00032A8C
public static char HexUnescape(string pattern, ref int index)
{
if (pattern == null)
{
throw new ArgumentException("pattern");
}
if (index < 0 || index >= pattern.Length)
{
throw new ArgumentOutOfRangeException("index");
}
int num = 0;
int num2 = 0;
while (index + 3 <= pattern.Length && pattern[index] == '%' && Uri.IsHexDigit(pattern[index + 1]) && Uri.IsHexDigit(pattern[index + 2]))
{
index++;
int num3 = Uri.FromHex(pattern[index++]);
int num4 = Uri.FromHex(pattern[index++]);
int num5 = (num3 << 4) + num4;
if (num == 0)
{
if (num5 < 192)
{
return (char)num5;
}
if (num5 < 224)
{
num2 = num5 - 192;
num = 2;
}
else if (num5 < 240)
{
num2 = num5 - 224;
num = 3;
}
else if (num5 < 248)
{
num2 = num5 - 240;
num = 4;
}
else if (num5 < 251)
{
num2 = num5 - 248;
num = 5;
}
else if (num5 < 254)
{
num2 = num5 - 252;
num = 6;
}
num2 <<= (num - 1) * 6;
}
else
{
num2 += num5 - 128 << (num - 1) * 6;
}
num--;
if (num <= 0)
{
IL_1A2:
return (char)num2;
}
}
if (num == 0)
{
return pattern[index++];
}
goto IL_1A2;
}
// Token: 0x06000BBA RID: 3002 RVA: 0x00034A40 File Offset: 0x00032C40
public static bool IsHexDigit(char digit)
{
return ('0' <= digit && digit <= '9') || ('a' <= digit && digit <= 'f') || ('A' <= digit && digit <= 'F');
}
// Token: 0x06000BBB RID: 3003 RVA: 0x00034A84 File Offset: 0x00032C84
public static bool IsHexEncoding(string pattern, int index)
{
return index + 3 <= pattern.Length && (pattern[index++] == '%' && Uri.IsHexDigit(pattern[index++])) && Uri.IsHexDigit(pattern[index]);
}
// Token: 0x06000BBC RID: 3004 RVA: 0x00034ADC File Offset: 0x00032CDC
public string MakeRelative(Uri toUri)
{
if (this.Scheme != toUri.Scheme || this.Authority != toUri.Authority)
{
return toUri.ToString();
}
if (this.path == toUri.path)
{
return string.Empty;
}
string[] array = this.Segments;
string[] array2 = toUri.Segments;
int i = 0;
int num = Math.Min(array.Length, array2.Length);
while (i < num)
{
if (array[i] != array2[i])
{
break;
}
i++;
}
string text = string.Empty;
for (int j = i + 1; j < array.Length; j++)
{
text += "../";
}
for (int k = i; k < array2.Length; k++)
{
text += array2[k];
}
return text;
}
// Token: 0x06000BBD RID: 3005 RVA: 0x00034BD0 File Offset: 0x00032DD0
public override string ToString()
{
if (this.cachedToString != null)
{
return this.cachedToString;
}
string text = ((!this.query.StartsWith("?")) ? this.Unescape(this.query) : ('?' + this.Unescape(this.query.Substring(1))));
this.cachedToString = this.Unescape(this.GetLeftPart(UriPartial.Path), true) + text + this.fragment;
return this.cachedToString;
}
// Token: 0x06000BBE RID: 3006 RVA: 0x00034C5C File Offset: 0x00032E5C
protected void Escape()
{
this.path = Uri.EscapeString(this.path);
}
// Token: 0x06000BBF RID: 3007 RVA: 0x00034C70 File Offset: 0x00032E70
protected static string EscapeString(string str)
{
return Uri.EscapeString(str, false, true, true);
}
// Token: 0x06000BC0 RID: 3008 RVA: 0x00034C7C File Offset: 0x00032E7C
internal static string EscapeString(string str, bool escapeReserved, bool escapeHex, bool escapeBrackets)
{
if (str == null)
{
return string.Empty;
}
StringBuilder stringBuilder = new StringBuilder();
int length = str.Length;
for (int i = 0; i < length; i++)
{
if (Uri.IsHexEncoding(str, i))
{
stringBuilder.Append(str.Substring(i, 3));
i += 2;
}
else
{
byte[] bytes = Encoding.UTF8.GetBytes(new char[] { str[i] });
int num = bytes.Length;
for (int j = 0; j < num; j++)
{
char c = (char)bytes[j];
if (c <= ' ' || c >= '\u007f' || "<>%\"{}|\\^`".IndexOf(c) != -1 || (escapeHex && c == '#') || (escapeBrackets && (c == '[' || c == ']')) || (escapeReserved && ";/?:@&=+$,".IndexOf(c) != -1))
{
stringBuilder.Append(Uri.HexEscape(c));
}
else
{
stringBuilder.Append(c);
}
}
}
}
return stringBuilder.ToString();
}
// Token: 0x06000BC1 RID: 3009 RVA: 0x00034D9C File Offset: 0x00032F9C
protected void Parse()
{
this.Parse(this.source);
if (this.userEscaped)
{
return;
}
this.host = Uri.EscapeString(this.host, false, true, false);
this.path = Uri.EscapeString(this.path);
}
// Token: 0x06000BC2 RID: 3010 RVA: 0x00034DE8 File Offset: 0x00032FE8
protected string Unescape(string str)
{
return this.Unescape(str, false);
}
// Token: 0x06000BC3 RID: 3011 RVA: 0x00034DF4 File Offset: 0x00032FF4
internal string Unescape(string str, bool excludeSharp)
{
if (str == null)
{
return string.Empty;
}
StringBuilder stringBuilder = new StringBuilder();
int length = str.Length;
for (int i = 0; i < length; i++)
{
char c = str[i];
if (c == '%')
{
char c2 = Uri.HexUnescape(str, ref i);
if (excludeSharp && c2 == '#')
{
stringBuilder.Append("%23");
}
else
{
stringBuilder.Append(c2);
}
i--;
}
else
{
stringBuilder.Append(c);
}
}
return stringBuilder.ToString();
}
// Token: 0x06000BC4 RID: 3012 RVA: 0x00034E88 File Offset: 0x00033088
private void ParseAsWindowsUNC(string uriString)
{
this.scheme = Uri.UriSchemeFile;
this.port = -1;
this.fragment = string.Empty;
this.query = string.Empty;
this.isUnc = true;
uriString = uriString.TrimStart(new char[] { '\\' });
int num = uriString.IndexOf('\\');
if (num > 0)
{
this.path = uriString.Substring(num);
this.host = uriString.Substring(0, num);
}
else
{
this.host = uriString;
this.path = string.Empty;
}
this.path = this.path.Replace("\\", "/");
}
// Token: 0x06000BC5 RID: 3013 RVA: 0x00034F34 File Offset: 0x00033134
private void ParseAsWindowsAbsoluteFilePath(string uriString)
{
if (uriString.Length > 2 && uriString[2] != '\\' && uriString[2] != '/')
{
throw new FormatException("Relative file path is not allowed.");
}
this.scheme = Uri.UriSchemeFile;
this.host = string.Empty;
this.port = -1;
this.path = uriString.Replace("\\", "/");
this.fragment = string.Empty;
this.query = string.Empty;
}
// Token: 0x06000BC6 RID: 3014 RVA: 0x00034FC0 File Offset: 0x000331C0
private void ParseAsUnixAbsoluteFilePath(string uriString)
{
this.isUnixFilePath = true;
this.scheme = Uri.UriSchemeFile;
this.port = -1;
this.fragment = string.Empty;
this.query = string.Empty;
this.host = string.Empty;
this.path = null;
if (uriString.StartsWith("//"))
{
uriString = uriString.TrimStart(new char[] { '/' });
this.path = '/' + uriString;
}
if (this.path == null)
{
this.path = uriString;
}
}
// Token: 0x06000BC7 RID: 3015 RVA: 0x00035058 File Offset: 0x00033258
private void Parse(string uriString)
{
if (uriString == null)
{
throw new ArgumentNullException("uriString");
}
int length = uriString.Length;
if (length <= 1)
{
throw new FormatException();
}
int num = uriString.IndexOf(':');
if (num < 0)
{
if (uriString[0] == '/')
{
this.ParseAsUnixAbsoluteFilePath(uriString);
}
else
{
if (!uriString.StartsWith("\\\\"))
{
throw new FormatException("URI scheme was not recognized, nor input string is not recognized as an absolute file path.");
}
this.ParseAsWindowsUNC(uriString);
}
return;
}
if (num == 1)
{
if (!char.IsLetter(uriString[0]))
{
throw new FormatException("URI scheme must start with alphabet character.");
}
this.ParseAsWindowsAbsoluteFilePath(uriString);
return;
}
else
{
this.scheme = uriString.Substring(0, num).ToLower(CultureInfo.InvariantCulture);
if (!char.IsLetter(this.scheme[0]))
{
throw new FormatException("URI scheme must start with alphabet character.");
}
for (int i = 1; i < this.scheme.Length; i++)
{
if (!char.IsLetterOrDigit(this.scheme, i))
{
switch (this.scheme[i])
{
case '+':
case '-':
case '.':
goto IL_132;
}
throw new FormatException("URI scheme must consist of one of alphabet, digits, '+', '-' or '.' character.");
}
IL_132:;
}
uriString = uriString.Substring(num + 1);
num = uriString.IndexOf('#');
if (!this.IsUnc && num != -1)
{
this.fragment = uriString.Substring(num);
uriString = uriString.Substring(0, num);
}
num = uriString.IndexOf('?');
if (num != -1)
{
this.query = uriString.Substring(num);
uriString = uriString.Substring(0, num);
if (!this.userEscaped)
{
this.query = Uri.EscapeString(this.query);
}
}
bool flag = this.scheme == Uri.UriSchemeFile && uriString.StartsWith("///");
if (uriString.StartsWith("//"))
{
if (uriString.StartsWith("////"))
{
flag = false;
}
uriString = uriString.TrimStart(new char[] { '/' });
if (uriString.Length > 1 && uriString[1] == ':')
{
flag = false;
}
}
else if (!Uri.IsPredefinedScheme(this.scheme))
{
this.path = uriString;
this.isOpaquePart = true;
return;
}
num = uriString.IndexOfAny(new char[] { '/' });
if (flag)
{
num = -1;
}
if (num == -1)
{
if (this.scheme != Uri.UriSchemeMailto && this.scheme != Uri.UriSchemeNews && this.scheme != Uri.UriSchemeFile)
{
this.path = "/";
}
}
else
{
this.path = uriString.Substring(num);
uriString = uriString.Substring(0, num);
}
num = uriString.IndexOf("@");
if (num != -1)
{
this.userinfo = uriString.Substring(0, num);
uriString = uriString.Remove(0, num + 1);
}
this.port = -1;
num = uriString.LastIndexOf(":");
if (flag)
{
num = -1;
}
if (num != -1 && num != uriString.Length - 1)
{
string text = uriString.Remove(0, num + 1);
if (text.Length > 1 && text[text.Length - 1] != ']')
{
try
{
this.port = (int)uint.Parse(text, CultureInfo.InvariantCulture);
uriString = uriString.Substring(0, num);
}
catch (Exception)
{
throw new FormatException("Invalid URI: invalid port number");
}
}
}
if (this.port == -1)
{
this.port = Uri.GetDefaultPort(this.scheme);
}
this.host = uriString;
if (flag)
{
this.path = '/' + uriString;
this.host = string.Empty;
}
else if (this.host.Length == 2 && this.host[1] == ':')
{
this.path = this.host + this.path;
this.host = string.Empty;
}
else if (this.isUnixFilePath)
{
uriString = "//" + uriString;
this.host = string.Empty;
}
else
{
if (this.host.Length == 0)
{
throw new FormatException("Invalid URI: The hostname could not be parsed");
}
if (this.scheme == Uri.UriSchemeFile)
{
this.isUnc = true;
}
}
if (this.scheme != Uri.UriSchemeMailto && this.scheme != Uri.UriSchemeNews && this.scheme != Uri.UriSchemeFile && this.reduce)
{
this.path = Uri.Reduce(this.path);
}
return;
}
}
// Token: 0x06000BC8 RID: 3016 RVA: 0x0003557C File Offset: 0x0003377C
private static string Reduce(string path)
{
path = path.Replace('\\', '/');
string[] array = path.Split(new char[] { '/' });
ArrayList arrayList = new ArrayList();
int num = array.Length;
for (int i = 0; i < num; i++)
{
string text = array[i];
if (text.Length != 0 && !(text == "."))
{
if (text == "..")
{
if (arrayList.Count == 0)
{
if (i != 1)
{
throw new Exception("Invalid path.");
}
}
else
{
arrayList.RemoveAt(arrayList.Count - 1);
}
}
else
{
arrayList.Add(text);
}
}
}
if (arrayList.Count == 0)
{
return "/";
}
arrayList.Insert(0, string.Empty);
string text2 = string.Join("/", (string[])arrayList.ToArray(typeof(string)));
if (path.EndsWith("/"))
{
text2 += '/';
}
return text2;
}
// Token: 0x06000BC9 RID: 3017 RVA: 0x0003569C File Offset: 0x0003389C
internal static string GetSchemeDelimiter(string scheme)
{
for (int i = 0; i < Uri.schemes.Length; i++)
{
if (Uri.schemes[i].scheme == scheme)
{
return Uri.schemes[i].delimiter;
}
}
return Uri.SchemeDelimiter;
}
// Token: 0x06000BCA RID: 3018 RVA: 0x000356F4 File Offset: 0x000338F4
internal static int GetDefaultPort(string scheme)
{
for (int i = 0; i < Uri.schemes.Length; i++)
{
if (Uri.schemes[i].scheme == scheme)
{
return Uri.schemes[i].defaultPort;
}
}
return -1;
}
// Token: 0x06000BCB RID: 3019 RVA: 0x00035748 File Offset: 0x00033948
private string GetOpaqueWiseSchemeDelimiter()
{
if (this.isOpaquePart)
{
return ":";
}
return Uri.GetSchemeDelimiter(this.scheme);
}
// Token: 0x06000BCC RID: 3020 RVA: 0x00035768 File Offset: 0x00033968
protected bool IsBadFileSystemCharacter(char ch)
{
if (ch < ' ' || (ch < '@' && ch > '9'))
{
return true;
}
switch (ch)
{
case '*':
case ',':
case '/':
break;
default:
switch (ch)
{
case '\\':
case '^':
break;
default:
if (ch != '\0' && ch != '"' && ch != '&' && ch != '|')
{
return false;
}
break;
}
break;
}
return true;
}
// Token: 0x06000BCD RID: 3021 RVA: 0x000357F0 File Offset: 0x000339F0
protected static bool IsExcludedCharacter(char ch)
{
return ch <= ' ' || ch >= '\u007f' || (ch == '"' || ch == '#' || ch == '%' || ch == '<' || ch == '>' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}');
}
// Token: 0x06000BCE RID: 3022 RVA: 0x0003587C File Offset: 0x00033A7C
private static bool IsPredefinedScheme(string scheme)
{
if (scheme != null)
{
if (Uri.<>f__switch$map17 == null)
{
Uri.<>f__switch$map17 = new Dictionary<string, int>(8)
{
{ "http", 0 },
{ "https", 0 },
{ "file", 0 },
{ "ftp", 0 },
{ "nntp", 0 },
{ "gopher", 0 },
{ "mailto", 0 },
{ "news", 0 }
};
}
int num;
if (Uri.<>f__switch$map17.TryGetValue(scheme, out num))
{
if (num == 0)
{
return true;
}
}
}
return false;
}
// Token: 0x06000BCF RID: 3023 RVA: 0x00035928 File Offset: 0x00033B28
protected bool IsReservedCharacter(char ch)
{
return ch == '$' || ch == '&' || ch == '+' || ch == ',' || ch == '/' || ch == ':' || ch == ';' || ch == '=' || ch == '@';
}
// Token: 0x0400031E RID: 798
private bool isUnixFilePath;
// Token: 0x0400031F RID: 799
private string source;
// Token: 0x04000320 RID: 800
private string scheme;
// Token: 0x04000321 RID: 801
private string host;
// Token: 0x04000322 RID: 802
private int port;
// Token: 0x04000323 RID: 803
private string path;
// Token: 0x04000324 RID: 804
private string query;
// Token: 0x04000325 RID: 805
private string fragment;
// Token: 0x04000326 RID: 806
private string userinfo;
// Token: 0x04000327 RID: 807
private bool isUnc;
// Token: 0x04000328 RID: 808
private bool isOpaquePart;
// Token: 0x04000329 RID: 809
private string[] segments;
// Token: 0x0400032A RID: 810
private bool userEscaped;
// Token: 0x0400032B RID: 811
private string cachedAbsoluteUri;
// Token: 0x0400032C RID: 812
private string cachedToString;
// Token: 0x0400032D RID: 813
private string cachedLocalPath;
// Token: 0x0400032E RID: 814
private int cachedHashCode;
// Token: 0x0400032F RID: 815
private bool reduce;
// Token: 0x04000330 RID: 816
private static readonly string hexUpperChars = "0123456789ABCDEF";
// Token: 0x04000331 RID: 817
public static readonly string SchemeDelimiter = "://";
// Token: 0x04000332 RID: 818
public static readonly string UriSchemeFile = "file";
// Token: 0x04000333 RID: 819
public static readonly string UriSchemeFtp = "ftp";
// Token: 0x04000334 RID: 820
public static readonly string UriSchemeGopher = "gopher";
// Token: 0x04000335 RID: 821
public static readonly string UriSchemeHttp = "http";
// Token: 0x04000336 RID: 822
public static readonly string UriSchemeHttps = "https";
// Token: 0x04000337 RID: 823
public static readonly string UriSchemeMailto = "mailto";
// Token: 0x04000338 RID: 824
public static readonly string UriSchemeNews = "news";
// Token: 0x04000339 RID: 825
public static readonly string UriSchemeNntp = "nntp";
// Token: 0x0400033A RID: 826
private static Uri.UriScheme[] schemes = new Uri.UriScheme[]
{
new Uri.UriScheme(Uri.UriSchemeHttp, Uri.SchemeDelimiter, 80),
new Uri.UriScheme(Uri.UriSchemeHttps, Uri.SchemeDelimiter, 443),
new Uri.UriScheme(Uri.UriSchemeFtp, Uri.SchemeDelimiter, 21),
new Uri.UriScheme(Uri.UriSchemeFile, Uri.SchemeDelimiter, -1),
new Uri.UriScheme(Uri.UriSchemeMailto, ":", 25),
new Uri.UriScheme(Uri.UriSchemeNews, ":", -1),
new Uri.UriScheme(Uri.UriSchemeNntp, Uri.SchemeDelimiter, 119),
new Uri.UriScheme(Uri.UriSchemeGopher, Uri.SchemeDelimiter, 70)
};
// Token: 0x020000EC RID: 236
private struct UriScheme
{
// Token: 0x06000BD0 RID: 3024 RVA: 0x00035980 File Offset: 0x00033B80
public UriScheme(string s, string d, int p)
{
this.scheme = s;
this.delimiter = d;
this.defaultPort = p;
}
// Token: 0x0400033C RID: 828
public string scheme;
// Token: 0x0400033D RID: 829
public string delimiter;
// Token: 0x0400033E RID: 830
public int defaultPort;
}
}
}