public static extern NtStatus NtQueryInformationAtom(
     ushort Atom,
     AtomInformationClass AtomInformationClass,
     SafeBuffer AtomInformation,
     int AtomInformationLength,
     out int ReturnLength
 );
Ejemplo n.º 2
0
 internal unsafe MemoryMappedFileBlock(IDisposable accessor, SafeBuffer safeBuffer, byte* pointer, int size)
 {
     _accessor = accessor;
     _safeBuffer = safeBuffer;
     _pointer = pointer;
     _size = size;
 }
        [System.Security.SecuritySafeCritical]  // auto-generated
        protected void Initialize(SafeBuffer buffer, Int64 offset, Int64 capacity, FileAccess access)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (buffer.ByteLength < (UInt64)(offset + capacity))
            {
                throw new ArgumentException(SR.Argument_OffsetAndCapacityOutOfBounds);
            }
            if (access < FileAccess.Read || access > FileAccess.ReadWrite)
            {
                throw new ArgumentOutOfRangeException(nameof(access));
            }
            Contract.EndContractBlock();

            if (_isOpen)
            {
                throw new InvalidOperationException(SR.InvalidOperation_CalledTwice);
            }

            unsafe
            {
                byte* pointer = null;

                try
                {
                    buffer.AcquirePointer(ref pointer);
                    if (((byte*)((Int64)pointer + offset + capacity)) < pointer)
                    {
                        throw new ArgumentException(SR.Argument_UnmanagedMemAccessorWrapAround);
                    }
                }
                finally
                {
                    if (pointer != null)
                    {
                        buffer.ReleasePointer();
                    }
                }
            }

            _offset = offset;
            _buffer = buffer;
            _capacity = capacity;
            _access = access;
            _isOpen = true;
            _canRead = (_access & FileAccess.Read) != 0;
            _canWrite = (_access & FileAccess.Write) != 0;
        }
Ejemplo n.º 4
0
		public UnmanagedMemoryAccessor (SafeBuffer buffer, long offset, long capacity, FileAccess access) {
			if (buffer == null)
				throw new ArgumentNullException ("buffer");
			if (offset < 0)
				throw new ArgumentOutOfRangeException ("offset");
			if (capacity < 0)
				throw new ArgumentOutOfRangeException ("capacity");
			if (offset + capacity < 0)
				throw new InvalidOperationException ();
			this.buffer = buffer;
			this.offset = offset;
			this.capacity = capacity;
			this.access = access;
		}
Ejemplo n.º 5
0
        protected override void Dispose(bool disposing)
        {
            if (_safeBuffer != null)
            {
                _safeBuffer.ReleasePointer();
                _safeBuffer = null;
            }

            if (_accessor != null)
            {
                _accessor.Dispose();
                _accessor = null;
            }

            _pointer = null;
        }
Ejemplo n.º 6
0
        protected override void Dispose(bool disposing)
        {
            if (safeBuffer != null)
            {
                safeBuffer.ReleasePointer();
                safeBuffer = null;
            }

            if (accessor != null)
            {
                accessor.Dispose();
                accessor = null;
            }

            pointer = null;
        }
Ejemplo n.º 7
0
 [System.Security.SecurityCritical]  // auto-generated
 internal UnmanagedMemoryStream(SafeBuffer buffer, long offset, long length, FileAccess access, bool skipSecurityCheck) {
     Initialize(buffer, offset, length, access, skipSecurityCheck);
 }
Ejemplo n.º 8
0
 public StreamRange(StreamRef stream, MemoryMappedViewAccessor view, long offset, uint size, long actualOffset, long actualSize)
 {
     Stream = stream;
     View = view;
     CacheEntry = default(ViewCache.CacheEntry);
     Offset = offset;
     Size = size;
     Buffer = view.GetSafeBuffer();
     Pointer = null;
     Buffer.AcquirePointer(ref Pointer);
     IsDisposed = false;
     unchecked {
         Pointer += view.GetPointerOffset();
         Pointer += (offset - actualOffset);
     }
 }
 private static SecurityDescriptorSid QuerySid(SafeBuffer buffer, QuerySidFunc func)
 {
     IntPtr sid;
     bool sid_defaulted;
     func(buffer, out sid, out sid_defaulted).ToNtException();
     if (sid != IntPtr.Zero)
     {
         return new SecurityDescriptorSid(new Sid(sid), sid_defaulted);
     }
     return null;
 }
Ejemplo n.º 10
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 public UnmanagedMemoryStream(SafeBuffer buffer, long offset, long length, FileAccess access)
 {
     Initialize(buffer, offset, length, access, false);
 }
Ejemplo n.º 11
0
        [System.Security.SecurityCritical]  // auto-generated
        private void Initialize(SafeBuffer buffer, long offset, long length, FileAccess access, bool skipSecurityCheck)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException("length", SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (buffer.ByteLength < (ulong)(offset + length))
            {
                throw new ArgumentException(SR.Argument_InvalidSafeBufferOffLen);
            }
            if (access < FileAccess.Read || access > FileAccess.ReadWrite)
            {
                throw new ArgumentOutOfRangeException("access");
            }
            Contract.EndContractBlock();

            if (_isOpen)
            {
                throw new InvalidOperationException(SR.InvalidOperation_CalledTwice);
            }

            // check for wraparound
            unsafe
            {
                byte* pointer = null;

                try
                {
                    buffer.AcquirePointer(ref pointer);
                    if ((pointer + offset + length) < pointer)
                    {
                        throw new ArgumentException(SR.ArgumentOutOfRange_UnmanagedMemStreamWrapAround);
                    }
                }
                finally
                {
                    if (pointer != null)
                    {
                        buffer.ReleasePointer();
                    }
                }
            }

            _offset = offset;
            _buffer = buffer;
            _length = length;
            _capacity = length;
            _access = access;
            _isOpen = true;
        }
Ejemplo n.º 12
0
        internal unsafe static byte* AcquirePointer(object accessor, out SafeBuffer safeBuffer)
        {
            DebugCorlib.Assert(lazyIsAvailable.GetValueOrDefault());

            safeBuffer = (SafeBuffer)lazySafeMemoryMappedViewHandle.GetValue(accessor);

            byte* ptr = null;
            safeBuffer.AcquirePointer(ref ptr);

            long offset;
            if (lazyPointerOffset != null)
            {
                offset = (long)lazyPointerOffset.GetValue(accessor);
            }
            else
            {
                object internalView = lazyInternalViewField.GetValue(accessor);
                offset = (long)lazyInternalPointerOffset.GetValue(internalView);
            }

            return ptr + offset;
        }
Ejemplo n.º 13
0
		public UnmanagedMemoryStream (SafeBuffer buffer, long offset, long length) :
			this (buffer, offset, length, FileAccess.Read)
		{
		}
 internal unsafe void Initialize(SafeBuffer buffer, long offset, long length, FileAccess access, bool skipSecurityCheck)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (offset < 0L)
     {
         throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
     }
     if (length < 0L)
     {
         throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
     }
     if (buffer.ByteLength < (offset + length))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSafeBufferOffLen"));
     }
     if ((access < FileAccess.Read) || (access > FileAccess.ReadWrite))
     {
         throw new ArgumentOutOfRangeException("access");
     }
     if (this._isOpen)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CalledTwice"));
     }
     if (!skipSecurityCheck)
     {
         new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
     }
     byte* pointer = null;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         buffer.AcquirePointer(ref pointer);
         if (((pointer + offset) + length) < pointer)
         {
             throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamWrapAround"));
         }
     }
     finally
     {
         if (pointer != null)
         {
             buffer.ReleasePointer();
         }
     }
     this._offset = offset;
     this._buffer = buffer;
     this._length = length;
     this._capacity = length;
     this._access = access;
     this._isOpen = true;
 }
 /// <summary>
 /// Constructor from an unmanged buffer.
 /// </summary>
 /// <param name="sid">A safe buffer containing a valid SID.</param>
 /// <exception cref="NtException">Thrown if the buffer is not valid.</exception>
 public Sid(SafeBuffer sid) : this(sid.DangerousGetHandle())
 {
 }
 public UnmanagedMemoryStream(SafeBuffer buffer, long offset, long length)
 {
     this.Initialize(buffer, offset, length, FileAccess.Read, false);
 }
        private void ParseSecurityDescriptor(SafeBuffer buffer)
        {
            if (!NtRtl.RtlValidSecurityDescriptor(buffer))
            {
                throw new ArgumentException("Invalid security descriptor");
            }

            Owner = QuerySid(buffer, NtRtl.RtlGetOwnerSecurityDescriptor);
            Group = QuerySid(buffer, NtRtl.RtlGetGroupSecurityDescriptor);
            Dacl = QueryAcl(buffer, NtRtl.RtlGetDaclSecurityDescriptor);
            Sacl = QueryAcl(buffer, NtRtl.RtlGetSaclSecurityDescriptor);
            SecurityDescriptorControl control;
            uint revision;
            NtRtl.RtlGetControlSecurityDescriptor(buffer, out control, out revision).ToNtException();
            Control = control;
            Revision = revision;
        }
        private static Acl QueryAcl(SafeBuffer buffer, QueryAclFunc func)
        {
            IntPtr acl;
            bool acl_present;
            bool acl_defaulted;

            func(buffer, out acl_present, out acl, out acl_defaulted).ToNtException();
            if (!acl_present)
            {
                return null;
            }

            return new Acl(acl, acl_defaulted);
        }
Ejemplo n.º 19
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void Initialize(SafeBuffer buffer, long offset, long length, FileAccess access, bool skipSecurityCheck) {
            if (buffer == null) {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0) {
                throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (length < 0) {
                throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (buffer.ByteLength < (ulong)(offset + length)) {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSafeBufferOffLen"));
            }
            if (access < FileAccess.Read || access > FileAccess.ReadWrite) {
                throw new ArgumentOutOfRangeException("access");
            }
            Contract.EndContractBlock();

            if (_isOpen) {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CalledTwice"));
            }
            if (!skipSecurityCheck) {
#pragma warning disable 618
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
#pragma warning restore 618
            }

            // check for wraparound
            unsafe {
                byte* pointer = null;
                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    buffer.AcquirePointer(ref pointer);
                    if ( (pointer + offset + length) < pointer) {
                        throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamWrapAround"));
                    }
                }
                finally {
                    if (pointer != null) {
                        buffer.ReleasePointer();
                    }
                }
            }

            _offset = offset;
            _buffer = buffer;
            _length = length;
            _capacity = length;
            _access = access;
            _isOpen = true;
        }
Ejemplo n.º 20
0
 public CacheEntry(MemoryMappedViewAccessor view, long offset, uint size)
 {
     CreatedWhen = Time.Ticks;
     View = view;
     Offset = offset;
     Size = size;
     IsDisposed = false;
     _RefCount = 1;
     Buffer = view.GetSafeBuffer();
     Pointer = null;
     Buffer.AcquirePointer(ref Pointer);
     PointerOffset = view.GetPointerOffset();
 }
Ejemplo n.º 21
0
		protected void Initialize (SafeBuffer buffer, long offset, long length, FileAccess access)
		{
			if (buffer == null)
				throw new ArgumentNullException ("buffer");

			if (offset < 0)
				throw new ArgumentOutOfRangeException ("offset");

			if (length < 0)
				throw new ArgumentOutOfRangeException ("length");

			ulong blength = buffer.ByteLength;
			if ((blength - (ulong) length) < (ulong) offset)
				throw new ArgumentException ("Invalid offset and/or length");

			if (access < FileAccess.Read || access > FileAccess.ReadWrite)
				throw new ArgumentOutOfRangeException ("access");

			if (!closed)
				throw new InvalidOperationException ("Called Initialize twice");

			this.length = length;
			this.capacity = length;
			this.fileaccess = access;
			this.safebuffer = buffer;
			initial_position = offset;
			current_position = offset;
			closed = false;
		}
Ejemplo n.º 22
0
 internal SafeBufferAccessor(SafeBuffer buffer, long offset, long length, bool readOnly) {
     Debug.Assert(buffer != null, "buffer is null");
     Initialize(buffer, offset, length, readOnly ? FileAccess.Read : FileAccess.ReadWrite);
 }
Ejemplo n.º 23
0
		public UnmanagedMemoryStream (SafeBuffer buffer, long offset, long length, FileAccess access)
		{
			closed = true;
			Initialize (buffer, offset, length, access);
		}
 static extern NtStatus LsaLogonUser(SafeLsaHandle LsaHandle, LsaString OriginName, SecurityLogonType LogonType, uint AuthenticationPackage,
     SafeBuffer AuthenticationInformation,
     int AuthenticationInformationLength,
     IntPtr LocalGroups,
     TOKEN_SOURCE SourceContext,
     out IntPtr ProfileBuffer,
     out int ProfileBufferLength,
     out Luid LogonId,
     out SafeKernelObjectHandle Token,
     out QUOTA_LIMITS Quotas,
     out NtStatus SubStatus
 );
Ejemplo n.º 25
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 protected void Initialize(SafeBuffer buffer, long offset, long length, FileAccess access)
 {
     Initialize(buffer, offset, length, access, false);
 }
Ejemplo n.º 26
0
 public StreamRange(StreamRef stream, ViewCache.CacheEntry cacheEntry, long offset, uint size)
 {
     Stream = stream;
     CacheEntry = cacheEntry;
     View = null;
     Offset = offset;
     Size = size;
     Buffer = cacheEntry.Buffer;
     IsDisposed = false;
     unchecked {
         Pointer = cacheEntry.Pointer + cacheEntry.PointerOffset;
         Pointer += (offset - cacheEntry.Offset);
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="object_name">The object name, can be null.</param>
        /// <param name="attributes">The object attribute flags.</param>
        /// <param name="root">An optional root handle, can be SafeKernelObjectHandle.Null. Will duplicate the handle.</param>
        /// <param name="sqos">An optional security quality of service.</param>
        /// <param name="security_descriptor">An optional security descriptor.</param>
        public ObjectAttributes(string object_name, AttributeFlags attributes, SafeKernelObjectHandle root, 
            SecurityQualityOfService sqos, SecurityDescriptor security_descriptor)
        {
            Length = Marshal.SizeOf(this);
            if (object_name != null)
            {
                ObjectName = new UnicodeString(object_name).ToBuffer();
            }
            else
            {
                ObjectName = SafeHGlobalBuffer.Null;
            }

            Attributes = attributes;
            if (sqos != null)
            {
                SecurityQualityOfService = sqos.ToBuffer();
            }
            else
            {
                SecurityQualityOfService = SafeHGlobalBuffer.Null; 
            }

            RootDirectory = !root.IsInvalid ? NtObject.DuplicateHandle(root) : SafeKernelObjectHandle.Null;
            if (security_descriptor != null)
            {
                SecurityDescriptor = security_descriptor.ToSafeBuffer();
            }
            else
            {
                SecurityDescriptor = SafeHGlobalBuffer.Null;
            }
        }
Ejemplo n.º 28
0
        public StreamHeaderRef(MemoryMappedViewAccessor accessor)
        {
            Accessor = accessor;
            Buffer = accessor.GetSafeBuffer();

            byte* temp = null;
            Buffer.AcquirePointer(ref temp);

            Ptr = (StreamHeader*)temp;
        }
Ejemplo n.º 29
0
        internal unsafe static byte* AcquirePointer(object accessor, out SafeBuffer safeBuffer)
        {
            Debug.Assert(s_lazyIsAvailable.GetValueOrDefault());

            safeBuffer = (SafeBuffer)s_lazySafeMemoryMappedViewHandle.GetValue(accessor);

            byte* ptr = null;
            safeBuffer.AcquirePointer(ref ptr);

            try
            {
                long offset;
                if (s_lazyPointerOffset != null)
                {
                    offset = (long)s_lazyPointerOffset.GetValue(accessor);
                }
                else
                {
                    object internalView = s_lazyInternalViewField.GetValue(accessor);
                    offset = (long)s_lazyInternalPointerOffset.GetValue(internalView);
                }

                return ptr + offset;
            }
            catch (MemberAccessException)
            {
                s_lazyIsAvailable = false;
                return null;
            }
            catch (InvalidOperationException)
            {
                // thrown when accessing unapproved API in a Windows Store app
                s_lazyIsAvailable = false;
                return null;
            }
            catch (TargetInvocationException ex)
            {
                ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
                throw;
            }
        }
 [System.Security.SecuritySafeCritical]  // auto-generated
 public UnmanagedMemoryAccessor(SafeBuffer buffer, Int64 offset, Int64 capacity, FileAccess access)
 {
     Initialize(buffer, offset, capacity, access);
 }