예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
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);
        }
예제 #4
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());
            }
        }
예제 #5
0
 internal override void ToSafeBuffer(SafeAlpcMessageAttributesBuffer buffer)
 {
     buffer.SetWorkOnBehalfAttribute(this);
 }
예제 #6
0
 internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message)
 {
     buffer.GetWorkOnBehalfAttribute(this);
 }
예제 #7
0
 internal override void ToSafeBuffer(SafeAlpcMessageAttributesBuffer buffer)
 {
     buffer.SetDirectAttribute(this);
 }
예제 #8
0
 internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message)
 {
     buffer.GetHandleAttribute(this, port, message);
 }
예제 #10
0
 internal override void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message)
 {
     buffer.GetSecurityAttribute(this);
 }
예제 #11
0
 internal abstract void FromSafeBuffer(SafeAlpcMessageAttributesBuffer buffer, NtAlpc port, AlpcMessage message);
예제 #12
0
 internal abstract void ToSafeBuffer(SafeAlpcMessageAttributesBuffer buffer);
예제 #13
0
 SafeAlpcMessageAttributesBuffer IMessageAttributes.ToSafeBuffer()
 {
     return(SafeAlpcMessageAttributesBuffer.Create(AllocatedAttributes));
 }