Less dynamic memory allocation
This commit is contained in:
@@ -42,9 +42,9 @@ int get_test_device(libusb_context *usb_ctx, struct libusb_device_bundle *bundle
|
|||||||
void LIBUSB_CALL async_ctrl_transfer_cb(struct libusb_transfer *transfer)
|
void LIBUSB_CALL async_ctrl_transfer_cb(struct libusb_transfer *transfer)
|
||||||
{
|
{
|
||||||
printf("transfer status: %s (%i / %i)\n",
|
printf("transfer status: %s (%i / %i)\n",
|
||||||
libusb_error_name(transfer->status),
|
libusb_error_name(transfer->status),
|
||||||
transfer->actual_length,
|
transfer->actual_length,
|
||||||
transfer->length);
|
transfer->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void libusb1_async_ctrl_transfer(libusb_device_handle *handle,
|
void libusb1_async_ctrl_transfer(libusb_device_handle *handle,
|
||||||
@@ -114,28 +114,88 @@ void libusb1_no_error_ctrl_transfer(libusb_device_handle *handle,
|
|||||||
printf("%s\n", libusb_error_name(ret));
|
printf("%s\n", libusb_error_name(ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned char data_0xA_0xC0_buf[192] =
|
||||||
|
{
|
||||||
|
0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA,
|
||||||
|
0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA,
|
||||||
|
0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA,
|
||||||
|
0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA,
|
||||||
|
0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA, 0xA,
|
||||||
|
0xA, 0xA, 0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
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned char data_0x0_0x41_buf[65] =
|
||||||
|
{
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned char data_0x0_0xC0_buf[192] =
|
||||||
|
{
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
|
||||||
|
};
|
||||||
|
|
||||||
void stall(libusb_device_handle *handle)
|
void stall(libusb_device_handle *handle)
|
||||||
{
|
{
|
||||||
unsigned char *data = malloc(0xC0);
|
libusb1_async_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A,
|
||||||
memset(data, 0xA, 0xC0);
|
data_0xA_0xC0_buf, 0xC0, 1);
|
||||||
libusb1_async_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A, data, 0xC0, 1);
|
|
||||||
free(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void leak(libusb_device_handle *handle)
|
void leak(libusb_device_handle *handle)
|
||||||
{
|
{
|
||||||
unsigned char *data = malloc(0xC0);
|
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A,
|
||||||
memset(data, 0, 0xC0);
|
data_0x0_0xC0_buf, 0xC0, 1);
|
||||||
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A, data, 0xC0, 1);
|
|
||||||
free(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void no_leak(libusb_device_handle *handle)
|
void no_leak(libusb_device_handle *handle)
|
||||||
{
|
{
|
||||||
unsigned char *data = malloc(0xC1);
|
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A,
|
||||||
memset(data, 0, 0xC1);
|
data_0xA_0xC1_buf, 0xC1, 1);
|
||||||
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A, data, 0xC1, 1);
|
|
||||||
free(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_req_stall(libusb_device_handle *handle)
|
void usb_req_stall(libusb_device_handle *handle)
|
||||||
@@ -146,14 +206,13 @@ void usb_req_stall(libusb_device_handle *handle)
|
|||||||
|
|
||||||
void usb_req_leak(libusb_device_handle *handle)
|
void usb_req_leak(libusb_device_handle *handle)
|
||||||
{
|
{
|
||||||
unsigned char data[0x40];
|
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A,
|
||||||
memset(data, 0, 0x40);
|
data_0x0_0x40_buf, 0x40, 1);
|
||||||
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A, data, 0x40, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_req_no_leak(libusb_device_handle *handle)
|
void usb_req_no_leak(libusb_device_handle *handle)
|
||||||
{
|
{
|
||||||
unsigned char data[0x41];
|
|
||||||
memset(data, 0, 0x41);
|
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A,
|
||||||
libusb1_no_error_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A, data, 0x41, 1);
|
data_0x0_0x41_buf, 0x41, 1);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user