Guest User

Untitled

a guest
Nov 10th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <libusb-1.0/libusb.h>
  5.  
  6. const int interface_number = 0;
  7.  
  8. int main(int argc, char** argv) {
  9.     int result;
  10.  
  11.     result = libusb_init(NULL);
  12.     if (result) {
  13.         printf("Failed to initialize libusb: %s\n", libusb_error_name(result));
  14.         return EXIT_FAILURE;
  15.     }
  16.  
  17.     libusb_device_handle* device_handle = libusb_open_device_with_vid_pid(NULL, 0x2104, 0x0313);
  18.     if (!device_handle) {
  19.         printf("Failed to open device\n");
  20.         return EXIT_FAILURE;
  21.     }
  22.  
  23.     libusb_set_auto_detach_kernel_driver(device_handle, true);
  24.     result = libusb_claim_interface(device_handle, interface_number);
  25.     if (result) {
  26.         printf("Failed to claim interface: %s\n", libusb_error_name(result));
  27.         return EXIT_FAILURE;
  28.     }
  29.  
  30.     uint8_t write_buffer[] = {
  31.         0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00,
  32.         0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x1b,
  33.         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x58,
  34.         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
  35.         0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00,
  36.         0x00, 0x00, 0x03
  37.     };
  38.     int length;
  39.     result = libusb_bulk_transfer(device_handle, 0x5, write_buffer, sizeof(write_buffer), &length, 1000);
  40.     if (result) {
  41.         printf("Failed to write data: %s\n", libusb_error_name(result));
  42.         return EXIT_FAILURE;
  43.     }
  44.  
  45.     uint8_t read_buffer[32] = {0};
  46.     result = libusb_bulk_transfer(device_handle, 0x83, read_buffer, sizeof(read_buffer), &length, 1000);
  47.     if (result) {
  48.         printf("Failed to read data: %s\n", libusb_error_name(result));
  49.         return EXIT_FAILURE;
  50.     }
  51.  
  52.     libusb_release_interface(device_handle, interface_number);
  53.  
  54.     libusb_close(device_handle);
  55.  
  56.     libusb_exit(NULL);
  57.  
  58.     return EXIT_SUCCESS;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment