Exemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public AlpcReceiveMessageAttributes(AlpcMessageAttributeFlags allocated_attributes)
 {
     AllocatedAttributes = allocated_attributes;
     _attributes         = new Dictionary <AlpcMessageAttributeFlags, AlpcMessageAttribute>();
     _handles            = new DisposableList <NtObject>();
     DataView            = new SafeAlpcDataViewBuffer();
     SecurityContext     = new SafeAlpcSecurityContextHandle();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Get an attribute.
 /// </summary>
 /// <param name="flag">The attribute flag to get.</param>
 /// <returns>The attribute. Returns null if not found.</returns>
 public AlpcMessageAttribute GetAttribute(AlpcMessageAttributeFlags flag)
 {
     if (_attributes.ContainsKey(flag))
     {
         return(_attributes[flag]);
     }
     return(null);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get an attribute as a structured type.
        /// </summary>
        /// <typeparam name="T">The attribute type.</typeparam>
        /// <param name="attribute">The attribute.</param>
        /// <returns>A buffer which represents the structured type.</returns>
        /// <exception cref="NtException">Thrown if attribute doesn't exist.</exception>
        public SafeStructureInOutBuffer <T> GetAttribute <T>(AlpcMessageAttributeFlags attribute) where T : new()
        {
            IntPtr attr = GetAttributePointer(attribute);

            if (attr == IntPtr.Zero)
            {
                throw new NtException(NtStatus.STATUS_INVALID_PARAMETER);
            }
            return(new SafeStructureInOutBuffer <T>(attr, Marshal.SizeOf(typeof(T)), false));
        }
Exemplo n.º 4
0
        private void ClearAttributes(AlpcMessage msg, AlpcReceiveMessageAttributes attributes)
        {
            AlpcMessageAttributeFlags flags = attributes.ValidAttributes & (AlpcMessageAttributeFlags.View | AlpcMessageAttributeFlags.Handle);

            if (!msg.ContinuationRequired || flags == 0)
            {
                return;
            }

            _client.Send(AlpcMessageFlags.None, msg, attributes.ToContinuationAttributes(flags), NtWaitTimeout.Infinite);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a new buffer with allocations for a specified set of attributes.
        /// </summary>
        /// <param name="flags">The attributes to allocate.</param>
        /// <returns>The allocated buffed.</returns>
        public static SafeAlpcMessageAttributesBuffer Create(AlpcMessageAttributeFlags flags)
        {
            NtStatus status = NtAlpcNativeMethods.AlpcInitializeMessageAttribute(flags, Null, 0, out int size);

            if (status != NtStatus.STATUS_BUFFER_TOO_SMALL)
            {
                throw new NtException(status);
            }

            SafeAlpcMessageAttributesBuffer buffer = new SafeAlpcMessageAttributesBuffer(size);

            NtAlpcNativeMethods.AlpcInitializeMessageAttribute(flags, buffer, buffer.Length, out size).ToNtException();
            return(buffer);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Convert this set of attributes to one which can be used to free on continuation required.
        /// </summary>
        /// <param name="attributes">The attributes to </param>
        /// <returns>The send attributes.</returns>
        public AlpcSendMessageAttributes ToContinuationAttributes(AlpcMessageAttributeFlags attributes)
        {
            AlpcSendMessageAttributes ret = new AlpcSendMessageAttributes();

            if ((ValidAttributes & attributes & AlpcMessageAttributeFlags.View) != 0)
            {
                ret.Add(new AlpcDataViewMessageAttribute(0, 0, 0, AlpcDataViewAttrFlags.ReleaseView));
            }
            if ((ValidAttributes & attributes & AlpcMessageAttributeFlags.Handle) != 0)
            {
                ret.Add(new AlpcHandleMessageAttribute());
            }
            return(ret);
        }
Exemplo n.º 7
0
        SafeAlpcMessageAttributesBuffer IMessageAttributes.ToSafeBuffer()
        {
            if (_attributes.Count == 0)
            {
                return(SafeAlpcMessageAttributesBuffer.Null);
            }

            AlpcMessageAttributeFlags flags = AllocatedAttributes;

            using (var buffer = SafeAlpcMessageAttributesBuffer.Create(flags)) {
                foreach (var attr in _attributes.Values)
                {
                    attr.ToSafeBuffer(buffer);
                }

                var result = buffer.Result;
                result.ValidAttributes = flags;
                buffer.Result          = result;
                return(buffer.Detach());
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Get a pointer to an allocated attribute. Returns NULL if not available.
 /// </summary>
 /// <param name="attribute">The attribute to get.</param>
 /// <returns>The pointer to the attribute buffer, IntPtr.Zero if not found.</returns>
 public IntPtr GetAttributePointer(AlpcMessageAttributeFlags attribute)
 {
     return(NtAlpcNativeMethods.AlpcGetMessageAttribute(this, attribute));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attribute_flag">The single attribute flag which this represents.</param>
 protected AlpcMessageAttribute(AlpcMessageAttributeFlags attribute_flag)
 {
     AttributeFlag = attribute_flag;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Checks if an attribute flag is valid.
 /// </summary>
 /// <param name="attribute">The attribute to test.</param>
 /// <returns>True if the attribute is value.</returns>
 public bool HasValidAttribute(AlpcMessageAttributeFlags attribute)
 {
     return(ValidAttributes.HasFlag(attribute));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Remove an attribute object.
 /// </summary>
 /// <param name="flag">The attribute flag to remove.</param>
 public void Remove(AlpcMessageAttributeFlags flag)
 {
     _attributes.Remove(flag);
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public NewNtAlpcReceiveAttributesCmdlet()
 {
     Attributes = AlpcMessageAttributeFlags.AllAttributes;
 }
 public static extern IntPtr AlpcGetMessageAttribute(
     SafeAlpcMessageAttributesBuffer Buffer,
     AlpcMessageAttributeFlags AttributeFlag
     );
 public static extern NtStatus AlpcInitializeMessageAttribute(
     AlpcMessageAttributeFlags AttributeFlags,
     SafeAlpcMessageAttributesBuffer Buffer,
     int BufferSize,
     out int RequiredBufferSize
     );
 public static extern int AlpcGetHeaderSize(AlpcMessageAttributeFlags Flags);