forked from Endermanch/XPKeygen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.cpp
143 lines (110 loc) · 3.65 KB
/
key.cpp
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
//
// Created by Andrew on 09/04/2023.
//
#include "header.h"
/* Converts from byte sequence to the CD-key. */
void base24(char *cdKey, ul32 *byteSeq) {
byte rbs[16];
BIGNUM *z;
// Copy byte sequence to the reversed byte sequence.
memcpy(rbs, byteSeq, sizeof(rbs));
// Skip trailing zeroes and reverse y.
int length;
for (length = 15; rbs[length] == 0; length--);
endiannessConvert(rbs, ++length);
// Convert reversed byte sequence to BigNum z.
z = BN_bin2bn(rbs, length, nullptr);
// Divide z by 24 and convert the remainder to a CD-key char.
cdKey[25] = 0;
for (int i = 24; i >= 0; i--)
cdKey[i] = charset[BN_div_word(z, 24)];
BN_free(z);
}
/* Converts from CD-key to a byte sequence. */
void unbase24(ul32 *byteSeq, const char *cdKey) {
byte pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
BIGNUM *y = BN_new();
BN_zero(y);
// Remove dashes from the CD-key and put it into a Base24 byte array.
for (int i = 0, k = 0; i < strlen(cdKey) && k < PK_LENGTH; i++) {
for (int j = 0; j < 24; j++) {
if (cdKey[i] != '-' && cdKey[i] == charset[j]) {
pDecodedKey[k++] = j;
break;
}
}
}
// Empty byte sequence.
memset(byteSeq, 0, 16);
// Calculate the weighed sum of byte array elements.
for (int i = 0; i < PK_LENGTH; i++) {
BN_mul_word(y, PK_LENGTH - 1);
BN_add_word(y, pDecodedKey[i]);
}
// Acquire length.
int n = BN_num_bytes(y);
// Place the generated code into the byte sequence.
BN_bn2bin(y, (byte *)byteSeq);
BN_free(y);
// Reverse the byte sequence.
endiannessConvert((byte *) byteSeq, n);
}
/* Formats Windows XP key output. */
void formatXP(WCHAR *pBSection, WCHAR *pCSection, WCHAR *pText) {
WCHAR pFPK[32]{};
int pSSection = 0;
for (int i = 0; i < wcslen(pCSection); i++)
pSSection -= pCSection[i] - '0';
while (pSSection < 0)
pSSection += 7;
char pKey[PK_LENGTH + NULL_TERMINATOR]{};
ul32 msDigits = _wtoi(pBSection),
lsDigits = _wtoi(pCSection);
ul32 nRPK = msDigits * 1'000'000 + lsDigits,
hash = 0,
bKey[4]{},
bSig[2]{};
bool bValid = keyXP(pKey, nRPK);
unbase24(bKey, pKey);
unpackXP(nullptr, &hash, bSig, bKey);
for (int i = 0; i < 5; i++)
wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]);
wsprintfW(
pText,
L"Product ID:\tPPPPP-%03d-%06d%d-23XXX\r\n\r\nBytecode:\t%08lX %08lX %08lX %08lX\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n",
nRPK / 1'000'000,
nRPK % 1'000'000,
pSSection,
bKey[3], bKey[2], bKey[1], bKey[0],
hash,
bSig[1], bSig[0],
bValid ? L"True" : L"False",
pFPK
);
}
/* Formats Windows Server 2003 key output. */
void formatServer(WCHAR *pText) {
WCHAR pFPK[32]{};
char pKey[PK_LENGTH + NULL_TERMINATOR]{};
ul32 hash = 0,
osFamily = 0,
prefix = 0,
bKey[4]{},
bSig[2]{};
bool bValid = keyServer(pKey);
unbase24(bKey, pKey);
unpackServer(&osFamily, &hash, bSig, &prefix, bKey);
for (int i = 0; i < 5; i++)
wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]);
wsprintfW(
pText,
L"Bytecode:\t%08lX %08lX %08lX %08lX\r\nOS Family:\t%d\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nPrefix:\t\t%04lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n",
bKey[3], bKey[2], bKey[1], bKey[0],
osFamily,
hash,
bSig[1], bSig[0],
prefix,
bValid ? L"True" : L"False",
pFPK
);
}