add globals.h, cleanup logging, don't use static for all functions in xp_activate32.h

This commit is contained in:
Alexander Frick
2025-11-23 20:09:04 -08:00
parent 3e871fd475
commit ec4b7fafe0
7 changed files with 88 additions and 55 deletions
+15
View File
@@ -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_
+1 -1
View File
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Resource.rc
// Used by resource.rc
//
#pragma once
+2 -2
View File
@@ -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
+43 -29
View File
@@ -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<long>(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);
}
+23 -23
View File
@@ -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_
+1
View File
@@ -158,6 +158,7 @@
<ItemGroup>
<ClInclude Include="src/constants.h" />
<ClInclude Include="src/framework.h" />
<ClInclude Include="src/globals.h" />
<ClInclude Include="src/keygen.h" />
<ClInclude Include="src/resource.h" />
<ClInclude Include="src/xp_activate32.h" />
+3
View File
@@ -40,6 +40,9 @@
<ClInclude Include="src/framework.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src/globals.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src/keygen.h">
<Filter>Header Files</Filter>
</ClInclude>