Created
December 31, 2022 19:00
-
-
Save petabyt/33297a4bf77a1b217acbc58e6af7afab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/ioctl.h> | |
#include <errno.h> | |
#include <usb.h> | |
#include <linux/usbdevice_fs.h> | |
#include <stdio.h> | |
int inep; | |
int outep; | |
int intep; | |
void probeUsb(struct usb_device *dev) { | |
int n = dev->config->interface->altsetting->bNumEndpoints; | |
printf("Endpoints: %d\n", n); | |
struct usb_endpoint_descriptor *ep = dev->config->interface->altsetting->endpoint; | |
for (int i = 0; i < n; i++) { | |
if (ep[i].bmAttributes == USB_ENDPOINT_TYPE_BULK) { | |
if ((ep[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == | |
USB_ENDPOINT_DIR_MASK) { | |
printf("Found inep: 0x%02x\n", ep[i].bEndpointAddress); | |
inep = ep[i].bEndpointAddress; | |
} | |
if ((ep[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == 0) { | |
printf("Found outep: 0x%02x\n", ep[i].bEndpointAddress); | |
outep = ep[i].bEndpointAddress; | |
} | |
} else if ((ep[i].bmAttributes == USB_ENDPOINT_TYPE_INTERRUPT) && | |
((ep[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == | |
USB_ENDPOINT_DIR_MASK)) { | |
printf("Found intep: 0x%02x\n", ep[i].bEndpointAddress); | |
intep = ep[i].bEndpointAddress; | |
} | |
} | |
struct usb_dev_handle *devh = usb_open(dev); | |
if (devh == NULL) { | |
perror("usb_open() failure"); | |
return; | |
} else { | |
if (usb_set_configuration(devh, dev->config->bConfigurationValue)) { | |
perror("usb_set_configuration() failure"); | |
usb_close(devh); | |
return; | |
} | |
if (usb_claim_interface(devh, 0)) { | |
perror("usb_claim_interface() failure"); | |
usb_close(devh); | |
return; | |
} | |
} | |
puts("In a connection"); | |
char buffer[512]; | |
// Try to send a command (?) | |
char export[] = {0x0, 0x29, 0, 0}; | |
int x = usb_bulk_write( | |
devh, | |
outep, | |
export, 4, 1000); | |
printf("Sent %d bytes\n", x); | |
x = usb_bulk_read( | |
devh, | |
intep, // Can't get anything on inep, 0 on intep | |
buffer, 512, 1000); | |
FILE *f = fopen("dump", "w"); | |
fwrite(buffer, x, 1, f); | |
fclose(f); | |
printf("Read %d bytes\n", x); | |
usb_close(devh); | |
puts("Disconnected"); | |
} | |
int main() { | |
usb_init(); | |
usb_find_busses(); | |
usb_find_devices(); | |
struct usb_bus *bus = usb_get_busses(); | |
struct usb_device *dev; | |
while (bus != NULL) { | |
dev = bus->devices; | |
while (dev) { | |
int ic = dev->config->interface->altsetting->bInterfaceClass; | |
int vend = dev->descriptor.idVendor; | |
printf("Trying %s\n", dev->filename); | |
printf("Interface class: %X\n", ic); | |
printf("Vendor: %X\n", vend); | |
if (vend == 0x4CB && ic == 0xFF) | |
probeUsb(dev); | |
puts("----"); | |
dev = dev->next; | |
} | |
bus = bus->next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment