-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstructs.h
146 lines (118 loc) · 3.05 KB
/
structs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#include <limits.h>
#include <cstdint>
// Taken from https://github.com/hjelmn/libusb-compat-0.1/blob/master/libusb/usb.h
#define LIST_ADD(begin, ent) \
do \
{ \
if (begin) \
{ \
ent->next = begin; \
ent->next->prev = ent; \
} \
else \
ent->next = NULL; \
ent->prev = NULL; \
begin = ent; \
} while (0)
typedef struct libusb_device_handle libusb_device_handle;
struct usb_dev_handle
{
libusb_device_handle *handle;
struct usb_device *device;
/* libusb-0.1 is buggy w.r.t. interface claiming. it allows you to claim
* multiple interfaces but only tracks the most recently claimed one,
* which is used for usb_set_altinterface(). we clone the buggy behaviour
* here. */
int last_claimed_interface;
};
struct usb_bus
{
struct usb_bus *next, *prev;
char dirname[PATH_MAX + 1];
struct usb_device *devices;
uint32_t location;
struct usb_device *root_dev;
};
// ripped from IDA
struct usb_endpoint_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
uint8_t bRefresh;
uint8_t bSynchAddress;
uint8_t* xtra;
int xtralen;
};
// also ripped from IDA
struct usb_interface_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
usb_endpoint_descriptor *endpoint;
uint8_t * xtra;
int xtralen;
};
struct usb_interface
{
usb_interface_descriptor *altsetting;
int num_altsetting;
};
struct usb_config_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t MaxPower;
usb_interface *interface;
unsigned char *extra; /* Extra descriptors */
int extralen;
};
/* Device descriptor */
struct usb_device_descriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
};
struct usb_device
{
usb_device *next, *prev;
char filename[PATH_MAX + 1];
usb_bus *bus;
usb_device_descriptor descriptor;
usb_config_descriptor *config;
void *dev; /* Darwin support */
uint8_t devnum;
unsigned char num_children;
struct usb_device **children;
};
struct usb_dev_handle;
typedef struct usb_dev_handle usb_dev_handle;
extern "C" struct usb_bus *usb_busses;