mirror of
https://github.com/Neo-Desktop/WindowsXPKg
synced 2024-11-22 05:41:01 +02:00
Data type consistency uplift
This commit is contained in:
parent
3f95974e61
commit
06920ede2a
@ -51,7 +51,7 @@ Options parseCommandLine(int argc, char* argv[]) {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_product_id(uint32_t *pid)
|
void print_product_id(DWORD *pid)
|
||||||
{
|
{
|
||||||
char raw[12];
|
char raw[12];
|
||||||
char b[6], c[8];
|
char b[6], c[8];
|
||||||
|
10
src/header.h
10
src/header.h
@ -58,7 +58,7 @@ typedef uint64_t QWORD;
|
|||||||
extern char charset[];
|
extern char charset[];
|
||||||
|
|
||||||
// util.cpp
|
// util.cpp
|
||||||
void endian(uint8_t *data, int length);
|
void endian(BYTE *data, int length);
|
||||||
EC_GROUP *initializeEllipticCurve(
|
EC_GROUP *initializeEllipticCurve(
|
||||||
std::string pSel,
|
std::string pSel,
|
||||||
std::string aSel,
|
std::string aSel,
|
||||||
@ -72,12 +72,12 @@ EC_GROUP *initializeEllipticCurve(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// key.cpp
|
// key.cpp
|
||||||
void unbase24(uint32_t *byteSeq, const char *cdKey);
|
void unbase24(DWORD *byteSeq, const char *cdKey);
|
||||||
void base24(char *cdKey, uint32_t *byteSeq);
|
void base24(char *cdKey, DWORD *byteSeq);
|
||||||
|
|
||||||
// cli.cpp
|
// cli.cpp
|
||||||
void print_product_key(char *pk);
|
void print_product_key(char *pk);
|
||||||
void print_product_id(uint32_t *pid);
|
void print_product_id(DWORD *pid);
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
std::string binkid;
|
std::string binkid;
|
||||||
@ -93,7 +93,7 @@ void showHelp(char *argv[]);
|
|||||||
|
|
||||||
// xp.cpp
|
// xp.cpp
|
||||||
bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, char *cdKey);
|
bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, char *cdKey);
|
||||||
void generateXPKey(char *pKey, EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *order, BIGNUM *privateKey, uint32_t *pRaw);
|
void generateXPKey(char *pKey, EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *order, BIGNUM *privateKey, DWORD *pRaw);
|
||||||
|
|
||||||
// server.cpp
|
// server.cpp
|
||||||
|
|
||||||
|
12
src/key.cpp
12
src/key.cpp
@ -5,8 +5,8 @@
|
|||||||
#include "header.h"
|
#include "header.h"
|
||||||
|
|
||||||
/* Converts from CD-key to a byte sequence. */
|
/* Converts from CD-key to a byte sequence. */
|
||||||
void unbase24(uint32_t *byteSeq, const char *cdKey) {
|
void unbase24(DWORD *byteSeq, const char *cdKey) {
|
||||||
uint8_t pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
|
BYTE pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
|
||||||
BIGNUM *y = BN_new();
|
BIGNUM *y = BN_new();
|
||||||
|
|
||||||
BN_zero(y);
|
BN_zero(y);
|
||||||
@ -34,16 +34,16 @@ void unbase24(uint32_t *byteSeq, const char *cdKey) {
|
|||||||
int n = BN_num_bytes(y);
|
int n = BN_num_bytes(y);
|
||||||
|
|
||||||
// Place the generated code into the byte sequence.
|
// Place the generated code into the byte sequence.
|
||||||
BN_bn2bin(y, (uint8_t *)byteSeq);
|
BN_bn2bin(y, (BYTE *)byteSeq);
|
||||||
BN_free(y);
|
BN_free(y);
|
||||||
|
|
||||||
// Reverse the byte sequence.
|
// Reverse the byte sequence.
|
||||||
endian((uint8_t *)byteSeq, n);
|
endian((BYTE *)byteSeq, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Converts from byte sequence to the CD-key. */
|
/* Converts from byte sequence to the CD-key. */
|
||||||
void base24(char *cdKey, uint32_t *byteSeq) {
|
void base24(char *cdKey, DWORD *byteSeq) {
|
||||||
uint8_t rbyteSeq[16];
|
BYTE rbyteSeq[16];
|
||||||
BIGNUM *z;
|
BIGNUM *z;
|
||||||
|
|
||||||
// Copy byte sequence to the reversed byte sequence.
|
// Copy byte sequence to the reversed byte sequence.
|
||||||
|
@ -106,7 +106,7 @@ int main(int argc, char *argv[]) {
|
|||||||
// Calculation
|
// Calculation
|
||||||
char pKey[25];
|
char pKey[25];
|
||||||
|
|
||||||
uint32_t nRaw = options.channelID * 1000000 ; /* <- change */
|
DWORD nRaw = options.channelID * 1000000 ; /* <- change */
|
||||||
|
|
||||||
BIGNUM *bnrand = BN_new();
|
BIGNUM *bnrand = BN_new();
|
||||||
BN_rand(bnrand, 19, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY);
|
BN_rand(bnrand, 19, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY);
|
||||||
|
@ -345,10 +345,10 @@ int main()
|
|||||||
assert(EC_POINT_is_on_curve(ec, pub, ctx) == 1);
|
assert(EC_POINT_is_on_curve(ec, pub, ctx) == 1);
|
||||||
|
|
||||||
char pkey[25];
|
char pkey[25];
|
||||||
uint32_t osfamily[1], prefix[1];
|
DWORD osfamily[1], prefix[1];
|
||||||
|
|
||||||
osfamily[0] = 1280;
|
osfamily[0] = 1280;
|
||||||
RAND_bytes((uint8_t *)prefix, 4);
|
RAND_bytes((BYTE *)prefix, 4);
|
||||||
prefix[0] &= 0x3ff;
|
prefix[0] &= 0x3ff;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -10,9 +10,9 @@ int randomRange() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Convert data between endianness types. */
|
/* Convert data between endianness types. */
|
||||||
void endian(uint8_t *data, int length) {
|
void endian(BYTE *data, int length) {
|
||||||
for (int i = 0; i < length / 2; i++) {
|
for (int i = 0; i < length / 2; i++) {
|
||||||
uint8_t temp = data[i];
|
BYTE temp = data[i];
|
||||||
data[i] = data[length - i - 1];
|
data[i] = data[length - i - 1];
|
||||||
data[length - i - 1] = temp;
|
data[length - i - 1] = temp;
|
||||||
}
|
}
|
||||||
|
28
src/xp.cpp
28
src/xp.cpp
@ -18,7 +18,7 @@
|
|||||||
#include "header.h"
|
#include "header.h"
|
||||||
|
|
||||||
/* Unpacks the Windows XP Product Key. */
|
/* Unpacks the Windows XP Product Key. */
|
||||||
void unpackXP(uint32_t *serial, uint32_t *hash, uint32_t *sig, uint32_t *raw) {
|
void unpackXP(DWORD *serial, DWORD *hash, DWORD *sig, DWORD *raw) {
|
||||||
|
|
||||||
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
||||||
// log2(24^25) = 114.
|
// log2(24^25) = 114.
|
||||||
@ -39,7 +39,7 @@ void unpackXP(uint32_t *serial, uint32_t *hash, uint32_t *sig, uint32_t *raw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Packs the Windows XP Product Key. */
|
/* Packs the Windows XP Product Key. */
|
||||||
void packXP(uint32_t *raw, const uint32_t *serial, const uint32_t *hash, const uint32_t *sig) {
|
void packXP(DWORD *raw, const DWORD *serial, const DWORD *hash, const DWORD *sig) {
|
||||||
raw[0] = serial[0] | ((hash[0] & 1) << 31);
|
raw[0] = serial[0] | ((hash[0] & 1) << 31);
|
||||||
raw[1] = (hash[0] >> 1) | ((sig[0] & 0x1f) << 27);
|
raw[1] = (hash[0] >> 1) | ((sig[0] & 0x1f) << 27);
|
||||||
raw[2] = (sig[0] >> 5) | (sig[1] << 27);
|
raw[2] = (sig[0] >> 5) | (sig[1] << 27);
|
||||||
@ -51,8 +51,8 @@ bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, cha
|
|||||||
BN_CTX *context = BN_CTX_new();
|
BN_CTX *context = BN_CTX_new();
|
||||||
|
|
||||||
// Convert Base24 CD-key to bytecode.
|
// Convert Base24 CD-key to bytecode.
|
||||||
uint32_t bKey[4]{};
|
DWORD bKey[4]{};
|
||||||
uint32_t pID, checkHash, sig[2];
|
DWORD pID, checkHash, sig[2];
|
||||||
|
|
||||||
unbase24(bKey, cdKey);
|
unbase24(bKey, cdKey);
|
||||||
|
|
||||||
@ -68,8 +68,8 @@ bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, cha
|
|||||||
BN_set_word(e, checkHash);
|
BN_set_word(e, checkHash);
|
||||||
|
|
||||||
// Reverse signature and create a new BigNum s.
|
// Reverse signature and create a new BigNum s.
|
||||||
endian((uint8_t *)sig, sizeof(sig));
|
endian((BYTE *)sig, sizeof(sig));
|
||||||
s = BN_bin2bn((uint8_t *)sig, sizeof(sig), nullptr);
|
s = BN_bin2bn((BYTE *)sig, sizeof(sig), nullptr);
|
||||||
|
|
||||||
// Create x and y.
|
// Create x and y.
|
||||||
BIGNUM *x = BN_new();
|
BIGNUM *x = BN_new();
|
||||||
@ -95,8 +95,8 @@ bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, cha
|
|||||||
// x = v.x; y = v.y;
|
// x = v.x; y = v.y;
|
||||||
EC_POINT_get_affine_coordinates(eCurve, v, x, y, context);
|
EC_POINT_get_affine_coordinates(eCurve, v, x, y, context);
|
||||||
|
|
||||||
uint8_t buf[FIELD_BYTES], md[SHA_DIGEST_LENGTH], t[4];
|
BYTE buf[FIELD_BYTES], md[SHA_DIGEST_LENGTH], t[4];
|
||||||
uint32_t newHash;
|
DWORD newHash;
|
||||||
|
|
||||||
SHA_CTX hContext;
|
SHA_CTX hContext;
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ bool verifyXPKey(EC_GROUP *eCurve, EC_POINT *generator, EC_POINT *publicKey, cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate a valid Product Key. */
|
/* Generate a valid Product Key. */
|
||||||
void generateXPKey(char *pKey, EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *order, BIGNUM *privateKey, uint32_t *pRaw) {
|
void generateXPKey(char *pKey, EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *order, BIGNUM *privateKey, DWORD *pRaw) {
|
||||||
EC_POINT *r = EC_POINT_new(eCurve);
|
EC_POINT *r = EC_POINT_new(eCurve);
|
||||||
BN_CTX *ctx = BN_CTX_new();
|
BN_CTX *ctx = BN_CTX_new();
|
||||||
|
|
||||||
@ -159,10 +159,10 @@ void generateXPKey(char *pKey, EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *or
|
|||||||
BIGNUM *x = BN_new();
|
BIGNUM *x = BN_new();
|
||||||
BIGNUM *y = BN_new();
|
BIGNUM *y = BN_new();
|
||||||
|
|
||||||
uint32_t bKey[4]{};
|
DWORD bKey[4]{};
|
||||||
|
|
||||||
do {
|
do {
|
||||||
uint32_t hash = 0, sig[2]{};
|
DWORD hash = 0, sig[2]{};
|
||||||
|
|
||||||
memset(bKey, 0, 4);
|
memset(bKey, 0, 4);
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ void generateXPKey(char *pKey, EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *or
|
|||||||
EC_POINT_get_affine_coordinates(eCurve, r, x, y, ctx);
|
EC_POINT_get_affine_coordinates(eCurve, r, x, y, ctx);
|
||||||
|
|
||||||
SHA_CTX hContext;
|
SHA_CTX hContext;
|
||||||
uint8_t md[SHA_DIGEST_LENGTH]{}, buf[FIELD_BYTES]{}, t[4]{};
|
BYTE md[SHA_DIGEST_LENGTH]{}, buf[FIELD_BYTES]{}, t[4]{};
|
||||||
|
|
||||||
// h = (First-32(SHA1(pRaw, r.x, r.y)) >> 4
|
// h = (First-32(SHA1(pRaw, r.x, r.y)) >> 4
|
||||||
SHA1_Init(&hContext);
|
SHA1_Init(&hContext);
|
||||||
@ -225,8 +225,8 @@ void generateXPKey(char *pKey, EC_GROUP *eCurve, EC_POINT *generator, BIGNUM *or
|
|||||||
BN_mod_add(s, s, c, order, ctx);
|
BN_mod_add(s, s, c, order, ctx);
|
||||||
|
|
||||||
// Convert s from BigNum back to bytecode and reverse the endianness.
|
// Convert s from BigNum back to bytecode and reverse the endianness.
|
||||||
BN_bn2bin(s, (uint8_t *)sig);
|
BN_bn2bin(s, (BYTE *)sig);
|
||||||
endian((uint8_t *)sig, BN_num_bytes(s));
|
endian((BYTE *)sig, BN_num_bytes(s));
|
||||||
|
|
||||||
// Pack product key.
|
// Pack product key.
|
||||||
packXP(bKey, pRaw, &hash, sig);
|
packXP(bKey, pRaw, &hash, sig);
|
||||||
|
Loading…
Reference in New Issue
Block a user