public override Guid BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            var bytes = buffer.GetBytes(0, 16);

            return(new Guid(bytes));
        }
Пример #2
0
        public override bool BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            var bytes = buffer.GetBytes();

            return(bytes.Any(b => b != 0));
        }
        public override TStruct BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            // Construct a new TStruct from the data in the buffer.
            var value = Marshal.PtrToStructure(buffer.Data, typeof(TStruct));

            return((TStruct)value);
        }
Пример #4
0
        public override TInteger BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            var integerSize = Marshal.SizeOf(typeof(TInteger));
            var bytes       = buffer.GetBytes(0, integerSize);

            return(_fromBytes(bytes));
        }
Пример #5
0
        public override GenericSecurityDescriptor BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            var bytes = buffer.GetBytes();

            var securityDescriptor = new RawSecurityDescriptor(bytes, 0);

            return(securityDescriptor);
        }
        public override string BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            var bytes = buffer.GetBytes();

            // Figure out how much data there is, ignoring any null terminator.
            var byteLength = bytes.Length;

            if (byteLength > 2 && bytes[byteLength - 1] == 0 && bytes[byteLength - 2] == 0)
            {
                byteLength -= 2;
            }

            return(Encoding.Unicode.GetString(bytes, 0, byteLength));
        }
        public override string[] BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            // All strings to be returned.
            var result = new List <string>();

            // Variables used during the string conversions.
            var data   = buffer.GetBytes();
            var offset = 0;
            var length = 0;

            // Don't go past the end of the data.
            while (offset < data.Length)
            {
                // Find out how many bytes are used for the string.
                for (length = 0; length + 2 <= data.Length; length += 2)
                {
                    if (data[offset + length] == 0 && data[offset + length + 1] == 0)
                    {
                        break;
                    }
                }

                // The list is terminate by a single empty string.
                if (length == 0)
                {
                    break;
                }

                // Get the string and add it to the result.
                var item = Encoding.Unicode.GetString(data, offset, length);
                result.Add(item);

                // Update the offset to point to the next string.
                offset += length + 2;
            }

            // Return the converted strings.
            return(result.ToArray());
        }
Пример #8
0
        public override byte[] BufferToValue(Api.Buffer buffer)
        {
            buffer.ThrowIfNull("buffer");

            return(buffer.GetBytes());
        }