From 05ee5eb933a9fc95a46f475dd25760843aeadfbc Mon Sep 17 00:00:00 2001 From: Neo <321592+Neo-Desktop@users.noreply.github.com> Date: Tue, 30 May 2023 12:37:13 -0700 Subject: [PATCH] update CMakeLists to correctly compile sources - update readme to reflect that factor out reused functions to shared.cpp/shared.h --- .gitignore | 15 ++++++- CMakeLists.txt | 19 +++++--- README.md | 2 +- build/.gitkeep | 0 header.h | 8 ---- server_algorithm.cpp | 70 +---------------------------- shared.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++ shared.h | 26 +++++++++++ xp_algorithm.cpp | 104 +------------------------------------------ 9 files changed, 159 insertions(+), 188 deletions(-) create mode 100644 build/.gitkeep delete mode 100644 header.h create mode 100644 shared.cpp create mode 100644 shared.h diff --git a/.gitignore b/.gitignore index 1f5f3de..1100325 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -srv2003key -xpkey +build/* ### NotepadPP template # Notepad++ backups # @@ -234,3 +233,15 @@ bh_unicode_properties.cache # https://packagecontrol.io/packages/sublime-github GitHub.sublime-settings +### CMake template +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps diff --git a/CMakeLists.txt b/CMakeLists.txt index 62b1869..e67783d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,18 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) PROJECT(WindowsXPKg) - SET(CMAKE_CXX_STANDARD 17) -SET(SOURCE main.c xp_algorithm.c server_algorithm.c) -SET(HEADER header.h) -TARGET_LINK_LIBRARIES(${CMAKE_SOURCE_DIR}/lib/libcrypto.lib) -ADD_EXECUTABLE(Release ${SOURCE}) +find_package(PkgConfig REQUIRED) +pkg_search_module(OPENSSL REQUIRED openssl) + +if (!OPENSSL_FOUND) + message(FATAL_ERROR "OpenSSL Not Found") +endif() + +ADD_EXECUTABLE(xpkey xp_algorithm.cpp shared.cpp) +TARGET_INCLUDE_DIRECTORIES(xpkey PUBLIC crypto) +TARGET_LINK_LIBRARIES(xpkey PUBLIC crypto) + +ADD_EXECUTABLE(srv2003key server_algorithm.cpp shared.cpp) +TARGET_INCLUDE_DIRECTORIES(srv2003key PUBLIC crypto) +TARGET_LINK_LIBRARIES(srv2003key PUBLIC crypto) diff --git a/README.md b/README.md index 361cd9a..6fd5b84 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ In light of the recent exponential interest in this project I've decided to put ### **Usage** 1. Feel free to use [XPKeygen](https://github.com/Endermanch/XPKeygen) on **Windows** to generate a key, and use such key during installation. - * If on **Linux** please clone and compile this repository using `make` and run using `./xpkey` to generate a Volume License Key + * If on **Linux** please clone and compile this repository using `cd build && cmake ../ && make` and run using `./xpkey` to generate a Volume License Key 2. (For retail only): After installation, you will be prompted to activate Windows. Select the *telephone activation* method, then, fire up [xp_activate32.exe](https://archive.org/details/xp_activate32_202305) and enter the installation ID that the activation wizard gave you. diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/header.h b/header.h deleted file mode 100644 index 2fcb095..0000000 --- a/header.h +++ /dev/null @@ -1,8 +0,0 @@ -// -// Created by Andrew on 30/05/2023. -// - -#ifndef WINDOWSXPKG_HEADER_H -#define WINDOWSXPKG_HEADER_H - -#endif //WINDOWSXPKG_HEADER_H diff --git a/server_algorithm.cpp b/server_algorithm.cpp index 1c6c0bd..c731c70 100644 --- a/server_algorithm.cpp +++ b/server_algorithm.cpp @@ -1,12 +1,4 @@ -#include -#include -#include -#include -#include -#include -#include - -uint8_t cset[] = "BCDFGHJKMPQRTVWXY2346789"; +#include "shared.h" #define FIELD_BITS_2003 512 #define FIELD_BYTES_2003 64 @@ -28,66 +20,6 @@ void pack2003(uint32_t *raw, uint32_t *osfamily, uint32_t *hash, uint32_t *sig, raw[3] = (sig[1] >> 22) | (prefix[0] << 8); } -static void endian(uint8_t *x, int n) -{ - int i; - for (i = 0; i < n/2; i++) { - uint8_t t; - t = x[i]; - x[i] = x[n-i-1]; - x[n-i-1] = t; - } -} - -void unbase24(uint32_t *x, uint8_t *c) -{ - memset(x, 0, 16); - int i, n; - - BIGNUM *y = BN_new(); - BN_zero(y); - - for (i = 0; i < 25; i++) - { - BN_mul_word(y, 24); - BN_add_word(y, c[i]); - } - n = BN_num_bytes(y); - BN_bn2bin(y, (uint8_t *)x); - BN_free(y); - - endian((uint8_t *)x, n); -} - -void base24(uint8_t *c, uint32_t *x) -{ - uint8_t y[16]; - int i; - - BIGNUM *z; - memcpy(y, x, sizeof(y)); - for (i = 15; y[i] == 0; i--) {} i++; - endian(y, i); - z = BN_bin2bn(y, i, NULL); - - c[25] = 0; - for (i = 24; i >= 0; i--) { - uint8_t t = BN_div_word(z, 24); - c[i] = cset[t]; - } - BN_free(z); -} - -void print_product_key(uint8_t *pk) -{ - int i; - assert(strlen((const char *)pk) == 25); - for (i = 0; i < 25; i++) { - putchar(pk[i]); - if (i != 24 && i % 5 == 4) putchar('-'); - } -} - int verify2003(EC_GROUP *ec, EC_POINT *generator, EC_POINT *public_key, char *cdkey) { uint8_t key[25]; diff --git a/shared.cpp b/shared.cpp new file mode 100644 index 0000000..c9bb41f --- /dev/null +++ b/shared.cpp @@ -0,0 +1,103 @@ +// +// Created by neo on 5/26/2023. +// + +#include "shared.h" + +uint8_t cset[] = "BCDFGHJKMPQRTVWXY2346789"; + +// Reverse data +void endian(uint8_t *data, int len) +{ + int i; + for (i = 0; i < len/2; i++) { + uint8_t temp; + temp = data[i]; + data[i] = data[len-i-1]; + data[len-i-1] = temp; + } +} + +void unbase24(uint32_t *x, uint8_t *c) +{ + + memset(x, 0, 16); + int i, n; + + BIGNUM *y = BN_new(); + BN_zero(y); + + for (i = 0; i < 25; i++) + { + BN_mul_word(y, 24); + BN_add_word(y, c[i]); + } + n = BN_num_bytes(y); + BN_bn2bin(y, (uint8_t *)x); + BN_free(y); + + endian((uint8_t *)x, n); +} + +void base24(uint8_t *c, uint32_t *x) +{ + uint8_t y[16]; + int i; + BIGNUM *z; + + // Convert x to BigNum z + memcpy(y, x, sizeof(y)); // Copy X to Y; Y=X + for (i = 15; y[i] == 0; i--) {} i++; // skip following nulls + endian(y, i); // Reverse y + z = BN_bin2bn(y, i, NULL); // Convert y to BigNum z + + + // Divide z by 24 and convert remainder with cset to Base24-CDKEY Char + c[25] = 0; + for (i = 24; i >= 0; i--) { + uint8_t t = BN_div_word(z, 24); + c[i] = cset[t]; + } + + BN_free(z); +} + +void print_product_id(uint32_t *pid) +{ + char raw[12]; + char b[6], c[8]; + int i, digit = 0; + + // Cut a away last bit of pid and convert it to an accii-number (=raw) + sprintf(raw, "%d", pid[0] >> 1); + + // Make b-part {640-....} + strncpy(b, raw, 3); + b[3] = 0; + + // Make c-part {...-123456X...} + strcpy(c, raw + 3); + + printf("> %s\n", c); + // Make checksum digit-part {...56X-} + assert(strlen(c) == 6); + for (i = 0; i < 6; i++) + digit -= c[i] - '0'; // Sum digits + + while (digit < 0) + digit += 7; + c[6] = digit + '0'; + c[7] = 0; + + printf("Product ID: 55274-%s-%s-23xxx\n", b, c); +} + +void print_product_key(uint8_t *pk) +{ + int i; + assert(strlen((const char *)pk) == 25); + for (i = 0; i < 25; i++) { + putchar(pk[i]); + if (i != 24 && i % 5 == 4) putchar('-'); + } +} \ No newline at end of file diff --git a/shared.h b/shared.h new file mode 100644 index 0000000..9d9376f --- /dev/null +++ b/shared.h @@ -0,0 +1,26 @@ +// +// Created by neo on 5/26/2023. +// + +#ifndef WINDOWSXPKG_SHARED_H +#define WINDOWSXPKG_SHARED_H + +#include +#include +#include +#include + +#include +#include +#include +#include + +extern uint8_t cset[]; + +void endian(uint8_t *data, int len); +void unbase24(uint32_t *x, uint8_t *c); +void base24(uint8_t *c, uint32_t *x); +void print_product_key(uint8_t *pk); +void print_product_id(uint32_t *pid); + +#endif //WINDOWSXPKG_SHARED_H diff --git a/xp_algorithm.cpp b/xp_algorithm.cpp index e1eb889..6e6ebb9 100644 --- a/xp_algorithm.cpp +++ b/xp_algorithm.cpp @@ -15,17 +15,10 @@ */ -#include -#include -#include -#include -#include -#include - +#include "shared.h" #define FIELD_BITS 384 #define FIELD_BYTES 48 -uint8_t cset[] = "BCDFGHJKMPQRTVWXY2346789"; static void unpack(uint32_t *pid, uint32_t *hash, uint32_t *sig, uint32_t *raw) @@ -49,101 +42,6 @@ static void pack(uint32_t *raw, uint32_t *pid, uint32_t *hash, uint32_t *sig) raw[3] = sig[1] >> 5; } -// Reverse data -static void endian(uint8_t *data, int len) -{ - int i; - for (i = 0; i < len/2; i++) { - uint8_t temp; - temp = data[i]; - data[i] = data[len-i-1]; - data[len-i-1] = temp; - } -} - -void unbase24(uint32_t *x, uint8_t *c) -{ - - memset(x, 0, 16); - int i, n; - - BIGNUM *y = BN_new(); - BN_zero(y); - - for (i = 0; i < 25; i++) - { - BN_mul_word(y, 24); - BN_add_word(y, c[i]); - } - n = BN_num_bytes(y); - BN_bn2bin(y, (uint8_t *)x); - BN_free(y); - - endian((uint8_t *)x, n); -} - -void base24(uint8_t *c, uint32_t *x) -{ - uint8_t y[16]; - int i; - BIGNUM *z; - - // Convert x to BigNum z - memcpy(y, x, sizeof(y)); // Copy X to Y; Y=X - for (i = 15; y[i] == 0; i--) {} i++; // skip following nulls - endian(y, i); // Reverse y - z = BN_bin2bn(y, i, NULL); // Convert y to BigNum z - - - // Divide z by 24 and convert remainder with cset to Base24-CDKEY Char - c[25] = 0; - for (i = 24; i >= 0; i--) { - uint8_t t = BN_div_word(z, 24); - c[i] = cset[t]; - } - - BN_free(z); -} - -void print_product_id(uint32_t *pid) -{ - char raw[12]; - char b[6], c[8]; - int i, digit = 0; - - // Cut a away last bit of pid and convert it to an accii-number (=raw) - sprintf(raw, "%d", pid[0] >> 1); - - // Make b-part {640-....} - strncpy(b, raw, 3); - b[3] = 0; - - // Make c-part {...-123456X...} - strcpy(c, raw + 3); - - // Make checksum digit-part {...56X-} - assert(strlen(c) == 6); - for (i = 0; i < 6; i++) - digit -= c[i] - '0'; // Sum digits - - while (digit < 0) - digit += 7; - c[6] = digit + '0'; - c[7] = 0; - - printf("Product ID: 55274-%s-%s-23xxx\n", b, c); -} - -void print_product_key(uint8_t *pk) -{ - int i; - assert(strlen((const char *)pk) == 25); - for (i = 0; i < 25; i++) { - putchar(pk[i]); - if (i != 24 && i % 5 == 4) putchar('-'); - } -} - void verify(EC_GROUP *ec, EC_POINT *generator, EC_POINT *public_key, char *cdkey) { uint8_t key[25];