Exemple #1
0
        public void OnInitialize(USBSimulatorDevice device)
        {
            _device = device;

            Endpoints = new List <EndpointInformation>();
            Endpoints.Add(new EndpointInformation(0x01, EndpointInformation.EndpointDirection.Outgoing,
                                                  EndpointInformation.EndpointType.Bulk, 0x40));
            Endpoints.Add(new EndpointInformation(0x03, EndpointInformation.EndpointDirection.Incoming,
                                                  EndpointInformation.EndpointType.Bulk, 0x40));
        }
Exemple #2
0
        public void OnInitialize(USBSimulatorDevice device)
        {
            _device   = device;
            _messages = new Queue <byte[]>();

            //Start message queueing thread
            _sendThread = new Thread(new ThreadStart(_SendMessages));
            _sendThread.IsBackground = true;
            _sendThread.Start();

            //Build endpoint information
            Endpoints = new List <EndpointInformation>();
            Endpoints.Add(new EndpointInformation(0x01,
                                                  EndpointInformation.EndpointDirection.Incoming, EndpointInformation.EndpointType.Interrupt, 0x08));
        }
        public void OnInitialize(USBSimulatorDevice device)
        {
            _device = device;

            //Fill the endpoint list as completely as we can
            Endpoints = new List <EndpointInformation>();
            int transferred;
            var configuration = new byte[255];
            int index         = 0;

            if (_forwardee.GetDescriptor(0x02, 0x00, 0x00, configuration, 255, out transferred))
            {
                //NOTE: Only supporting one configuration
                int totalLength = configuration[2] | (configuration[3] << 8);
                while (index < totalLength)
                {
                    if (configuration[index + 1] == 0x05)
                    {
                        //This is an endpoint descriptor
                        int endpoint = configuration[index + 2] & 0x7F;

                        if ((configuration[index + 2] & 0x80) > 0)
                        {
                            //Incoming endpoint
                            _readers.Add(endpoint, _forwardee.OpenEndpointReader(_GetReadEndpointId(endpoint)));
                            _readers[endpoint].DataReceived       += DeviceForwarder_DataReceived;
                            _readers[endpoint].DataReceivedEnabled = true;
                            Endpoints.Add(new EndpointInformation(endpoint, EndpointInformation.EndpointDirection.Incoming,
                                                                  (EndpointInformation.EndpointType)configuration[index + 3], configuration[index + 4] | (configuration[index + 5] << 8)));
                        }
                        else
                        {
                            //Outgoing endpoint
                            _writers.Add(endpoint, _forwardee.OpenEndpointWriter(_GetWriteEndpointId(endpoint)));
                            Endpoints.Add(new EndpointInformation(endpoint, EndpointInformation.EndpointDirection.Outgoing,
                                                                  (EndpointInformation.EndpointType)configuration[index + 3], configuration[index + 4] | (configuration[index + 5] << 8)));
                        }
                    }

                    index += configuration[index];
                }
            }
        }
        public void OnInitialize(USBSimulatorDevice device)
        {
            _device = device;

              //Set up the endpoints
              Endpoints = new List<EndpointInformation>();
              Endpoints.Add(new EndpointInformation(0x01,
            EndpointInformation.EndpointDirection.Incoming, EndpointInformation.EndpointType.Bulk, 0x40));
              Endpoints.Add(new EndpointInformation(0x02,
            EndpointInformation.EndpointDirection.Outgoing, EndpointInformation.EndpointType.Bulk, 0x40));
        }
Exemple #5
0
        static void Main()
        {
            Logger.Level          = Logger.LoggingLevel.Verbose;
            Logger.LogEntryAdded += Logger_LogEntryAdded;

            _device = new USBSimulatorDevice();

            if (_device != null)
            {
                Console.WriteLine("Specify device to simulate:");
                Console.WriteLine("\t1: Mass storage device");
                Console.WriteLine("\t2: HID keyboard");
                Console.WriteLine("\t3: Forwarder");
                Console.WriteLine("\t4: Serial adapter");
                Console.WriteLine();

                bool done = false;
                while (!done)
                {
                    done = true;
                    switch (Console.ReadKey(true).Key)
                    {
                    case ConsoleKey.D1:
                        _device.CurrentDevice = new MassStorageDevice(0xAAAA, 0xABCD, "test.img", 65536,
                                                                      "Brandon", "Virtual Drive", 1.00);
                        break;

                    case ConsoleKey.D2:
                        _device.CurrentDevice = new HIDKeyboard(0xDEAD, 0xBEEF);
                        break;

                    case ConsoleKey.D3:
                        _device.CurrentDevice = new DeviceForwarder(0x0451, 0xE004);
                        break;

                    case ConsoleKey.D4:
                        _device.CurrentDevice = new SerialAdapter();
                        break;

                    default:
                        done = false;
                        break;
                    }
                }

                Console.WriteLine("Keys:");
                Console.WriteLine("\tF1: Attach device to host.");
                Console.WriteLine("\tF2: Detach device from host.");
                Console.WriteLine("\tF3: Reset interface (in case simulator was unplugged).");
                if (_device.CurrentDevice as HIDKeyboard != null)
                {
                    Console.WriteLine("\tS:  Send sample keypress data.");
                }
                Console.WriteLine("Press [ESC] to disconnect and quit.");

                while (true)
                {
                    if (Console.KeyAvailable)
                    {
                        var key = Console.ReadKey(true).Key;
                        if (key == ConsoleKey.Escape)
                        {
                            break;
                        }
                        else if (key == ConsoleKey.S)
                        {
                            var d = _device.CurrentDevice as HIDKeyboard;

                            if (d != null)
                            {
                                d.ClearKeypresses();
                                d.ClearKeypresses();
                                d.ClearKeypresses();
                                d.SendKey(HIDKeyboard.KeyboardModifier.LeftGUI, HIDKeyboard.KeyboardKey.LetterR);
                                d.SendString("notepad");
                                d.SendKey(HIDKeyboard.KeyboardKey.Enter);
                                d.SendString("This is a test of the emergency broadcast system.");
                                d.SendKey(HIDKeyboard.KeyboardKey.Enter);
                                d.SendKey(HIDKeyboard.KeyboardKey.Enter);
                                d.SendString("Haha, I own you!");
                                d.SendKey(HIDKeyboard.KeyboardKey.Enter);
                                d.SendKey(HIDKeyboard.KeyboardModifier.LeftGUI, HIDKeyboard.KeyboardKey.LetterR);
                                d.SendString("cmd");
                                d.SendKey(HIDKeyboard.KeyboardKey.Enter);
                            }
                        }
                        else if (key == ConsoleKey.F1)
                        {
                            _device.AttachDevice();
                        }
                        else if (key == ConsoleKey.F2)
                        {
                            _device.DetachDevice();
                        }
                        else if (key == ConsoleKey.F3)
                        {
                            _device.Reset();
                        }
                    }

                    Thread.Sleep(10);
                }

                _device.DetachDevice();
                Thread.Sleep(1000); //HACK: Give time to detach properly
                _device.Close();
            }
        }
        public void OnInitialize(USBSimulatorDevice device)
        {
            _device = device;

              //Fill the endpoint list as completely as we can
              Endpoints = new List<EndpointInformation>();
              int transferred;
              var configuration = new byte[255];
              int index = 0;
              if (_forwardee.GetDescriptor(0x02, 0x00, 0x00, configuration, 255, out transferred))
              {
            //NOTE: Only supporting one configuration
            int totalLength = configuration[2] | (configuration[3] << 8);
            while (index < totalLength)
            {
              if (configuration[index + 1] == 0x05)
              {
            //This is an endpoint descriptor
            int endpoint = configuration[index + 2] & 0x7F;

            if ((configuration[index + 2] & 0x80) > 0)
            {
              //Incoming endpoint
              _readers.Add(endpoint, _forwardee.OpenEndpointReader(_GetReadEndpointId(endpoint)));
              _readers[endpoint].DataReceived += DeviceForwarder_DataReceived;
              _readers[endpoint].DataReceivedEnabled = true;
              Endpoints.Add(new EndpointInformation(endpoint, EndpointInformation.EndpointDirection.Incoming,
                (EndpointInformation.EndpointType)configuration[index + 3], configuration[index + 4] | (configuration[index + 5] << 8)));
            }
            else
            {
              //Outgoing endpoint
              _writers.Add(endpoint, _forwardee.OpenEndpointWriter(_GetWriteEndpointId(endpoint)));
              Endpoints.Add(new EndpointInformation(endpoint, EndpointInformation.EndpointDirection.Outgoing,
                (EndpointInformation.EndpointType)configuration[index + 3], configuration[index + 4] | (configuration[index + 5] << 8)));
            }
              }

              index += configuration[index];
            }
              }
        }
        public void OnInitialize(USBSimulatorDevice device)
        {
            _device = device;
              _messages = new Queue<byte[]>();

              //Start message queueing thread
              _sendThread = new Thread(new ThreadStart(_SendMessages));
              _sendThread.IsBackground = true;
              _sendThread.Start();

              //Build endpoint information
              Endpoints = new List<EndpointInformation>();
              Endpoints.Add(new EndpointInformation(0x01,
            EndpointInformation.EndpointDirection.Incoming, EndpointInformation.EndpointType.Interrupt, 0x08));
        }