/// <summary> /// Get hash code. /// </summary> /// <returns>The hash code</returns> public override int GetHashCode() { return(Type.GetHashCode() ^ Flags.GetHashCode() ^ Mask.GetHashCode() ^ Sid.GetHashCode() ^ ObjectType.GetHashCode() ^ InheritedObjectType.GetHashCode() ^ ServerSid?.GetHashCode() ?? 0 ^ NtObjectUtils.GetHashCodeByteArray(ApplicationData)); }
internal void Serialize(BinaryWriter writer) { byte[] sid_data = Sid.ToArray(); if (Type == AceType.AllowedCompound) { MemoryStream stm = new MemoryStream(); BinaryWriter sidwriter = new BinaryWriter(stm); sidwriter.Write((int)CompoundAceType.Impersonation); sidwriter.Write(ServerSid.ToArray()); sidwriter.Write(sid_data); sid_data = stm.ToArray(); } int total_length = 4 + 4 + sid_data.Length; if (ApplicationData != null) { total_length += ApplicationData.Length; } // Add a round up to 4 byte alignment. int padding = 4 - (total_length % 4); if (padding == 4) { padding = 0; } total_length += padding; ObjectAceFlags flags = ObjectAceFlags.None; if (IsObjectAce) { // For Flags total_length += 4; if (ObjectType.HasValue) { total_length += 16; flags |= ObjectAceFlags.ObjectTypePresent; } if (InheritedObjectType.HasValue) { total_length += 16; flags |= ObjectAceFlags.InheritedObjectTypePresent; } } if (total_length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("Total ACE length greater than maximum"); } writer.Write((byte)Type); writer.Write(MapFromFlags(Type, Flags)); writer.Write((ushort)total_length); writer.Write(Mask.Access); if (IsObjectAce) { writer.Write((uint)flags); if (ObjectType.HasValue) { writer.Write(ObjectType.Value.ToByteArray()); } if (InheritedObjectType.HasValue) { writer.Write(InheritedObjectType.Value.ToByteArray()); } } writer.Write(sid_data); writer.Write(ApplicationData ?? new byte[0]); if (padding != 0) { writer.Write(new byte[padding]); } }