modified: myjupyterlab.sh
[GalaxyCodeBases.git] / etc / Windows / vlmcsd_old_vancepym / kms.h
blobc4542e9d985f6c7976a71f692ce400c1c1cf74bd
1 #ifndef __kms_h
2 #define __kms_h
4 #ifndef CONFIG
5 #define CONFIG "config.h"
6 #endif // CONFIG
7 #include CONFIG
9 #include <sys/time.h>
10 #include <stdlib.h>
11 #include "types.h"
13 // REQUEST... types are actually fixed size
14 // RESPONSE... size may vary, defined here is max possible size
17 #define MAX_RESPONSE_SIZE 384
18 #define PID_BUFFER_SIZE 64
19 #define MAX_REQUEST_SIZE sizeof(REQUEST_V6)
20 #define WORKSTATION_NAME_BUFFER 64
22 // Constants for V6 time stamp interval
23 #define TIME_C1 0x00000022816889BDULL
24 #define TIME_C2 0x000000208CBAB5EDULL
25 #define TIME_C3 0x3156CD5AC628477AULL
27 #define VERSION_INFO union \
28 { \
29 DWORD Version;\
30 struct { \
31 WORD MinorVer; \
32 WORD MajorVer; \
33 } /*__packed*/; \
34 } /*__packed*/
36 // Aliases for various KMS struct members
37 #define IsClientVM VMInfo
38 #define GraceTime BindingExpiration
39 #define MinutesRemaingInCurrentStatus BindingExpiration
40 #define ID ActID
41 #define ApplicationID AppID
42 #define SkuId ActID
43 #define KmsId KMSID
44 #define ClientMachineId CMID
45 #define MinimumClients N_Policy
46 #define TimeStamp ClientTime
47 #define PreviousCLientMachineId CMID_prev
48 #define Salt IV
49 #define XorSalt XoredIVs
50 #define ActivationInterval VLActivationInterval
51 #define RenewalInterval VLRenewalInterval
54 typedef struct {
55 VERSION_INFO;
56 DWORD VMInfo; // 0 = client is bare metal / 1 = client is VM
57 DWORD LicenseStatus; // 0 = Unlicensed, 1 = Licensed (Activated), 2 = OOB grace, 3 = OOT grace, 4 = NonGenuineGrace, 5 = Notification, 6 = extended grace
58 DWORD BindingExpiration; // Expiration of the current status in minutes (e.g. when KMS activation or OOB grace expires).
59 GUID AppID; // Can currently be Windows, Office2010 or Office2013 (see kms.c, table AppList).
60 GUID ActID; // Most detailed product list. One product key per ActID (see kms.c, table ExtendedProductList). Is ignored by KMS server.
61 GUID KMSID; // This is actually what the KMS server uses to grant or refuse activation (see kms.c, table BasicProductList).
62 GUID CMID; // Client machine id. Used by the KMS server for counting minimum clients.
63 DWORD N_Policy; // Minimum clients required for activation.
64 FILETIME ClientTime; // Current client time.
65 GUID CMID_prev; // previous client machine id. All zeros, if it never changed.
66 WCHAR WorkstationName[64]; // Workstation name. FQDN if available, NetBIOS otherwise.
67 } /*__packed*/ REQUEST;
69 typedef struct {
70 VERSION_INFO;
71 DWORD PIDSize; // Size of PIDData in bytes.
72 WCHAR KmsPID[PID_BUFFER_SIZE]; // ePID (must include terminating zero)
73 GUID CMID; // Client machine id. Must be the same as in request.
74 FILETIME ClientTime; // Current client time. Must be the same as in request.
75 DWORD Count; // Current activated machines. KMS server counts up to N_Policy << 1 then stops
76 DWORD VLActivationInterval; // Time in minutes when clients should retry activation if it was unsuccessful (default 2 hours)
77 DWORD VLRenewalInterval; // Time in minutes when clients should renew KMS activation (default 7 days)
78 } /*__packed*/ RESPONSE;
80 #ifdef _DEBUG
81 typedef struct {
82 VERSION_INFO;
83 DWORD PIDSize;
84 WCHAR KmsPID[49]; // Set this to the ePID length you want to debug
85 GUID CMID;
86 FILETIME ClientTime;
87 DWORD Count;
88 DWORD VLActivationInterval;
89 DWORD VLRenewalInterval;
90 } __packed RESPONSE_DEBUG;
91 #endif
94 typedef struct {
95 REQUEST RequestBase; // Base request
96 BYTE MAC[16]; // Aes 160 bit CMAC
97 } /*__packed*/ REQUEST_V4;
99 typedef struct {
100 RESPONSE ResponseBase; // Base response
101 BYTE MAC[16]; // Aes 160 bit CMAC
102 } /*__packed*/ RESPONSE_V4;
105 typedef struct {
106 VERSION_INFO; // unencrypted version info
107 BYTE IV[16]; // IV
108 REQUEST RequestBase; // Base Request
109 BYTE Pad[4]; // since this struct is fixed, we use fixed PKCS pad bytes
110 } /*__packed*/ REQUEST_V5;
112 typedef REQUEST_V5 REQUEST_V6; // v5 and v6 requests are identical
114 typedef struct {
115 VERSION_INFO;
116 BYTE IV[16];
117 RESPONSE ResponseBase;
118 BYTE RandomXoredIVs[16]; // If RequestIV was used for decryption: Random ^ decrypted Request IV ^ ResponseIV. If NULL IV was used for decryption: Random ^ decrypted Request IV
119 BYTE Hash[32]; // SHA256 of Random used in RandomXoredIVs
120 BYTE HwId[8]; // HwId from the KMS server
121 BYTE XoredIVs[16]; // If RequestIV was used for decryption: decrypted Request IV ^ ResponseIV. If NULL IV was used for decryption: decrypted Request IV.
122 BYTE HMAC[16]; // V6 Hmac (low 16 bytes only), see kms.c CreateV6Hmac
123 //BYTE Pad[10]; // Pad is variable sized. So do not include in struct
124 } /*__packed*/ RESPONSE_V6;
126 typedef struct { // not used except for sizeof(). Fields are the same as RESPONSE_V6
127 VERSION_INFO;
128 BYTE IV[16];
129 RESPONSE ResponseBase;
130 BYTE RandomXoredIVs[16];
131 BYTE Hash[32];
132 } /*__packed*/ RESPONSE_V5;
134 #ifdef _DEBUG
135 typedef struct { // Debug structure for direct casting of RPC data in debugger
136 VERSION_INFO;
137 BYTE IV[16];
138 RESPONSE_DEBUG ResponseBase;
139 BYTE RandomXoredIVs[16];
140 BYTE MAC[32];
141 BYTE Unknown[8];
142 BYTE XorSalts[16];
143 BYTE HMAC[16];
144 BYTE Pad[16];
145 } __packed RESPONSE_V6_DEBUG;
146 #endif
148 #define V4_PRE_EPID_SIZE ( \
149 sizeof(((RESPONSE*)0)->Version) + \
150 sizeof(((RESPONSE*)0)->PIDSize) \
153 #define V4_POST_EPID_SIZE ( \
154 sizeof(((RESPONSE*)0)->CMID) + \
155 sizeof(((RESPONSE*)0)->ClientTime) + \
156 sizeof(((RESPONSE*)0)->Count) + \
157 sizeof(((RESPONSE*)0)->VLActivationInterval) + \
158 sizeof(((RESPONSE*)0)->VLRenewalInterval) \
161 #define V6_DECRYPT_SIZE ( \
162 sizeof(((REQUEST_V6*)0)->IV) + \
163 sizeof(((REQUEST_V6*)0)->RequestBase) + \
164 sizeof(((REQUEST_V6*)0)->Pad) \
167 #define V6_UNENCRYPTED_SIZE ( \
168 sizeof(((RESPONSE_V6*)0)->Version) + \
169 sizeof(((RESPONSE_V6*)0)->IV) \
172 #define V6_PRE_EPID_SIZE ( \
173 V6_UNENCRYPTED_SIZE + \
174 sizeof(((RESPONSE*)0)->Version) + \
175 sizeof(((RESPONSE*)0)->PIDSize) \
178 #define V5_POST_EPID_SIZE ( \
179 V4_POST_EPID_SIZE + \
180 sizeof(((RESPONSE_V6*)0)->RandomXoredIVs) + \
181 sizeof(((RESPONSE_V6*)0)->Hash) \
184 #define V6_POST_EPID_SIZE ( \
185 V5_POST_EPID_SIZE + \
186 sizeof(((RESPONSE_V6*)0)->HwId) + \
187 sizeof(((RESPONSE_V6*)0)->XoredIVs) + \
188 sizeof(((RESPONSE_V6*)0)->HMAC) \
191 #define RESPONSE_RESULT_OK ((1 << 10) - 1) //(9 bits)
192 typedef union
194 DWORD mask;
195 struct
197 BOOL HashOK : 1;
198 BOOL TimeStampOK : 1;
199 BOOL ClientMachineIDOK : 1;
200 BOOL VersionOK : 1;
201 BOOL IVsOK : 1;
202 BOOL DecryptSuccess : 1;
203 BOOL HmacSha256OK : 1;
204 BOOL PidLengthOK : 1;
205 BOOL RpcOK : 1;
206 BOOL IVnotSuspicious : 1;
207 BOOL reserved3 : 1;
208 BOOL reserved4 : 1;
209 BOOL reserved5 : 1;
210 BOOL reserved6 : 1;
211 uint32_t effectiveResponseSize : 9;
212 uint32_t correctResponseSize : 9;
214 } RESPONSE_RESULT;
216 typedef BYTE hwid_t[8];
218 typedef struct
220 GUID guid;
221 const char* name;
222 const char* pid;
223 uint8_t AppIndex;
224 uint8_t KmsIndex;
225 } KmsIdList;
227 #define KMS_PARAM_MAJOR AppIndex
228 #define KMS_PARAM_REQUIREDCOUNT KmsIndex
230 #define APP_ID_WINDOWS 0
231 #define APP_ID_OFFICE2010 1
232 #define APP_ID_OFFICE2013 2
234 #define KMS_ID_VISTA 0
235 #define KMS_ID_WIN7 1
236 #define KMS_ID_WIN8_VL 2
237 #define KMS_ID_WIN_BETA 3
238 #define KMS_ID_WIN8_RETAIL 4
239 #define KMS_ID_WIN81_VL 5
240 #define KMS_ID_WIN81_RETAIL 6
241 #define KMS_ID_WIN2008A 7
242 #define KMS_ID_WIN2008B 8
243 #define KMS_ID_WIN2008C 9
244 #define KMS_ID_WIN2008R2A 10
245 #define KMS_ID_WIN2008R2B 11
246 #define KMS_ID_WIN2008R2C 12
247 #define KMS_ID_WIN2012 13
248 #define KMS_ID_WIN2012R2 14
249 #define KMS_ID_OFFICE2010 15
250 #define KMS_ID_OFFICE2013 16
251 #define KMS_ID_WIN_SRV_BETA 17
252 #define KMS_ID_OFFICE2016 18
253 #define KMS_ID_WIN10_VL 19
254 #define KMS_ID_WIN10_RETAIL 20
256 #define PWINGUID &AppList[APP_ID_WINDOWS].guid
257 #define POFFICE2010GUID &AppList[APP_ID_OFFICE2010].guid
258 #define POFFICE2013GUID &AppList[APP_ID_OFFICE2013].guid
260 typedef BOOL(__stdcall *RequestCallback_t)(const REQUEST *const baseRequest, RESPONSE *const baseResponse, BYTE *const hwId, const char* const ipstr);
262 size_t CreateResponseV4(REQUEST_V4 *const Request, BYTE *const response_data, const char* const ipstr);
263 size_t CreateResponseV6(REQUEST_V6 *restrict Request, BYTE *const response_data, const char* const ipstr);
264 BYTE *CreateRequestV4(size_t *size, const REQUEST* requestBase);
265 BYTE *CreateRequestV6(size_t *size, const REQUEST* requestBase);
266 void randomPidInit();
267 void get16RandomBytes(void* ptr);
268 RESPONSE_RESULT DecryptResponseV6(RESPONSE_V6* Response_v6, int responseSize, BYTE* const response, const BYTE* const request, BYTE* hwid);
269 RESPONSE_RESULT DecryptResponseV4(RESPONSE_V4* Response_v4, const int responseSize, BYTE* const response, const BYTE* const request);
270 void getUnixTimeAsFileTime(FILETIME *const ts);
271 __pure int64_t fileTimeToUnixTime(const FILETIME *const ts);
272 const char* getProductNameHE(const GUID *const guid, const KmsIdList *const List, ProdListIndex_t *const i);
273 const char* getProductNameLE(const GUID *const guid, const KmsIdList *const List, ProdListIndex_t *const i);
274 __pure ProdListIndex_t getExtendedProductListSize();
275 __pure ProdListIndex_t getAppListSize(void);
277 extern const KmsIdList ProductList[];
278 extern const KmsIdList AppList[];
279 extern const KmsIdList ExtendedProductList[];
281 extern RequestCallback_t CreateResponseBase;
283 #ifdef _PEDANTIC
284 uint16_t IsValidLcid(const uint16_t Lcid);
285 #endif // _PEDANTIC
287 #endif // __kms_h