Example #1
0
        public KnownAce(AceType type, AceFlags flags, int mask, Sid sid)
        {
            if (
                type != AceType.AccessAllowed &&
                type != AceType.AccessDenied &&
                type != AceType.SystemAlarm &&
                type != AceType.SystemAudit
                )
            {
                throw new ArgumentException("Invalid ACE type.");
            }

            this.MemoryRegion = new MemoryAlloc(
                Marshal.SizeOf(typeof(KnownAceStruct)) - // known ace struct size
                sizeof(int) +                            // minus SidStart field
                sid.Length                               // plus SID length
                );

            KnownAceStruct knownAce = new KnownAceStruct();

            // Initialize the ACE (minus the SID).
            knownAce.Header.AceType  = type;
            knownAce.Header.AceFlags = flags;
            knownAce.Header.AceSize  = (ushort)this.MemoryRegion.Size;
            knownAce.Mask            = mask;
            // Write the ACE to memory.
            this.MemoryRegion.WriteStruct <KnownAceStruct>(knownAce);
            // Write the SID.
            this.MemoryRegion.WriteMemory(Win32.KnownAceSidStartOffset.ToInt32(), sid, 0, sid.Length);
            // Update the cached info.
            this.Read();
        }
Example #2
0
        public KnownAce(AceType type, AceFlags flags, int mask, Sid sid)
        {
            if (
                type != AceType.AccessAllowed &&
                type != AceType.AccessDenied &&
                type != AceType.SystemAlarm &&
                type != AceType.SystemAudit
                )
                throw new ArgumentException("Invalid ACE type.");

            this.MemoryRegion = new MemoryAlloc(
                Marshal.SizeOf(typeof(KnownAceStruct)) - // known ace struct size
                sizeof(int) + // minus SidStart field
                sid.Length // plus SID length
                );

            KnownAceStruct knownAce = new KnownAceStruct();

            // Initialize the ACE (minus the SID).
            knownAce.Header.AceType = type;
            knownAce.Header.AceFlags = flags;
            knownAce.Header.AceSize = (ushort)this.MemoryRegion.Size;
            knownAce.Mask = mask;
            // Write the ACE to memory.
            this.MemoryRegion.WriteStruct<KnownAceStruct>(knownAce);
            // Write the SID.
            this.MemoryRegion.WriteMemory(Win32.KnownAceSidStartOffset.ToInt32(), sid, 0, sid.Length);
            // Update the cached info.
            this.Read();
        }
Example #3
0
        public KnownAce(AceType type, AceFlags flags, int mask, Sid sid)
        {
            if (
                type != AceType.AccessAllowed &&
                type != AceType.AccessDenied &&
                type != AceType.SystemAlarm &&
                type != AceType.SystemAudit
                )
                throw new ArgumentException("Invalid ACE type.");

            this.MemoryRegion = new MemoryAlloc(
                Marshal.SizeOf(typeof(KnownAceStruct)) -
                sizeof(int) +
                sid.Length
                );

            KnownAceStruct knownAce = new KnownAceStruct();

            knownAce.Header.AceType = type;
            knownAce.Header.AceFlags = flags;
            knownAce.Header.AceSize = (ushort)this.MemoryRegion.Size;
            knownAce.Mask = mask;

            this.MemoryRegion.WriteStruct<KnownAceStruct>(knownAce);

            this.MemoryRegion.WriteMemory(Win32.KnownAceSidStartOffset.ToInt32(), sid, 0, sid.Length);

            this.Read();
        }