コード例 #1
0
        /// <summary>
        /// Unmarshal and validate the descriptor type from the marshaler buffer.
        /// </summary>
        /// <param name="marshaler">The marshaler containing raw data.</param>
        /// <returns>true indicates that the field is decoded successfully and valid.</returns>
        protected bool ReadDescriptorType(PduMarshaler marshaler)
        {
            bDescriptorType = UsbDescriptorTypes.UNKNOWN;
            byte b = marshaler.ReadByte();

            // TODO: don't hard-code.
            if (b > 8 || b < 1)
            {
                return(false);
            }

            bDescriptorType = (UsbDescriptorTypes)b;
            return(true);
        }
コード例 #2
0
        private UsbDescriptorStructure GetNextDescriptor(UsbDescriptorTypes descriptorType)
        {
            byte[] temp = new byte[2];
            UsbDescriptorStructure result = null;

            while (ms.Position < ms.Length - 2)
            {
                if (2 != ms.Read(temp, 0, 2))
                {
                    return(null);
                }

                UsbDescriptorStructure des = new UsbDescriptorStructure();
                PduMarshaler.Unmarshal(temp, des);

                if (des.bDescriptorType == descriptorType)
                {
                    ms.Seek(-2, SeekOrigin.Current);

                    switch (des.bDescriptorType)
                    {
                    case UsbDescriptorTypes.USB_INTERFACE_DESCRIPTOR_TYPE:
                        result = new USB_INTERFACE_DESCRIPTOR();
                        if (ParseDescriptor(USB_INTERFACE_DESCRIPTOR.DefaultSize, result))
                        {
                            return(result);
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                        //break;
                    }
                }
                else
                {
                    ms.Seek(des.bLength - 1, SeekOrigin.Current);
                }
            }
            return(result);
        }