libusb-sniff: add libusb 1.0 support
This adds additional support for libusb-1.0 to the sniffing library. Afterwards it can be used with libusb 1.0 and libusb 0.1 based binaries.
This commit is contained in:
1 parent
d5028a12ca
commit
ed4bdab6e7
1 file changed
+129
@@ -27,7 +27,9 @@
|
||||
#include <dlfcn.h>
|
||||
|
||||
struct usb_dev_handle;
|
||||
struct libusb_device_handle;
|
||||
typedef struct usb_dev_handle usb_dev_handle;
|
||||
typedef struct libusb_device_handle libusb_device_handle;
|
||||
|
||||
static char to_ascii(char c) {
|
||||
|
||||
@@ -117,6 +119,54 @@ int usb_bulk_read(usb_dev_handle * dev, int ep, char * bytes, int size, int time
|
||||
|
||||
}
|
||||
|
||||
int libusb_bulk_transfer(libusb_device_handle *dev, unsigned char ep, unsigned char *bytes, int size, int *actual_length, unsigned int timeout) {
|
||||
|
||||
static int (*real_libusb_bulk_transfer)(libusb_device_handle *dev, unsigned char ep, unsigned char *bytes, int size, int *actual_length, unsigned int timeout) = NULL;
|
||||
int ret;
|
||||
|
||||
if ( ! real_libusb_bulk_transfer )
|
||||
*(void **)(&real_libusb_bulk_transfer) = dlsym(RTLD_NEXT, "libusb_bulk_transfer");
|
||||
|
||||
if ( ep == 0x81 ) {
|
||||
|
||||
ret = real_libusb_bulk_transfer(dev, ep, bytes, size, actual_length, timeout);
|
||||
|
||||
if ( ! getenv("USBSNIFF_SKIP_READ") ) {
|
||||
|
||||
printf("\n==== usb_bulk_read (ep=%d size=%d timeout=%d) ret = %d ====\n", ep, size, timeout, (ret < 0) ? ret : *actual_length);
|
||||
if ( ret == 0 ) {
|
||||
dump_bytes((char*) bytes, *actual_length);
|
||||
printf("====\n");
|
||||
}
|
||||
|
||||
if ( getenv("USBSNIFF_WAIT") ) {
|
||||
printf("Press ENTER"); fflush(stdout); getchar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
|
||||
if ( ! getenv("USBSNIFF_SKIP_WRITE") ) {
|
||||
|
||||
printf("\n==== usb_bulk_write (ep=%d size=%d timeout=%d) ====\n", ep, size, timeout);
|
||||
dump_bytes((char*) bytes, size);
|
||||
printf("====\n");
|
||||
|
||||
if ( getenv("USBSNIFF_WAIT") ) {
|
||||
printf("Press ENTER"); fflush(stdout); getchar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return real_libusb_bulk_transfer(dev, ep, bytes, size, actual_length, timeout);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout) {
|
||||
|
||||
static int (*real_usb_control_msg)(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout) = NULL;
|
||||
@@ -157,6 +207,46 @@ int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value
|
||||
|
||||
}
|
||||
|
||||
int libusb_control_msg(libusb_device_handle *dev, int requesttype, int request, int value, int index, unsigned char *bytes, int size, int timeout) {
|
||||
|
||||
static int (*real_usb_control_msg)(libusb_device_handle *dev, int requesttype, int request, int value, int index, unsigned char *bytes, int size, int timeout) = NULL;
|
||||
int ret;
|
||||
|
||||
if ( ! real_usb_control_msg )
|
||||
*(void **)(&real_usb_control_msg) = dlsym(RTLD_NEXT, "libusb_control_msg");
|
||||
|
||||
if ( requesttype == 64 && ! getenv("USBSNIFF_SKIP_CONTROL") ) {
|
||||
|
||||
printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ====\n", requesttype, request, value, index, size, timeout);
|
||||
dump_bytes((char*) bytes, size);
|
||||
printf("====\n");
|
||||
|
||||
if ( getenv("USBSNIFF_WAIT") ) {
|
||||
printf("Press ENTER"); fflush(stdout); getchar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ret = real_usb_control_msg(dev, requesttype, request, value, index, bytes, size, timeout);
|
||||
|
||||
if ( requesttype != 64 && ! getenv("USBSNIFF_SKIP_CONTROL") ) {
|
||||
|
||||
printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ret = %d ====\n", requesttype, request, value, index, size, timeout, ret);
|
||||
if ( ret > 0 ) {
|
||||
dump_bytes((char*) bytes, ret);
|
||||
printf("====\n");
|
||||
}
|
||||
|
||||
if ( getenv("USBSNIFF_WAIT") ) {
|
||||
printf("Press ENTER"); fflush(stdout); getchar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int usb_set_configuration(usb_dev_handle *dev, int configuration) {
|
||||
|
||||
static int (*real_usb_set_configuration)(usb_dev_handle *dev, int configuration) = NULL;
|
||||
@@ -170,6 +260,19 @@ int usb_set_configuration(usb_dev_handle *dev, int configuration) {
|
||||
|
||||
}
|
||||
|
||||
int libusb_set_configuration(libusb_device_handle *dev, int configuration) {
|
||||
|
||||
static int (*real_usb_set_configuration)(libusb_device_handle *dev, int configuration) = NULL;
|
||||
|
||||
if ( ! real_usb_set_configuration )
|
||||
*(void **)(&real_usb_set_configuration) = dlsym(RTLD_NEXT, "libusb_set_configuration");
|
||||
|
||||
printf("\n==== usb_set_configuration (configuration=%d) ====\n", configuration);
|
||||
|
||||
return real_usb_set_configuration(dev, configuration);
|
||||
|
||||
}
|
||||
|
||||
int usb_claim_interface(usb_dev_handle *dev, int interface) {
|
||||
|
||||
static int (*real_usb_claim_interface)(usb_dev_handle *dev, int interface) = NULL;
|
||||
@@ -183,6 +286,19 @@ int usb_claim_interface(usb_dev_handle *dev, int interface) {
|
||||
|
||||
}
|
||||
|
||||
int libusb_claim_interface(libusb_device_handle *dev, int interface) {
|
||||
|
||||
static int (*real_usb_claim_interface)(libusb_device_handle *dev, int interface) = NULL;
|
||||
|
||||
if ( ! real_usb_claim_interface )
|
||||
*(void **)(&real_usb_claim_interface) = dlsym(RTLD_NEXT, "libusb_claim_interface");
|
||||
|
||||
printf("\n==== usb_claim_interface (interface=%d) ====\n", interface);
|
||||
|
||||
return real_usb_claim_interface(dev, interface);
|
||||
|
||||
}
|
||||
|
||||
int usb_set_altinterface(usb_dev_handle *dev, int alternate) {
|
||||
|
||||
static int (*real_usb_set_altinterface)(usb_dev_handle *dev, int alternate) = NULL;
|
||||
@@ -195,3 +311,16 @@ int usb_set_altinterface(usb_dev_handle *dev, int alternate) {
|
||||
return real_usb_set_altinterface(dev, alternate);
|
||||
|
||||
}
|
||||
|
||||
int libusb_set_interface_alt_setting(libusb_device_handle *dev, int interface, int alternate) {
|
||||
|
||||
static int (*real_usb_set_altinterface)(libusb_device_handle *dev, int interface, int alternate) = NULL;
|
||||
|
||||
if ( ! real_usb_set_altinterface )
|
||||
*(void **)(&real_usb_set_altinterface) = dlsym(RTLD_NEXT, "libusb_set_interface_alt_setting");
|
||||
|
||||
printf("\n==== usb_set_altinterface (alternate=%d) ====\n", alternate);
|
||||
|
||||
return real_usb_set_altinterface(dev, interface, alternate);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user