Пример #1
0
        public static void SendPayload(FileInfo info)
        {
            Writes = 0;
            byte[] payload = File.ReadAllBytes(info.FullName);
            var    buf     = new byte[0x10];

            Device.ReadPipe(0x81, buf, 0x10, out _, IntPtr.Zero);
            WritePayload(Device, SwizzlePayload(payload));

            if (Writes % 2 != 1)
            {
                Console.WriteLine("Switching buffers...");
                Device.WritePipe(1, new byte[0x1000], 0x1000, out _, IntPtr.Zero);
            }

            var setup = new WINUSB_SETUP_PACKET
            {
                RequestType = 0x81,
                Request     = 0,
                Value       = 0,
                Index       = 0,
                Length      = 0x7000
            };

            Task.Run(() => Device.ControlTransfer(setup, new byte[0x7000], 0x7000, out var b, IntPtr.Zero));
        }
        bool SendUsbControl(byte interfaceNum,
                            byte dir, byte type, byte recipient, byte request, ushort value, ushort index,
                            byte[] Buffer, uint BufferLength, out uint LengthTransferred)
        {
            bool retVal = false;
            WINUSB_SETUP_PACKET packet;

            packet.RequestType = (byte)((dir << 7) | (type << 5) | (recipient));
            packet.Request     = request;
            packet.Value       = value;
            packet.Index       = index;
            packet.Length      = 0;
            LengthTransferred  = 0;
            if (usb.ClaimInterface(interfaceNum, false))
            {
                if (usb.ControlTransfer(packet, Buffer, BufferLength, out LengthTransferred, IntPtr.Zero))
                {
                    retVal = true;
                }

                usb.ReleaseInterface(interfaceNum, false);
            }
            return(retVal);
        }