| 435 | } |
| 436 | |
| 437 | bool Interception_Worker::getUSBDeviceDescriptor(ushort vendor_id, ushort product_id, QString &iManufacturer, QString &iProduct) |
| 438 | { |
| 439 | if (!s_libusb_available) { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | libusb_device_handle *handle; |
| 444 | libusb_device *dev; |
| 445 | struct libusb_device_descriptor dev_desc; |
| 446 | char string[256]; |
| 447 | |
| 448 | handle = libusb_open_device_with_vid_pid(NULL, vendor_id, product_id); |
| 449 | if (handle == NULL) { |
| 450 | #ifdef DEBUG_LOGOUT_ON |
| 451 | QString vendorIdStr = QString("0x%1").arg(QString::number(vendor_id, 16).toUpper(), 4, '0'); |
| 452 | QString productIdStr = QString("0x%1").arg(QString::number(product_id, 16).toUpper(), 4, '0'); |
| 453 | qDebug().nospace().noquote() << "[getUSBDeviceDescriptor] Failed to open USB device -> " << "VendorID = " << vendorIdStr << ", ProductID = " << productIdStr; |
| 454 | #endif |
| 455 | return false; |
| 456 | } |
| 457 | |
| 458 | dev = libusb_get_device(handle); |
| 459 | int ret = libusb_get_device_descriptor(dev, &dev_desc); |
| 460 | if (ret != LIBUSB_SUCCESS) { |
| 461 | #ifdef DEBUG_LOGOUT_ON |
| 462 | qDebug() << "[getUSBDeviceDescriptor] Failed to get device descriptor :" << ret; |
| 463 | #endif |
| 464 | libusb_close(handle); |
| 465 | return false; |
| 466 | } |
| 467 | |
| 468 | if (dev_desc.iManufacturer) { |
| 469 | ret = libusb_get_string_descriptor_ascii(handle, dev_desc.iManufacturer, (unsigned char*)string, sizeof(string)); |
| 470 | if (ret > 0) { |
| 471 | iManufacturer = QString::fromLatin1(string, ret); |
| 472 | } else { |
| 473 | #ifdef DEBUG_LOGOUT_ON |
| 474 | qDebug() << "[getUSBDeviceDescriptor] Failed to get iManufacturer string descriptor :" << ret; |
| 475 | #endif |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | if (dev_desc.iProduct) { |
| 480 | ret = libusb_get_string_descriptor_ascii(handle, dev_desc.iProduct, (unsigned char*)string, sizeof(string)); |
| 481 | if (ret > 0) { |
| 482 | iProduct = QString::fromLatin1(string, ret); |
| 483 | } else { |
| 484 | #ifdef DEBUG_LOGOUT_ON |
| 485 | qDebug() << "[getUSBDeviceDescriptor] Failed to get iProduct string descriptor :" << ret; |
| 486 | #endif |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | libusb_close(handle); |
| 491 | return true; |
| 492 | } |
| 493 | |
| 494 | QHash<QString, USBDeviceInfo> Interception_Worker::parseUSBIDs(const QString &filePath) |
nothing calls this directly
no outgoing calls
no test coverage detected