using System; using System.Collections; using System.Runtime.InteropServices; using System.Security.AccessControl; using System.Text; namespace System.Security.Permissions { /// Controls the ability to access registry variables. This class cannot be inherited. // Token: 0x02000564 RID: 1380 [ComVisible(true)] [Serializable] public sealed class RegistryPermission : CodeAccessPermission, IBuiltInPermission, IUnrestrictedPermission { /// Initializes a new instance of the class with either fully restricted or unrestricted permission as specified. /// One of the values. /// The parameter is not a valid value of . // Token: 0x06003264 RID: 12900 RVA: 0x000AD0A8 File Offset: 0x000AB2A8 public RegistryPermission(PermissionState state) { this._state = CodeAccessPermission.CheckPermissionState(state, true); this.createList = new ArrayList(); this.readList = new ArrayList(); this.writeList = new ArrayList(); } /// Initializes a new instance of the class with the specified access to the specified registry variables. /// One of the values. /// A list of registry variables (semicolon-separated) to which access is granted. /// The parameter is not a valid value of .-or- The parameter is not a valid string. // Token: 0x06003265 RID: 12901 RVA: 0x000AD0EC File Offset: 0x000AB2EC public RegistryPermission(RegistryPermissionAccess access, string pathList) { this._state = PermissionState.None; this.createList = new ArrayList(); this.readList = new ArrayList(); this.writeList = new ArrayList(); this.AddPathList(access, pathList); } /// Initializes a new instance of the class with the specified access to the specified registry variables and the specified access rights to registry control information. /// One of the values. /// A bitwise combination of the values. /// A list of registry variables (semicolon-separated) to which access is granted. /// The parameter is not a valid value of .-or- The parameter is not a valid string. // Token: 0x06003266 RID: 12902 RVA: 0x000AD130 File Offset: 0x000AB330 public RegistryPermission(RegistryPermissionAccess access, AccessControlActions control, string pathList) { if (!Enum.IsDefined(typeof(AccessControlActions), control)) { string text = string.Format(Locale.GetText("Invalid enum {0}"), control); throw new ArgumentException(text, "AccessControlActions"); } this._state = PermissionState.None; this.AddPathList(access, control, pathList); } // Token: 0x06003267 RID: 12903 RVA: 0x000AD190 File Offset: 0x000AB390 int IBuiltInPermission.GetTokenIndex() { return 5; } /// Adds access for the specified registry variables to the existing state of the permission. /// One of the values. /// A list of registry variables (semicolon-separated). /// The parameter is not a valid value of .-or- The parameter is not a valid string. // Token: 0x06003268 RID: 12904 RVA: 0x000AD194 File Offset: 0x000AB394 public void AddPathList(RegistryPermissionAccess access, string pathList) { if (pathList == null) { throw new ArgumentNullException("pathList"); } switch (access) { case RegistryPermissionAccess.NoAccess: return; case RegistryPermissionAccess.Read: this.AddWithUnionKey(this.readList, pathList); return; case RegistryPermissionAccess.Write: this.AddWithUnionKey(this.writeList, pathList); return; case RegistryPermissionAccess.Create: this.AddWithUnionKey(this.createList, pathList); return; case RegistryPermissionAccess.AllAccess: this.AddWithUnionKey(this.createList, pathList); this.AddWithUnionKey(this.readList, pathList); this.AddWithUnionKey(this.writeList, pathList); return; } this.ThrowInvalidFlag(access, false); } /// Adds access for the specified registry variables to the existing state of the permission, specifying registry permission access and access control actions. /// One of the values. /// One of the values. /// A list of registry variables (separated by semicolons). /// The parameter is not a valid value of .-or- The parameter is not a valid string. // Token: 0x06003269 RID: 12905 RVA: 0x000AD254 File Offset: 0x000AB454 [MonoTODO("(2.0) Access Control isn't implemented")] public void AddPathList(RegistryPermissionAccess access, AccessControlActions control, string pathList) { throw new NotImplementedException(); } /// Gets paths for all registry variables with the specified . /// A list of the registry variables (semicolon-separated) with the specified . /// One of the values that represents a single type of registry variable access. /// /// is not a valid value of .-or- is , which represents more than one type of registry variable access, or , which does not represent any type of registry variable access. // Token: 0x0600326A RID: 12906 RVA: 0x000AD25C File Offset: 0x000AB45C public string GetPathList(RegistryPermissionAccess access) { switch (access) { case RegistryPermissionAccess.NoAccess: case RegistryPermissionAccess.AllAccess: this.ThrowInvalidFlag(access, true); goto IL_6E; case RegistryPermissionAccess.Read: return this.GetPathList(this.readList); case RegistryPermissionAccess.Write: return this.GetPathList(this.writeList); case RegistryPermissionAccess.Create: return this.GetPathList(this.createList); } this.ThrowInvalidFlag(access, false); IL_6E: return null; } /// Sets new access for the specified registry variable names to the existing state of the permission. /// One of the values. /// A list of registry variables (semicolon-separated). /// The parameter is not a valid value of .-or- The parameter is not a valid string. // Token: 0x0600326B RID: 12907 RVA: 0x000AD2D8 File Offset: 0x000AB4D8 public void SetPathList(RegistryPermissionAccess access, string pathList) { if (pathList == null) { throw new ArgumentNullException("pathList"); } switch (access) { case RegistryPermissionAccess.NoAccess: return; case RegistryPermissionAccess.Read: { this.readList.Clear(); string[] array = pathList.Split(new char[] { ';' }); foreach (string text in array) { this.readList.Add(text); } return; } case RegistryPermissionAccess.Write: { this.writeList.Clear(); string[] array = pathList.Split(new char[] { ';' }); foreach (string text2 in array) { this.writeList.Add(text2); } return; } case RegistryPermissionAccess.Create: { this.createList.Clear(); string[] array = pathList.Split(new char[] { ';' }); foreach (string text3 in array) { this.createList.Add(text3); } return; } case RegistryPermissionAccess.AllAccess: { this.createList.Clear(); this.readList.Clear(); this.writeList.Clear(); string[] array = pathList.Split(new char[] { ';' }); foreach (string text4 in array) { this.createList.Add(text4); this.readList.Add(text4); this.writeList.Add(text4); } return; } } this.ThrowInvalidFlag(access, false); } /// Creates and returns an identical copy of the current permission. /// A copy of the current permission. // Token: 0x0600326C RID: 12908 RVA: 0x000AD4AC File Offset: 0x000AB6AC public override IPermission Copy() { RegistryPermission registryPermission = new RegistryPermission(this._state); string text = this.GetPathList(RegistryPermissionAccess.Create); if (text != null) { registryPermission.SetPathList(RegistryPermissionAccess.Create, text); } text = this.GetPathList(RegistryPermissionAccess.Read); if (text != null) { registryPermission.SetPathList(RegistryPermissionAccess.Read, text); } text = this.GetPathList(RegistryPermissionAccess.Write); if (text != null) { registryPermission.SetPathList(RegistryPermissionAccess.Write, text); } return registryPermission; } /// Reconstructs a permission with a specified state from an XML encoding. /// The XML encoding to use to reconstruct the permission. /// The parameter is null. /// The parameter is not a valid permission element.-or- The parameter's version number is not valid. // Token: 0x0600326D RID: 12909 RVA: 0x000AD508 File Offset: 0x000AB708 public override void FromXml(SecurityElement esd) { CodeAccessPermission.CheckSecurityElement(esd, "esd", 1, 1); CodeAccessPermission.CheckSecurityElement(esd, "esd", 1, 1); if (CodeAccessPermission.IsUnrestricted(esd)) { this._state = PermissionState.Unrestricted; } string text = esd.Attribute("Create"); if (text != null && text.Length > 0) { this.SetPathList(RegistryPermissionAccess.Create, text); } string text2 = esd.Attribute("Read"); if (text2 != null && text2.Length > 0) { this.SetPathList(RegistryPermissionAccess.Read, text2); } string text3 = esd.Attribute("Write"); if (text3 != null && text3.Length > 0) { this.SetPathList(RegistryPermissionAccess.Write, text3); } } /// Creates and returns a permission that is the intersection of the current permission and the specified permission. /// A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty. /// A permission to intersect with the current permission. It must be of the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x0600326E RID: 12910 RVA: 0x000AD5B8 File Offset: 0x000AB7B8 public override IPermission Intersect(IPermission target) { RegistryPermission registryPermission = this.Cast(target); if (registryPermission == null) { return null; } if (this.IsUnrestricted()) { return registryPermission.Copy(); } if (registryPermission.IsUnrestricted()) { return this.Copy(); } RegistryPermission registryPermission2 = new RegistryPermission(PermissionState.None); this.IntersectKeys(this.createList, registryPermission.createList, registryPermission2.createList); this.IntersectKeys(this.readList, registryPermission.readList, registryPermission2.readList); this.IntersectKeys(this.writeList, registryPermission.writeList, registryPermission2.writeList); return (!registryPermission2.IsEmpty()) ? registryPermission2 : null; } /// Determines whether the current permission is a subset of the specified permission. /// true if the current permission is a subset of the specified permission; otherwise, false. /// A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x0600326F RID: 12911 RVA: 0x000AD65C File Offset: 0x000AB85C public override bool IsSubsetOf(IPermission target) { RegistryPermission registryPermission = this.Cast(target); if (registryPermission == null) { return false; } if (registryPermission.IsEmpty()) { return this.IsEmpty(); } if (this.IsUnrestricted()) { return registryPermission.IsUnrestricted(); } return registryPermission.IsUnrestricted() || (this.KeyIsSubsetOf(this.createList, registryPermission.createList) && this.KeyIsSubsetOf(this.readList, registryPermission.readList) && this.KeyIsSubsetOf(this.writeList, registryPermission.writeList)); } /// Returns a value indicating whether the current permission is unrestricted. /// true if the current permission is unrestricted; otherwise, false. // Token: 0x06003270 RID: 12912 RVA: 0x000AD6F8 File Offset: 0x000AB8F8 public bool IsUnrestricted() { return this._state == PermissionState.Unrestricted; } /// Creates an XML encoding of the permission and its current state. /// An XML encoding of the permission, including any state information. // Token: 0x06003271 RID: 12913 RVA: 0x000AD704 File Offset: 0x000AB904 public override SecurityElement ToXml() { SecurityElement securityElement = base.Element(1); if (this._state == PermissionState.Unrestricted) { securityElement.AddAttribute("Unrestricted", "true"); } else { string text = this.GetPathList(RegistryPermissionAccess.Create); if (text != null) { securityElement.AddAttribute("Create", text); } text = this.GetPathList(RegistryPermissionAccess.Read); if (text != null) { securityElement.AddAttribute("Read", text); } text = this.GetPathList(RegistryPermissionAccess.Write); if (text != null) { securityElement.AddAttribute("Write", text); } } return securityElement; } /// Creates a permission that is the union of the current permission and the specified permission. /// A new permission that represents the union of the current permission and the specified permission. /// A permission to combine with the current permission. It must be of the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x06003272 RID: 12914 RVA: 0x000AD78C File Offset: 0x000AB98C public override IPermission Union(IPermission other) { RegistryPermission registryPermission = this.Cast(other); if (registryPermission == null) { return this.Copy(); } if (this.IsUnrestricted() || registryPermission.IsUnrestricted()) { return new RegistryPermission(PermissionState.Unrestricted); } if (this.IsEmpty() && registryPermission.IsEmpty()) { return null; } RegistryPermission registryPermission2 = (RegistryPermission)this.Copy(); string text = registryPermission.GetPathList(RegistryPermissionAccess.Create); if (text != null) { registryPermission2.AddPathList(RegistryPermissionAccess.Create, text); } text = registryPermission.GetPathList(RegistryPermissionAccess.Read); if (text != null) { registryPermission2.AddPathList(RegistryPermissionAccess.Read, text); } text = registryPermission.GetPathList(RegistryPermissionAccess.Write); if (text != null) { registryPermission2.AddPathList(RegistryPermissionAccess.Write, text); } return registryPermission2; } // Token: 0x06003273 RID: 12915 RVA: 0x000AD834 File Offset: 0x000ABA34 private bool IsEmpty() { return this._state == PermissionState.None && this.createList.Count == 0 && this.readList.Count == 0 && this.writeList.Count == 0; } // Token: 0x06003274 RID: 12916 RVA: 0x000AD880 File Offset: 0x000ABA80 private RegistryPermission Cast(IPermission target) { if (target == null) { return null; } RegistryPermission registryPermission = target as RegistryPermission; if (registryPermission == null) { CodeAccessPermission.ThrowInvalidPermission(target, typeof(RegistryPermission)); } return registryPermission; } // Token: 0x06003275 RID: 12917 RVA: 0x000AD8B4 File Offset: 0x000ABAB4 internal void ThrowInvalidFlag(RegistryPermissionAccess flag, bool context) { string text; if (context) { text = Locale.GetText("Unknown flag '{0}'."); } else { text = Locale.GetText("Invalid flag '{0}' in this context."); } throw new ArgumentException(string.Format(text, flag), "flag"); } // Token: 0x06003276 RID: 12918 RVA: 0x000AD8FC File Offset: 0x000ABAFC private string GetPathList(ArrayList list) { if (this.IsUnrestricted()) { return string.Empty; } if (list.Count == 0) { return string.Empty; } StringBuilder stringBuilder = new StringBuilder(); foreach (object obj in list) { string text = (string)obj; stringBuilder.Append(text); stringBuilder.Append(";"); } string text2 = stringBuilder.ToString(); int length = text2.Length; if (length > 0) { return text2.Substring(0, length - 1); } return string.Empty; } // Token: 0x06003277 RID: 12919 RVA: 0x000AD9C8 File Offset: 0x000ABBC8 internal bool KeyIsSubsetOf(IList local, IList target) { bool flag = false; foreach (object obj in local) { string text = (string)obj; foreach (object obj2 in target) { string text2 = (string)obj2; if (text.StartsWith(text2)) { flag = true; break; } } if (!flag) { return false; } } return true; } // Token: 0x06003278 RID: 12920 RVA: 0x000ADAB0 File Offset: 0x000ABCB0 internal void AddWithUnionKey(IList list, string pathList) { string[] array = pathList.Split(new char[] { ';' }); foreach (string text in array) { int count = list.Count; if (count == 0) { list.Add(text); } else { for (int j = 0; j < count; j++) { string text2 = (string)list[j]; if (text2.StartsWith(text)) { list[j] = text; } else if (!text.StartsWith(text2)) { list.Add(text); } } } } } // Token: 0x06003279 RID: 12921 RVA: 0x000ADB60 File Offset: 0x000ABD60 internal void IntersectKeys(IList local, IList target, IList result) { foreach (object obj in local) { string text = (string)obj; foreach (object obj2 in target) { string text2 = (string)obj2; if (text2.Length > text.Length) { if (text2.StartsWith(text)) { result.Add(text2); } } else if (text.StartsWith(text2)) { result.Add(text); } } } } // Token: 0x040014B0 RID: 5296 private const int version = 1; // Token: 0x040014B1 RID: 5297 private PermissionState _state; // Token: 0x040014B2 RID: 5298 private ArrayList createList; // Token: 0x040014B3 RID: 5299 private ArrayList readList; // Token: 0x040014B4 RID: 5300 private ArrayList writeList; } }