From ec4b7fafe099edf8254411514e9a06787161c8cc Mon Sep 17 00:00:00 2001 From: Alexander Frick Date: Sun, 23 Nov 2025 20:09:04 -0800 Subject: [PATCH] add globals.h, cleanup logging, don't use static for all functions in xp_activate32.h --- src/globals.h | 15 ++++++++ src/resource.h | 2 +- src/version.h | 4 +- src/xp_activate32.cc | 72 +++++++++++++++++++++-------------- src/xp_activate32.h | 46 +++++++++++----------- xp_activate32.vcxproj | 1 + xp_activate32.vcxproj.filters | 3 ++ 7 files changed, 88 insertions(+), 55 deletions(-) create mode 100644 src/globals.h diff --git a/src/globals.h b/src/globals.h new file mode 100644 index 0000000..d243a00 --- /dev/null +++ b/src/globals.h @@ -0,0 +1,15 @@ +#ifndef XP_ACTIVATE32_GLOBALS_H_ +#define XP_ACTIVATE32_GLOBALS_H_ + +#include "framework.h" +#include "constants.h" + +/* Globals */ + +// Global instance handle +extern HINSTANCE g_hInstance; + +// This Windows version +extern std::string WinVer; + +#endif // XP_ACTIVATE32_GLOBALS_H_ diff --git a/src/resource.h b/src/resource.h index 964898c..31788c5 100644 --- a/src/resource.h +++ b/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by Resource.rc +// Used by resource.rc // #pragma once diff --git a/src/version.h b/src/version.h index d6ac6b5..11ae299 100644 --- a/src/version.h +++ b/src/version.h @@ -19,14 +19,14 @@ // Adhere to semver > semver.org #define MAJOR_VERSION 1 #define MINOR_VERSION 0 -#define BUILD_VERSION 2 +#define BUILD_VERSION 3 #define MAIN_TITLE L"XP_Activate32" #ifndef VERSION_STRING #define VERSION_STRING _VERSION(MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION) #define ABOUT_TITLE L"About XP_Activate32" - #define ABOUT_VERSION L"xp_activate32 ver. 1.0.2" + #define ABOUT_VERSION L"xp_activate32 ver. 1.0.3" #define ABOUT_COPYRIGHT L"Copyright © 2025 Alex313031" #define LEGAL_COPYRIGHT L"© 2025" #endif // VERSION_STRING diff --git a/src/xp_activate32.cc b/src/xp_activate32.cc index 5691bd5..e6a341b 100644 --- a/src/xp_activate32.cc +++ b/src/xp_activate32.cc @@ -3,6 +3,9 @@ #include "keygen.h" #include "utils.h" +/* Global instance handle */ +HINSTANCE g_hInstance = NULL; + static HICON hIcon[2]; #define divisor_double(src, dst) divisor_add(src, src, dst) @@ -943,31 +946,32 @@ static void PutIdToSystem(HWND hDlg) { INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { int i; switch (uMsg) { - case WM_INITDIALOG: - for (i = 0; i < 2; i++) - SendMessage(hDlg, WM_SETICON, i, (LPARAM)hIcon[i]); - OnActivationIdChange(hDlg); - SendMessage(hDlg, DM_SETDEFID, 102, 0); - return TRUE; - case WM_CLOSE: - EndDialog(hDlg, 0); - return TRUE; - case WM_COMMAND: - switch (wParam) { - case IDCANCEL: // Esc pressed - EndDialog(hDlg, 0); - break; - case MAKEWPARAM(101, EN_CHANGE): + case WM_INITDIALOG: + for (i = 0; i < 2; i++) { + SendMessage(hDlg, WM_SETICON, i, (LPARAM)hIcon[i]); + } OnActivationIdChange(hDlg); - break; - case 102: - GetIdFromSystem(hDlg); - break; - case 104: - PutIdToSystem(hDlg); - break; - } - return TRUE; + SendMessage(hDlg, DM_SETDEFID, 102, 0); + return TRUE; + case WM_CLOSE: + EndDialog(hDlg, 0); + return TRUE; + case WM_COMMAND: + switch (wParam) { + case IDCANCEL: // Esc pressed + EndDialog(hDlg, 0); + break; + case MAKEWPARAM(101, EN_CHANGE): + OnActivationIdChange(hDlg); + break; + case 102: + GetIdFromSystem(hDlg); + break; + case 104: + PutIdToSystem(hDlg); + break; + } + return TRUE; } return FALSE; } @@ -977,6 +981,10 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_ WCHAR *pCmdLine, _In_ INT nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); + /* Assign global HINSTANCE */ + g_hInstance = hInstance; + MSG Msg; + long err_status; // Allow and allocate conhost if (!AllocConsole()) { @@ -991,10 +999,11 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, if (cmdLine == nullptr || cmdLine == NULL) { std::wcerr << L"GetCommandLineW failed!" << std::endl; return 1; + } else { + std::wstring welcome_str = L"Welcome to XP_Activate32 ver. " + getVersionW(); + std::wcout << welcome_str << std::endl; } - std::wstring welcome_str = L"Welcome to XP_Activate32 ver. " + getVersionW(); - std::wcout << welcome_str << std::endl; INITCOMMONCONTROLSEX cc = {sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES}; InitCommonControlsEx(&cc); int i; @@ -1009,7 +1018,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, hIcon[i] = getDialogIcon(false, 194, x, y); } - INT_PTR status = DialogBoxW(NULL, MAKEINTRESOURCE(100), NULL, &DialogProc); + // Create main window + INT_PTR main_dialog = DialogBoxW(g_hInstance, MAKEINTRESOURCE(100), NULL, &DialogProc); + err_status = static_cast(main_dialog); for (i = 0; i < 2; i++) { DestroyIcon(hIcon[i]); @@ -1023,6 +1034,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, CoUninitialize(); } - std::cout << "status = " << status << std::endl; - ExitProcess(status); + std::wcout << L"err_status = " << err_status << std::endl; + if (err_status != 0L) { + system("pause"); + } + ExitProcess(err_status); } diff --git a/src/xp_activate32.h b/src/xp_activate32.h index a80030a..9c0d2e4 100644 --- a/src/xp_activate32.h +++ b/src/xp_activate32.h @@ -35,49 +35,51 @@ typedef struct { #define CHARTYPE wchar_t -static ui64 residue_add(ui64 x, ui64 y); +static FILE* fDummyFile; -static ui64 residue_sub(ui64 x, ui64 y); +ui64 residue_add(ui64 x, ui64 y); -static uint64_t __umul128(uint64_t multiplier, uint64_t multiplicand, uint64_t *product_hi); +ui64 residue_sub(ui64 x, ui64 y); -static ui64 ui128_quotient_mod(ui64 lo, ui64 hi); +uint64_t __umul128(uint64_t multiplier, uint64_t multiplicand, uint64_t *product_hi); -static ui64 residue_mul(ui64 x, ui64 y); +ui64 ui128_quotient_mod(ui64 lo, ui64 hi); -static ui64 residue_pow(ui64 x, ui64 y); +ui64 residue_mul(ui64 x, ui64 y); -static ui64 inverse(ui64 u, ui64 v); +ui64 residue_pow(ui64 x, ui64 y); -static ui64 residue_inv(ui64 x); +ui64 inverse(ui64 u, ui64 v); -static ui64 residue_sqrt(ui64 what); +ui64 residue_inv(ui64 x); + +ui64 residue_sqrt(ui64 what); int find_divisor_v(TDivisor* d); -static int polynomial_mul(int adeg, const ui64 a[], int bdeg, const ui64 b[], int resultprevdeg, ui64 result[]); +int polynomial_mul(int adeg, const ui64 a[], int bdeg, const ui64 b[], int resultprevdeg, ui64 result[]); -static int polynomial_div_monic(int adeg, ui64 a[], int bdeg, const ui64 b[], ui64* quotient); +int polynomial_div_monic(int adeg, ui64 a[], int bdeg, const ui64 b[], ui64* quotient); -static void polynomial_xgcd(int adeg, const ui64 a[3], int bdeg, const ui64 b[3], int* pgcddeg, ui64 gcd[3], int* pmult1deg, ui64 mult1[3], int* pmult2deg, ui64 mult2[3]); +void polynomial_xgcd(int adeg, const ui64 a[3], int bdeg, const ui64 b[3], int* pgcddeg, ui64 gcd[3], int* pmult1deg, ui64 mult1[3], int* pmult2deg, ui64 mult2[3]); -static int u2poly(const TDivisor* src, ui64 polyu[3], ui64 polyv[2]); +int u2poly(const TDivisor* src, ui64 polyu[3], ui64 polyv[2]); -static void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* dst); +void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* dst); -static void divisor_mul(const TDivisor* src, ui64 mult, TDivisor* dst); +void divisor_mul(const TDivisor* src, ui64 mult, TDivisor* dst); -static void divisor_mul128(const TDivisor* src, ui64 mult_lo, ui64 mult_hi, TDivisor* dst); +void divisor_mul128(const TDivisor* src, ui64 mult_lo, ui64 mult_hi, TDivisor* dst); -static unsigned rol(unsigned x, int shift); +unsigned rol(unsigned x, int shift); -static void sha1_single_block(unsigned char input[64], unsigned char output[20]); +void sha1_single_block(unsigned char input[64], unsigned char output[20]); -static void Mix(unsigned char* buffer, size_t bufSize, const unsigned char* key, size_t keySize); +void Mix(unsigned char* buffer, size_t bufSize, const unsigned char* key, size_t keySize); -static void Unmix(unsigned char* buffer, size_t bufSize, const unsigned char* key, size_t keySize); +void Unmix(unsigned char* buffer, size_t bufSize, const unsigned char* key, size_t keySize); -static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_id[49]); +int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_id[49]); //#undef INTERFACE //#define INTERFACE ICOMLicenseAgent @@ -93,6 +95,4 @@ static void PutIdToSystem(HWND hDlg); INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -static FILE* fDummyFile; - #endif // XP_ACTIVATE32_H_ diff --git a/xp_activate32.vcxproj b/xp_activate32.vcxproj index 478e2f8..3dedda2 100644 --- a/xp_activate32.vcxproj +++ b/xp_activate32.vcxproj @@ -158,6 +158,7 @@ + diff --git a/xp_activate32.vcxproj.filters b/xp_activate32.vcxproj.filters index 0b4f98e..9763411 100644 --- a/xp_activate32.vcxproj.filters +++ b/xp_activate32.vcxproj.filters @@ -40,6 +40,9 @@ Header Files + + Header Files + Header Files