I've posted a question in order to determinate hardware keylogger, but it seems its to complex and has blurry description, so nobody can answer.
For now my problem is narrowed to a single function call. I am trying to send output report to USB Keyboard with control transfer using libusb. And I am getting LIBUSB_ERROR_IO everytime with the description "Incorrect function" (GetLastError()=1). If doing tracing of libusb_control_transfer call, then the error occured once after DeviceIoControl call there. What that means? Does the device (usb KB) doesn't support output reports? Or maybe some required drivers needed? Testing on Windows 7sp1.
Here is my code:
int UsbKeyboard::SendOutputReport( )
{
auto kbdev = FindKeyboard(); // finds the keyboard device by product description
int r;
libusb_device_handle *devh = nullptr;
if ((r = libusb_open(kbdev, &devh)) < 0)
{
ShowError("Error open device", r);
return r;
}
r = libusb_set_configuration(devh, 1);
if (r < 0)
{
ShowError("libusb_set_configuration error ", r);
goto out;
}
libusb_set_debug(_context, 4);
r = libusb_claim_interface(devh, 0);
if (r < 0)
{
ShowError("libusb_claim_interface error ", r);
goto out;
}
unsigned char buf[65]; // trying to send LED packet
buf[0] = 0x2; // First byte is report number
buf[1] = 0x80;
// here is always error, r==-1 (LIBUSB_ERROR_IO)
r = libusb_control_transfer(devh, LIBUSB_ENDPOINT_OUT|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE,
HID_SET_REPORT/*0x9*/, (HID_REPORT_TYPE_OUTPUT/*0x2*/ << 8) | 0x00,
0, buf, (uint16_t)2, 1000);
if (r < 0) {
ShowError("Control Out error ", r);
goto out;
}
else
cout << "Control Transfer send OK - " << r << endl ;
out:
libusb_close(devh);
}
And libusb internals code:
// ...
// _windows_usb.c - _hid_set_report()
// This call returns FALSE and GetLastError()=1 (ERROR_INVALID_FUNCTION)
if (!DeviceIoControl(hid_handle, ioctl_code/*IOCTL_HID_SET_OUTPUT_REPORT*/, buf, write_size,
buf, write_size, &write_size, overlapped)) {
if (GetLastError() != ERROR_IO_PENDING) {
usbi_dbg("Failed to Write HID Output Report: %s", windows_error_str(0));
safe_free(buf);
return LIBUSB_ERROR_IO;
}
tp->hid_buffer = buf;
tp->hid_dest = NULL;
return LIBUSB_SUCCESS;
}
//...
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire