update CMakeLists to correctly compile sources - update readme to reflect that

factor out reused functions to shared.cpp/shared.h
This commit is contained in:
Neo 2023-05-30 12:37:13 -07:00
parent ac47a88f7e
commit 05ee5eb933
9 changed files with 159 additions and 188 deletions

15
.gitignore vendored
View File

@ -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

View File

@ -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)

View File

@ -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.

0
build/.gitkeep Normal file
View File

View File

@ -1,8 +0,0 @@
//
// Created by Andrew on 30/05/2023.
//
#ifndef WINDOWSXPKG_HEADER_H
#define WINDOWSXPKG_HEADER_H
#endif //WINDOWSXPKG_HEADER_H

View File

@ -1,12 +1,4 @@
#include <stdio.h>
#include <string.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <assert.h>
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];

103
shared.cpp Normal file
View File

@ -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('-');
}
}

26
shared.h Normal file
View File

@ -0,0 +1,26 @@
//
// Created by neo on 5/26/2023.
//
#ifndef WINDOWSXPKG_SHARED_H
#define WINDOWSXPKG_SHARED_H
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
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

View File

@ -15,17 +15,10 @@
*/
#include <stdio.h>
#include <string.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/sha.h>
#include <assert.h>
#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];