/// <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(); }
/// <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); }
/// <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)); }
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); }
/// <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); }
/// <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); }
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()); } }
/// <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)); }
/// <summary> /// Constructor. /// </summary> /// <param name="attribute_flag">The single attribute flag which this represents.</param> protected AlpcMessageAttribute(AlpcMessageAttributeFlags attribute_flag) { AttributeFlag = attribute_flag; }
/// <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)); }
/// <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);