Ejemplo n.º 1
0
        /// <summary>
        /// Get a named attribute from the pipe.
        /// </summary>
        /// <param name="attribute_type">The attribute type to query.</param>
        /// <param name="name">The name of the attribute.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The attribute value as a byte array.</returns>
        /// <exception cref="NtException">Thrown on error.</exception>
        public NtResult <byte[]> GetAttribute(PipeAttributeType attribute_type, string name, bool throw_on_error)
        {
            NtIoControlCode ioctl = GetAttributeToIoCtl(attribute_type);

            int size = 128;

            byte[] name_buffer = Encoding.ASCII.GetBytes(name + "\0");
            while (size < 4096)
            {
                var result = FsControl(ioctl, name_buffer, size, false);
                if (result.IsSuccess)
                {
                    return(result);
                }

                if (result.Status != NtStatus.STATUS_BUFFER_TOO_SMALL)
                {
                    result.Status.ToNtException(throw_on_error);
                    return(result);
                }

                size *= 2;
            }

            return(NtStatus.STATUS_BUFFER_TOO_SMALL.CreateResultFromError <byte[]>(throw_on_error));
        }
 /// <summary>
 /// Convert a control code to a known name.
 /// </summary>
 /// <param name="control_code">The control code.</param>
 /// <returns>The known name, or an empty string.</returns>
 public static string KnownControlCodeToName(NtIoControlCode control_code)
 {
     if (_control_code_to_name.ContainsKey(control_code))
     {
         return(_control_code_to_name[control_code]);
     }
     return(string.Empty);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Set a named attribute for a pipe.
        /// </summary>
        /// <param name="attribute_type">The attribute type to set.</param>
        /// <param name="name">The name of the attribute.</param>
        /// <param name="value">The value to set.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The status code for the attribute.</returns>
        /// <exception cref="NtException">Thrown on error.</exception>
        public NtStatus SetAttribute(PipeAttributeType attribute_type, string name, byte[] value, bool throw_on_error)
        {
            NtIoControlCode ioctl = SetAttributeToIoCtl(attribute_type);

            byte[]       name_bytes = Encoding.ASCII.GetBytes(name);
            MemoryStream stm        = new MemoryStream();

            stm.Write(name_bytes, 0, name_bytes.Length);
            stm.WriteByte(0);
            stm.Write(value, 0, value.Length);

            return(FsControl(ioctl, stm.ToArray(), 0, throw_on_error).Status);
        }