-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlibusbk_int.h
176 lines (156 loc) · 3.85 KB
/
libusbk_int.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma once
#include "Win32Def.h"
#include <libusbk.h>
#include <winioctl.h>
#pragma pack(push, 1)
namespace libusbk
{
struct interface_request_t
{
unsigned int interface_number;
unsigned int altsetting_number;
unsigned char intf_use_index: 1; // libusbK Only
unsigned char altf_use_index: 1; // libusbK Only
unsigned char: 6;
short interface_index; // libusbK Only
short altsetting_index; // libusbK Only
};
struct version_t
{
unsigned int major;
unsigned int minor;
unsigned int micro;
unsigned int nano;
unsigned int mod_value;
};
struct libusb_request
{
unsigned int timeout;
union
{
struct
{
unsigned int configuration;
} configuration;
interface_request_t intf; // libusbK Only
version_t version;
struct
{
unsigned int endpoint;
unsigned int packet_size;
unsigned int unused; // max_transfer_size is deprecated; (see pipe policies)
unsigned int transfer_flags;
unsigned int iso_start_frame_latency;
} endpoint;
struct
{
UCHAR PipeID;
ULONG IsoContextSize;
PKISO_CONTEXT IsoContext;
} IsoEx;
struct
{
UCHAR PipeID;
} AutoIsoEx;
struct
{
unsigned int type;
unsigned int recipient;
unsigned int request;
unsigned int value;
unsigned int index;
} vendor;
struct
{
unsigned int recipient;
unsigned int feature;
unsigned int index;
} feature;
struct
{
unsigned int recipient;
unsigned int index;
unsigned int status;
} status;
struct
{
unsigned int type;
unsigned int index;
unsigned int language_id;
unsigned int recipient;
} descriptor;
struct
{
unsigned int level;
} debug;
struct
{
unsigned int property;
} device_property;
struct
{
unsigned int key_type;
unsigned int name_offset;
unsigned int value_offset;
unsigned int value_length;
} device_registry_key;
struct
{
ULONG information_type;
} query_device;
struct
{
unsigned int interface_index;
unsigned int pipe_id;
unsigned int policy_type;
} pipe_policy;
struct
{
unsigned int policy_type;
} power_policy;
// WDF_USB_CONTROL_SETUP_PACKET control;
union
{
struct
{
UCHAR RequestType;
UCHAR Request;
USHORT Value;
USHORT Index;
USHORT Length;
} control;
};
};
};
constexpr DWORD LIBUSB_IOCTL_GET_VERSION = CTL_CODE(FILE_DEVICE_UNKNOWN, 0x812, METHOD_BUFFERED, FILE_ANY_ACCESS);
constexpr DWORD LIBUSB_IOCTL_GET_STATUS = CTL_CODE(FILE_DEVICE_UNKNOWN, 0x807, METHOD_BUFFERED, FILE_ANY_ACCESS);
};
#pragma pack(pop)
static inline bool libusbk_getInternals(KUSB_HANDLE handle, HANDLE* outMasterHandle=nullptr, HANDLE* outMasterInterfaceHandle=nullptr, LPCSTR* outDevicePath=nullptr, PUSB_CONFIGURATION_DESCRIPTOR* outConfigDescriptor=nullptr)
{
if (handle == nullptr)
return false;
auto byteHandle = (const unsigned char*)handle;
#if !_WIN64
memcpy(&byteHandle, &byteHandle[0x1C], sizeof(void*));
if (outMasterHandle != nullptr)
memcpy(outMasterHandle, &byteHandle[0x1C], sizeof(HANDLE));
if (outMasterInterfaceHandle != nullptr)
memcpy(outMasterInterfaceHandle, &byteHandle[0x20], sizeof(HANDLE));
if (outDevicePath != nullptr)
memcpy(outDevicePath, &byteHandle[0x24], sizeof(void*));
if (outConfigDescriptor != nullptr)
memcpy(outConfigDescriptor, &byteHandle[0x28], sizeof(void*));
#else
memcpy(&byteHandle, &byteHandle[0x30], sizeof(void*));
if (outMasterHandle != nullptr)
memcpy(outMasterHandle, &byteHandle[0x30], sizeof(HANDLE));
if (outMasterInterfaceHandle != nullptr)
memcpy(outMasterInterfaceHandle, &byteHandle[0x38], sizeof(HANDLE));
if (outDevicePath != nullptr)
memcpy(outDevicePath, &byteHandle[0x40], sizeof(void*));
if (outConfigDescriptor != nullptr)
memcpy(outConfigDescriptor, &byteHandle[0x48], sizeof(void*));
#endif
return true;
}