internal void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message) { var result = buffer.Result; var valid_attrs = result.ValidAttributes; if (valid_attrs.HasFlag(AlpcMessageAttributeFlags.Token)) { AddAttribute <AlpcTokenMessageAttribute>(buffer, port, message); } if (valid_attrs.HasFlag(AlpcMessageAttributeFlags.Context)) { AddAttribute <AlpcContextMessageAttribute>(buffer, port, message); } if (valid_attrs.HasFlag(AlpcMessageAttributeFlags.Handle)) { var attribute = AddAttribute <AlpcHandleMessageAttribute>(buffer, port, message); _handles.AddRange(attribute.Handles.Select(h => NtObjectUtils.FromHandle(h.Handle, true))); } if (valid_attrs.HasFlag(AlpcMessageAttributeFlags.Security)) { var attr = AddAttribute <AlpcSecurityMessageAttribute>(buffer, port, message); SecurityContext = new SafeAlpcSecurityContextHandle(attr.ContextHandle, true, port, attr.Flags, attr.SecurityQoS); } if (valid_attrs.HasFlag(AlpcMessageAttributeFlags.View)) { var attr = AddAttribute <AlpcDataViewMessageAttribute>(buffer, port, message); DataView = new SafeAlpcDataViewBuffer(new IntPtr(attr.ViewBase), attr.ViewSize, new SafeAlpcPortSectionHandle(attr.SectionHandle, true, port), attr.Flags, true); } if (valid_attrs.HasFlag(AlpcMessageAttributeFlags.WorkOnBehalfOf)) { AddAttribute <AlpcWorkOnBehalfMessageAttribute>(buffer, port, message); } }
internal T AddAttribute <T>(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message) where T : AlpcMessageAttribute, new() { T attribute = new T(); attribute.FromSafeBuffer(buffer, port, message); _attributes.Add(attribute.AttributeFlag, attribute); ValidAttributes |= attribute.AttributeFlag; return(attribute); }
/// <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); }
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()); } }
internal override void ToSafeBuffer(SafeAlpcMessageAttributesBuffer buffer) { buffer.SetWorkOnBehalfAttribute(this); }
internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message) { buffer.GetWorkOnBehalfAttribute(this); }
internal override void ToSafeBuffer(SafeAlpcMessageAttributesBuffer buffer) { buffer.SetDirectAttribute(this); }
internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message) { throw new NotImplementedException(); }
internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message) { buffer.GetHandleAttribute(this, port, message); }
internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message) { buffer.GetSecurityAttribute(this); }
internal abstract void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message);
internal abstract void ToSafeBuffer(SafeAlpcMessageAttributesBuffer buffer);
SafeAlpcMessageAttributesBuffer IMessageAttributes.ToSafeBuffer() { return(SafeAlpcMessageAttributesBuffer.Create(AllocatedAttributes)); }