/// <summary> /// Convert the ACL to a byte array /// </summary> /// <returns>The ACL as a byte array</returns> public byte[] ToByteArray() { AclRevision revision; byte[] aces; using (var ace_stm = new MemoryStream()) { using (var writer = new BinaryWriter(ace_stm)) { revision = Revision; if (revision != AclRevision.Revision || revision != AclRevision.RevisionDS) { revision = AclRevision.Revision; } foreach (Ace ace in this) { ace.Serialize(writer); if (ace.IsObjectAce) { revision = AclRevision.RevisionDS; } } } aces = ace_stm.ToArray(); } using (var buffer = new SafeHGlobalBuffer(Marshal.SizeOf(typeof(AclStructure)) + aces.Length)) { NtRtl.RtlCreateAcl(buffer, buffer.Length, revision).ToNtException(); NtRtl.RtlAddAce(buffer, revision, uint.MaxValue, aces, aces.Length).ToNtException(); return(buffer.ToArray()); } }
/// <summary> /// Convert the ACL to a byte array /// </summary> /// <returns>The ACL as a byte array</returns> public byte[] ToByteArray() { AclRevision revision; byte[] aces; using (var ace_stm = new MemoryStream()) { using (var writer = new BinaryWriter(ace_stm)) { revision = Revision; switch (revision) { case AclRevision.Revision: case AclRevision.RevisionCompound: case AclRevision.RevisionDS: break; default: revision = AclRevision.Revision; break; } foreach (Ace ace in this) { ace.Serialize(writer); if (ace.IsObjectAce) { revision = AclRevision.RevisionDS; } else if (ace.Type == AceType.AllowedCompound && revision < AclRevision.RevisionCompound) { revision = AclRevision.RevisionCompound; } } } aces = ace_stm.ToArray(); } using (var buffer = new SafeHGlobalBuffer(Marshal.SizeOf(typeof(AclStructure)) + aces.Length)) { NtRtl.RtlCreateAcl(buffer, buffer.Length, revision).ToNtException(); NtRtl.RtlAddAce(buffer, revision, uint.MaxValue, aces, aces.Length).ToNtException(); return(buffer.ToArray()); } }