add brackets to everything, remove static keyword on xp_activate.cc functions, add more strings and add IDS_* for them instead of raw numbers, add functions to get and log Windows version, translation corrections

This commit is contained in:
Alexander Frick
2025-11-24 01:53:10 -08:00
parent ec4b7fafe0
commit 72148adaca
11 changed files with 679 additions and 150 deletions
+7 -3
View File
@@ -42,14 +42,18 @@ source_set("xp_activate32_sources") {
sources = [
"src/constants.h",
"src/framework.h",
"src/keygen.cc",
"src/globals.h",
"src/keygen.h",
"src/resource.h",
"src/utils.h",
"src/xp_activate32.h",
]
sources += [
"src/keygen.cc",
"src/resource.rc",
"src/utils.cc",
"src/utils.h",
"src/xp_activate32.cc",
"src/xp_activate32.h",
]
}
+3
View File
@@ -0,0 +1,3 @@
gn gen out\Debug\&&ninja.bat -C out\Debug\ xp_activate32 -v -j 8&&copy /Y out\Debug\xp_activate32.exe Y:\xp_activate_debug.exe&&^
gn gen out\Release\&&ninja.bat -C out\Release\ xp_activate32 -v -j 8&&copy /Y out\Release\xp_activate32.exe Y:\xp_activate_rel.exe&&^
out\Debug\xp_activate32.exe
+5 -1
View File
@@ -10,6 +10,10 @@
#define assert(x) /*nothing*/
#ifndef __FUNC__
#define __FUNC__ __func__
#endif // __FUNC__
typedef int64_t i64;
typedef uint64_t ui64;
@@ -17,7 +21,7 @@ typedef uint64_t ui64;
#define NON_RESIDUE 43
static const ui64 f[6] = {0, 0x21840136C85381ULL, 0x44197B83892AD0ULL, 0x1400606322B3B04ULL, 0x1400606322B3B04ULL, 1};
const ui64 f[6] = {0, 0x21840136C85381ULL, 0x44197B83892AD0ULL, 0x1400606322B3B04ULL, 0x1400606322B3B04ULL, 1};
static const CLSID licdllCLSID = {0xACADF079, 0xCBCD, 0x4032, {0x83, 0xF2, 0xFA, 0x47, 0xC4, 0xDB, 0x09, 0x6F}};
static const IID licenseAgentIID = {0xB8CBAD79, 0x3F1F, 0x481A, {0xBB, 0x0C, 0xE7, 0xBB, 0xD7, 0x7B, 0xDD, 0xD1}};
+3
View File
@@ -9,6 +9,9 @@
// Global instance handle
extern HINSTANCE g_hInstance;
// Main window handle
extern HWND g_hMainDlg;
// This Windows version
extern std::string WinVer;
+20 -3
View File
@@ -11,9 +11,26 @@
#define IDD_MAINFRAME 100 // Main dialog
#define IDC_MAINFRAME 103 // Main window
#define IDI_MAINFRAME IDC_MAINFRAME // Main .exe/window icon
#define IDI_SMALL 203 // Main dialog icon
#define IDI_MAINFRAME 106 // Main .exe/window icon
#define IDI_SMALL 107 // Main dialog icon
#define IDC_MAINFRAME 108 // Main window
#define IDS_SUCC_ACTIVATION 0
#define IDS_WAITING_INPUT 1
#define IDS_ID_TOO_LARGE 2
#define IDS_INVALID_CHAR 3
#define IDS_INVALID_CHECK 4
#define IDS_UNKNOWN_ID 5
#define IDS_UNLUCKY_ID 6
#define IDS_TALKING_TO_SYS 7
#define IDS_ERROR 8
#define IDS_INFORMATION 9
#define IDS_FAILED_INITIALIZE 10
#define IDS_FAILED_CHECK 11
#define IDS_ALREADY_ACTIVATED 12
#define IDS_LIC_MAN_FAILED 13
#define IDS_GETVER_ERR 14
#define IDS_ABOUT_TITLE 15
#ifndef IDC_STATIC
#define IDC_STATIC -1
+42 -37
View File
@@ -2,6 +2,8 @@
//
#include "resource.h"
#pragma code_page(65001) // UTF-8
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
@@ -15,8 +17,6 @@
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
#pragma code_page(65001) // UTF-8
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
@@ -45,7 +45,7 @@ BEGIN
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
@@ -58,9 +58,9 @@ VS_VERSION_INFO VERSIONINFO
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG // 0x00000010L
#else
#else // Release mode
FILEFLAGS 0x00000000L // Normal?
#endif
#endif // _DEBUG
// Windows NT
FILEOS VOS_NT_WINDOWS32 // 0x00040004L
FILETYPE VFT_APP // 0x00000001L
@@ -116,10 +116,10 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CTEXT "Код установки:", -1, 2, 11, 75, 10
EDITTEXT 101, 77, 10, 250, 12, ES_CENTER | ES_AUTOHSCROLL
PUSHBUTTON "Спросить у системы", 102, 330, 10, 74, 12
PUSHBUTTON "Получить Код из системы", 102, 330, 10, 74, 12
CTEXT "Код подтверждения:", -1, 2, 25, 75, 10
EDITTEXT 103, 77, 24, 250, 12, ES_CENTER | ES_AUTOHSCROLL | ES_READONLY
PUSHBUTTON "Сказать системе", 104, 330, 24, 74, 12
PUSHBUTTON "Активировать!", 104, 330, 24, 74, 12
END
/////////////////////////////////////////////////////////////////////////////
@@ -129,23 +129,25 @@ END
STRINGTABLE
BEGIN
0 "Успешная активация!"
1 "жду код установки..."
2 "код слишком длинный"
3 "неправильный символ"
4 "ошибка в проверочной цифре"
5 "неизвестная версия кода"
6 "ну очень невезучий код..."
7 "говорю с системой..."
8 "Ошибка"
9 "Информация"
10 "Не получилось инициализировать менеджер лицензий"
11 "Не получилось проверить статус активации"
12 "Менеджер лицензий считает систему уже активированной"
13 "Менеджер лицензий вернул ошибку"
IDS_SUCC_ACTIVATION "Успешная активация!"
IDS_WAITING_INPUT "жду код установки..."
IDS_ID_TOO_LARGE "код слишком длинный"
IDS_INVALID_CHAR "неправильный символ!"
IDS_INVALID_CHECK "ошибка в проверочной цифре!"
IDS_UNKNOWN_ID "неизвестная версия кода"
IDS_UNLUCKY_ID "ну очень невезучий код..."
IDS_TALKING_TO_SYS "говорю с системой..."
IDS_ERROR "Ошибка"
IDS_INFORMATION "Информация"
IDS_FAILED_INITIALIZE "Не получилось инициализировать менеджер лицензий"
IDS_FAILED_CHECK "Не получилось проверить статус активации"
IDS_ALREADY_ACTIVATED "Менеджер лицензий считает систему уже активированной"
IDS_LIC_MAN_FAILED "Менеджер лицензий вернул ошибку"
IDS_GETVER_ERR "RtlGetVersion returned nullptr in ntdll.dll!"
IDS_ABOUT_TITLE ABOUT_TITLE
END
#endif // Russian (Russia) resources
#endif // Russian (Russia) resources
/////////////////////////////////////////////////////////////////////////////
@@ -180,23 +182,26 @@ END
STRINGTABLE
BEGIN
0 "Successful Activation!"
1 "Waiting for input..."
2 "ID is too large!"
3 "Invalid character!"
4 "Invalid check digit!"
5 "Unknown version of ID"
6 "This ID is really unlucky..."
7 "Talking to the system..."
8 "Error!"
9 "Information"
10 "Failed to initialize the license manager!"
11 "Failed to check activation status..."
12 "License manager reports that the system is already activated."
13 "License manager has failed!"
IDS_SUCC_ACTIVATION "Successful Activation!"
IDS_WAITING_INPUT "Waiting for input..."
IDS_ID_TOO_LARGE "ID is too large!"
IDS_INVALID_CHAR "Invalid character!"
IDS_INVALID_CHECK "Invalid check digit!"
IDS_UNKNOWN_ID "Unknown version of ID"
IDS_UNLUCKY_ID "This ID is really unlucky..."
IDS_TALKING_TO_SYS "Talking to the system..."
IDS_ERROR "Error!"
IDS_INFORMATION "Information"
IDS_FAILED_INITIALIZE "Failed to initialize the license manager!"
IDS_FAILED_CHECK "Failed to check activation status..."
IDS_ALREADY_ACTIVATED "License manager reports that the system is already activated."
IDS_LIC_MAN_FAILED "License manager has failed!"
IDS_GETVER_ERR "RtlGetVersion returned nullptr in ntdll.dll!"
IDS_ABOUT_TITLE ABOUT_TITLE
END
#endif // English resources
#endif // English resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
+385
View File
@@ -1,5 +1,9 @@
#include "utils.h"
#include "globals.h"
static bool is_win11;
HANDLE LoadImageFromDLL(LPCWSTR dllName,
UINT resourceId,
UINT imgType,
@@ -65,3 +69,384 @@ std::wstring getVersionW() {
wostr << MAJOR_VERSION << L"." << MINOR_VERSION << L"." << BUILD_VERSION;
return wostr.str();
}
std::string WinVer;
float getWinNTVersion() {
// Use RtlGetVersion from winnt.h, not wdm.h
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexw
OSVERSIONINFOEXW osInfo;
// Make sure we get the dll
HMODULE NtDllModule = GetModuleHandleW(L"ntdll");
// Get and run ntdll.dll function pointer to RtlGetVersion()
if (NtDllModule && NtDllModule != nullptr) {
*reinterpret_cast<FARPROC*>(&RtlGetVersion) =
GetProcAddress(NtDllModule, "RtlGetVersion");
} else {
RtlGetVersion = nullptr;
}
// Should never be null
if (RtlGetVersion != nullptr) {
osInfo.dwOSVersionInfoSize = sizeof osInfo;
RtlGetVersion(&osInfo);
NT_MAJOR = osInfo.dwMajorVersion;
NT_MINOR = osInfo.dwMinorVersion;
NT_BUILD = osInfo.dwBuildNumber;
NT_CSD_VERSION = osInfo.szCSDVersion;
NT_SUITE = osInfo.wSuiteMask;
NT_TYPE = osInfo.wProductType;
} else {
MessageBoxW(g_hMainDlg, strings[IDS_GETVER_ERR], strings[IDS_ERROR], MB_ICONSTOP);
}
return 5.1f;
}
std::wstring GetWinVersion() {
std::string ver = GetOSName();
std::wstring wver = L"1.0";
WinVer = ver;
return wver;
}
// Use WINNT API functions to get OS and system information
std::string const GetOSName() {
// Human readable OS name
std::string OsVer;
// For obscure versions or pre NT4 SP6
std::ostringstream debugStream;
float NT_VER = getWinNTVersion();
// Get the service pack
std::string NT_SERVICE_PACK(NT_CSD_VERSION.begin(),
NT_CSD_VERSION.end());
if (NT_MAJOR <= 3) {
NT_FEATURE_VERSION = NT_SERVICE_PACK;
NT_POST_STRING = NT_FEATURE_VERSION;
}
if (NT_MAJOR == 4) {
if (NT_BUILD < 1381) {
if (NT_SUITE == VER_SUITE_TERMINAL) {
NT_FEATURE_VERSION = " Beta Cairo Build";
} else {
NT_FEATURE_VERSION = " Beta Hydra Build";
}
} else {
if (NT_SUITE == VER_SUITE_TERMINAL) {
NT_FEATURE_VERSION = " Terminal Server";
}
}
} else if (NT_MAJOR == 5) {
switch (NT_MINOR) {
case 0:
if (NT_BUILD > 1386 && NT_BUILD < 2195) {
NT_FEATURE_VERSION = " Beta Win2K Build";
}
break;
case 1:
if (NT_BUILD > 2196 && NT_BUILD < 2600) {
NT_FEATURE_VERSION = " Beta Whistler Build";
}
if (NT_BUILD == 2700) {
NT_FEATURE_VERSION = " MCE 2005";
}
if (NT_BUILD == 2710) {
NT_FEATURE_VERSION = " MCE 2005 Update Rollup 2";
}
break;
case 2:
if (NT_BUILD > 2228 && NT_BUILD < 3790) {
NT_FEATURE_VERSION = " Beta Whistler Build";
}
if (NT_SUITE == VER_SUITE_WH_SERVER) {
if (NT_BUILD > 1282 && NT_BUILD < 3790) {
NT_FEATURE_VERSION = " Beta Quattro Build";
}
}
break;
default:
NT_FEATURE_VERSION = "";
break;
}
} else if (NT_MAJOR == 6) {
switch (NT_MINOR) {
case 0:
if (NT_BUILD > 3663 && NT_BUILD < 6000) {
NT_FEATURE_VERSION = " Beta Longhorn Build";
} else if (NT_BUILD == 6003) {
NT_FEATURE_VERSION = " KB4489887";
}
break;
case 1:
if (NT_BUILD > 6429 && NT_BUILD < 7600) {
NT_FEATURE_VERSION = " Beta Win7 Build";
}
break;
case 2:
if (NT_BUILD > 7652 && NT_BUILD < 9200) {
NT_FEATURE_VERSION = " Beta Win8 Build";
}
break;
case 3:
if (NT_BUILD > 9255 && NT_BUILD < 9600) {
NT_FEATURE_VERSION = " Beta Blue Build";
}
break;
default:
NT_FEATURE_VERSION = "";
break;
}
NT_POST_STRING = NT_SERVICE_PACK + NT_FEATURE_VERSION;
// No such thing as feature releases for Windows 8.1 and below
} else if (NT_MAJOR >= 10) {
if (NT_BUILD > 19045) {
is_win11 = true;
} else {
is_win11 = false;
}
if (NT_BUILD < 10240) {
NT_FEATURE_VERSION = "Beta Threshold Build ";
} else if (NT_BUILD == 10240) {
NT_FEATURE_VERSION = "1507 (RTM 2015 Release) ";
} else if (NT_BUILD == 10586) {
NT_FEATURE_VERSION = "1511 (Nov. 2015 Update) ";
} else if (NT_BUILD == 14393) {
NT_FEATURE_VERSION = "1607 (Anniversary Update) ";
} else if (NT_BUILD == 15063) {
NT_FEATURE_VERSION = "1703 (Creators Update) ";
} else if (NT_BUILD == 16299) {
NT_FEATURE_VERSION = "1709 (Fall Creators Update) ";
} else if (NT_BUILD == 17134) {
NT_FEATURE_VERSION = "1803 (Apr. 2018 Update) ";
} else if (NT_BUILD == 17763) {
NT_FEATURE_VERSION = "1809 (Oct. 2018 Update) ";
} else if (NT_BUILD == 18362) {
NT_FEATURE_VERSION = "1903 (May. 2019 Update) ";
} else if (NT_BUILD == 18363) {
NT_FEATURE_VERSION = "1909 (Nov. 2019 Update) ";
} else if (NT_BUILD == 19041) {
NT_FEATURE_VERSION = "2004 (May. 2020 Update) ";
} else if (NT_BUILD == 19042) {
NT_FEATURE_VERSION = "20H2 (Oct. 2020 Update) ";
} else if (NT_BUILD == 19043) {
NT_FEATURE_VERSION = "21H1 (May. 2021 Update) ";
} else if (NT_BUILD == 19044) {
NT_FEATURE_VERSION = "21H2 (Nov. 2021 Update) ";
} else if (NT_BUILD == 19045) {
NT_FEATURE_VERSION = "22H2 (Oct. 2022 Update) ";
} else if (NT_BUILD == 20348 || NT_BUILD == 25398) {
NT_FEATURE_VERSION = "Server 2022 ";
} else if (NT_BUILD < 22000 && NT_BUILD > 20348 && NT_BUILD != 25398) {
NT_FEATURE_VERSION = "Beta Build ";
} else if (NT_BUILD == 22000) {
NT_FEATURE_VERSION = "21H2 (RTM 2021 Release) ";
} else if (NT_BUILD == 22621) {
NT_FEATURE_VERSION = "22H2 (Sep. 2022 Update) ";
} else if (NT_BUILD == 22631) {
NT_FEATURE_VERSION = "23H2 (Oct. 2023 Update) ";
} else if (NT_BUILD == 26100) {
NT_FEATURE_VERSION = "24H2 (Oct. 2024 Update) ";
} else {
NOTREACHED();
}
}
NT_POST_STRING = NT_SERVICE_PACK + NT_FEATURE_VERSION;
if (NT_MAJOR == 3) {
OsVer = "Windows NT 3.x";
} else if (NT_MAJOR == 4) {
// Known to be buggy on NT 4.0, and needs SP6 to work
switch (NT_MINOR) {
case 0:
OsVer = "Windows NT 4.0 ";
break;
default:
debugStream.str("");
debugStream.clear();
debugStream << " Unknown Windows "
<< NT_MAJOR << NT_MINOR
<< NT_BUILD << std::endl;
OsVer = debugStream.str();
break;
}
} else if (NT_MAJOR == 5) {
switch (NT_MINOR) {
case 0:
OsVer = "Windows 2000 " + NT_POST_STRING;
break;
case 1:
if (NT_SUITE == VER_SUITE_PERSONAL) {
OsVer = "Windows XP Home Edition " + NT_POST_STRING;
} else if (NT_SUITE == VER_SUITE_EMBEDDEDNT) {
OsVer = "Windows XP Embedded " + NT_POST_STRING;
} else {
OsVer = "Windows XP Professional " + NT_POST_STRING;
}
break;
case 2:
if (NT_SUITE == VER_SUITE_WH_SERVER) {
OsVer = "Windows Home Server" + NT_POST_STRING;
} else {
OsVer = "Windows Server 2003/XP x64 " + NT_POST_STRING;
}
break;
case 5:
OsVer = "Windows Neptune " + NT_POST_STRING;
break;
default:
debugStream.str("");
debugStream.clear();
debugStream << " Unknown Windows "
<< NT_MAJOR << NT_MINOR
<< NT_BUILD << std::endl;
OsVer = debugStream.str();
break;
}
} else if (NT_MAJOR == 6) {
switch (NT_MINOR) {
case 0:
if (NT_TYPE == VER_NT_WORKSTATION) {
OsVer = "Windows Vista " + NT_POST_STRING;
} else {
OsVer = "Windows Server 2008 " + NT_POST_STRING;
}
break;
case 1:
if (NT_BUILD == 8400 || NT_SUITE == VER_SUITE_WH_SERVER) {
OsVer = "Windows Home Server 2011 " + NT_POST_STRING;
} else {
if (NT_TYPE == VER_NT_WORKSTATION) {
OsVer = "Windows 7 " + NT_POST_STRING;
} else {
OsVer = "Windows Server 2008 R2 " + NT_POST_STRING;
}
}
break;
case 2:
if (NT_TYPE == VER_NT_WORKSTATION) {
OsVer = "Windows 8 " + NT_POST_STRING;
} else {
OsVer = "Windows Server 2012 " + NT_POST_STRING;
}
break;
case 3:
if (NT_TYPE == VER_NT_WORKSTATION) {
OsVer = "Windows 8.1 " + NT_POST_STRING;
} else {
OsVer = "Windows Server 2012 R2 " + NT_POST_STRING;
}
break;
default:
debugStream.str("");
debugStream.clear();
debugStream << " Unknown Windows "
<< NT_MAJOR << NT_MINOR
<< NT_BUILD << std::endl;
OsVer = debugStream.str();
break;
}
} else if (NT_MAJOR == 10) {
switch (NT_MINOR) {
case 0: {
if (!is_win11) {
if (NT_TYPE == VER_NT_WORKSTATION) {
OsVer = "Windows 10 " + NT_POST_STRING;
} else {
if (NT_BUILD >= 14393 && NT_BUILD < 17763) {
OsVer = "Windows Server 2016 " + NT_POST_STRING;
} else if (NT_BUILD >= 17763 && NT_BUILD < 20348) {
OsVer = "Windows Server 2019 " + NT_POST_STRING;
} else if (NT_BUILD >= 20348 && NT_BUILD <= 25398) {
OsVer = "Windows Server 2022 " + NT_POST_STRING;
} else {
OsVer = "Windows Server " + NT_POST_STRING;
}
}
} else {
if (NT_TYPE == VER_NT_WORKSTATION) {
OsVer = "Windows 11 " + NT_POST_STRING;
} else {
if (NT_BUILD == 26100) {
OsVer = "Windows Server 2025 " + NT_POST_STRING;
} else {
OsVer = "Windows Server " + NT_POST_STRING;
}
}
}
break;
}
case 1:
OsVer = "Windows 12 " + NT_POST_STRING;
break;
default:
debugStream.str("");
debugStream.clear();
debugStream << " - Unknown Windows "
<< NT_MAJOR << NT_MINOR
<< NT_BUILD << std::endl;
OsVer = debugStream.str();
break;
}
} else {
debugStream.str("");
debugStream.clear();
debugStream << " - Unknown Windows";
OsVer = debugStream.str();
NOTREACHED();
}
return OsVer;
}
std::string const GetNTString() {
// NT version number
std::string NtVer;
std::ostringstream debugStream;
float NT_VER = getWinNTVersion();
// Make sure that the values returned make sense.
// NT Kernels with numbers outside this range don't exist
if (NT_MAJOR >=3 && NT_MAJOR <=11) {
// Define NtVer as human readable string literal separated by decimals
NtVer = " " + std::to_string(NT_MAJOR)
+ "." +
std::to_string(NT_MINOR)
+ "." +
std::to_string(NT_BUILD);
}
return NtVer;
}
// Intentionally execute an invalid opcode to kill the program and signal to debugger
// See http://ref.x86asm.net/coder32.html
void ImmediateDebugCrash() {
#if defined(_WIN32) && !defined(_WIN64)
// 32 bit assembly code
__asm int 3 // Execute int3 interrupt
__asm {
UD2 // Execute 0x0F, 0x0B
}
#elif defined(_WIN64) // x86_64
/* MSVC-specific x64 ud2 since MSVC doesn't allow inline assembly
when compiling for x64 */
__debugbreak();
#endif // defined(_WIN32) && !defined(_WIN64)
}
// Dumb equivalent of Chromium's implementation
void NotReachedImpl(std::string func_name) {
// Log function name and then crash the program
std::string func_string = func_name;
std::cerr << "NOTREACHED(): " << func_string << std::endl;
ImmediateDebugCrash();
}
+44 -1
View File
@@ -4,6 +4,28 @@
#include "constants.h"
#include "framework.h"
extern wchar_t strings[16][256];
namespace {
static ULONG NT_MAJOR = 0;
static ULONG NT_MINOR = 0;
static ULONG NT_BUILD = 0;
static std::wstring NT_CSD_VERSION;
static std::string NT_SERVICE_PACK;
static USHORT NT_SUITE;
static UCHAR NT_TYPE;
}
static std::string NT_FEATURE_VERSION;
static std::string NT_POST_STRING;
// Function to load arbitrary .ico from arbitrary .dll
HANDLE LoadImageFromDLL(LPCWSTR dllName,
UINT resourceId,
@@ -15,9 +37,30 @@ HANDLE LoadImageFromDLL(LPCWSTR dllName,
// Decide what icon to use for main dialog
HICON getDialogIcon(bool use_custom_icon, int resource, int x, int y);
// Version getter functions
// App version getter functions
std::string getVersionA();
std::wstring getVersionW();
// Windows version getter functions
float getWinNTVersion();
extern std::string WinVer;
std::wstring GetWinVersion();
std::string const GetOSName();
std::string const GetNTString();
// Debug functions
void NotReachedImpl(std::string func_name);
#ifndef NOTREACHED
#define NOTREACHED() \
std::string func_name(__FUNC__); \
NotReachedImpl(func_name);
#endif // NOTREACHED
#endif // XP_ACTIVATE32_UTILS_H_
-1
View File
@@ -26,7 +26,6 @@
#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.3"
#define ABOUT_COPYRIGHT L"Copyright © 2025 Alex313031"
#define LEGAL_COPYRIGHT L"© 2025"
#endif // VERSION_STRING
+162 -98
View File
@@ -3,31 +3,33 @@
#include "keygen.h"
#include "utils.h"
/* Global instance handle */
HINSTANCE g_hInstance = NULL;
HWND g_hMainDlg = NULL;
static HICON hIcon[2];
#define divisor_double(src, dst) divisor_add(src, src, dst)
wchar_t strings[16][256];
static ui64 residue_add(ui64 x, ui64 y) {
ui64 residue_add(ui64 x, ui64 y) {
ui64 z = x + y;
//z = z - (z >= MOD ? MOD : 0);
if (z >= MOD)
if (z >= MOD) {
z -= MOD;
}
return z;
}
static ui64 residue_sub(ui64 x, ui64 y) {
ui64 residue_sub(ui64 x, ui64 y) {
ui64 z = x - y;
//z += (x < y ? MOD : 0);
if (x < y)
if (x < y) {
z += MOD;
}
return z;
}
// copypasted from https://stackoverflow.com/questions/46870373/umul128-on-windows-32-bits
static uint64_t __umul128(uint64_t multiplier, uint64_t multiplicand, uint64_t *product_hi) {
uint64_t __umul128(uint64_t multiplier, uint64_t multiplicand, uint64_t *product_hi) {
// multiplier = ab = a * 2^32 + b
// multiplicand = cd = c * 2^32 + d
// ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
@@ -53,7 +55,7 @@ static uint64_t __umul128(uint64_t multiplier, uint64_t multiplicand, uint64_t *
return product_lo;
}
static ui64 ui128_quotient_mod(ui64 lo, ui64 hi) {
ui64 ui128_quotient_mod(ui64 lo, ui64 hi) {
// hi:lo * ceil(2**170/MOD) >> (64 + 64 + 42)
ui64 prod1;
__umul128(lo, 0x604fa6a1c6346a87, &prod1);
@@ -73,7 +75,7 @@ static ui64 ui128_quotient_mod(ui64 lo, ui64 hi) {
return (prod3lo >> 42) | (prod3hi << 22);
}
static ui64 residue_mul(ui64 x, ui64 y) {
ui64 residue_mul(ui64 x, ui64 y) {
// * ceil(2**170/MOD) = 0x2d351 c6d04f8b|604fa6a1 c6346a87 for (p-1)*(p-1) max
ui64 hi;
ui64 lo = __umul128(x, y, &hi);
@@ -81,9 +83,10 @@ static ui64 residue_mul(ui64 x, ui64 y) {
return lo - quotient * MOD;
}
static ui64 residue_pow(ui64 x, ui64 y) {
if (y == 0)
ui64 residue_pow(ui64 x, ui64 y) {
if (y == 0) {
return 1;
}
ui64 cur = x;
while (!(y & 1)) {
cur = residue_mul(cur, cur);
@@ -92,13 +95,14 @@ static ui64 residue_pow(ui64 x, ui64 y) {
ui64 res = cur;
while ((y >>= 1) != 0) {
cur = residue_mul(cur, cur);
if (y & 1)
if (y & 1) {
res = residue_mul(res, cur);
}
}
return res;
}
static ui64 inverse(ui64 u, ui64 v) {
ui64 inverse(ui64 u, ui64 v) {
//assert(u);
i64 tmp;
i64 xu = 1, xv = 0;
@@ -112,18 +116,20 @@ static ui64 inverse(ui64 u, ui64 v) {
return xu;
}
static ui64 residue_inv(ui64 x) {
ui64 residue_inv(ui64 x) {
return inverse(x, MOD);
//{ return residue_pow(x, MOD - 2); }
}
static ui64 residue_sqrt(ui64 what) {
if (!what)
ui64 residue_sqrt(ui64 what) {
if (!what) {
return 0;
}
ui64 g = NON_RESIDUE, z, y, r, x, b, t;
ui64 e = 0, q = MOD - 1;
while (!(q & 1))
while (!(q & 1)) {
e++, q >>= 1;
}
z = residue_pow(g, q);
y = z;
r = e;
@@ -136,8 +142,9 @@ static ui64 residue_sqrt(ui64 what) {
m++;
b2 = residue_mul(b2, b2);
} while (b2 != 1);
if (m == r)
if (m == r) {
return BAD;
}
t = residue_pow(y, 1 << (r - m - 1));
y = residue_mul(t, t);
r = m;
@@ -158,8 +165,9 @@ int find_divisor_v(TDivisor* d) {
ui64 v1;
ui64 f2[6];
int i, j;
for (i = 0; i < 6; i++)
for (i = 0; i < 6; i++) {
f2[i] = f[i];
}
const ui64 u0 = d->u[0];
const ui64 u1 = d->u[1];
for (j = 4; j--; ) {
@@ -189,13 +197,15 @@ int find_divisor_v(TDivisor* d) {
}
ui64 sqr = residue_mul(residue_mul(f1, f1), residue_inv(residue_add(coeff1, coeff1)));
v1 = residue_sqrt(sqr);
if (v1 == BAD)
if (v1 == BAD) {
return 0;
}
} else {
ui64 d = residue_add(residue_mul(f0, f0), residue_mul(f1, residue_sub(residue_mul(f1, u0), residue_mul(f0, u1))));
d = residue_sqrt(d);
if (d == BAD)
if (d == BAD) {
return 0;
}
d = residue_add(d, d);
ui64 inv = residue_inv(coeff2);
ui64 root = residue_mul(residue_add(coeff1, d), inv);
@@ -203,8 +213,9 @@ int find_divisor_v(TDivisor* d) {
if (v1 == BAD) {
root = residue_mul(residue_sub(coeff1, d), inv);
v1 = residue_sqrt(root);
if (v1 == BAD)
if (v1 == BAD) {
return 0;
}
}
}
ui64 v0 = residue_mul(residue_add(f1, residue_mul(u1, residue_mul(v1, v1))), residue_inv(residue_add(v1, v1)));
@@ -214,40 +225,48 @@ int find_divisor_v(TDivisor* d) {
}
// generic short slow code
static int polynomial_mul(int adeg, const ui64 a[], int bdeg, const ui64 b[], int resultprevdeg, ui64 result[]) {
if (adeg < 0 || bdeg < 0)
int polynomial_mul(int adeg, const ui64 a[], int bdeg, const ui64 b[], int resultprevdeg, ui64 result[]) {
if (adeg < 0 || bdeg < 0) {
return resultprevdeg;
}
int i, j;
for (i = resultprevdeg + 1; i <= adeg + bdeg; i++)
for (i = resultprevdeg + 1; i <= adeg + bdeg; i++) {
result[i] = 0;
}
resultprevdeg = i - 1;
for (i = 0; i <= adeg; i++)
for (j = 0; j <= bdeg; j++)
for (i = 0; i <= adeg; i++) {
for (j = 0; j <= bdeg; j++) {
result[i + j] = residue_add(result[i + j], residue_mul(a[i], b[j]));
while (resultprevdeg >= 0 && result[resultprevdeg] == 0)
}
}
while (resultprevdeg >= 0 && result[resultprevdeg] == 0) {
--resultprevdeg;
}
return resultprevdeg;
}
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) {
assert(bdeg >= 0);
assert(b[bdeg] == 1);
int i, j;
for (i = adeg - bdeg; i >= 0; i--) {
ui64 q = a[i + bdeg];
if (quotient)
if (quotient) {
quotient[i] = q;
for (j = 0; j < bdeg; j++)
}
for (j = 0; j < bdeg; j++) {
a[i + j] = residue_sub(a[i + j], residue_mul(q, b[j]));
}
a[i + j] = 0;
}
i += bdeg;
while (i >= 0 && a[i] == 0)
while (i >= 0 && a[i] == 0) {
i--;
}
return i;
}
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]) {
int sdeg = -1;
ui64 s[3] = {0, 0, 0};
int mult1deg = 0;
@@ -285,24 +304,32 @@ static void polynomial_xgcd(int adeg, const ui64 a[3], int bdeg, const ui64 b[3]
ui64 mult = residue_mul(gcd[gcddeg], residue_inv(r[rdeg]));
// quotient = mult * x**delta
assert(rdeg + delta < 3);
for (int i = 0; i <= rdeg; i++)
for (int i = 0; i <= rdeg; i++) {
gcd[i + delta] = residue_sub(gcd[i + delta], residue_mul(mult, r[i]));
while (gcddeg >= 0 && gcd[gcddeg] == 0)
}
while (gcddeg >= 0 && gcd[gcddeg] == 0) {
gcddeg--;
}
assert(sdeg + delta < 3);
for (int i = 0; i <= sdeg; i++)
for (int i = 0; i <= sdeg; i++) {
mult1[i + delta] = residue_sub(mult1[i + delta], residue_mul(mult, s[i]));
if (mult1deg < sdeg + delta)
}
if (mult1deg < sdeg + delta) {
mult1deg = sdeg + delta;
while (mult1deg >= 0 && mult1[mult1deg] == 0)
}
while (mult1deg >= 0 && mult1[mult1deg] == 0) {
mult1deg--;
}
assert(tdeg + delta < 3);
for (int i = 0; i <= tdeg; i++)
for (int i = 0; i <= tdeg; i++) {
mult2[i + delta] = residue_sub(mult2[i + delta], residue_mul(mult, t[i]));
if (mult2deg < tdeg + delta)
}
if (mult2deg < tdeg + delta) {
mult2deg = tdeg + delta;
while (mult2deg >= 0 && mult2[mult2deg] == 0)
}
while (mult2deg >= 0 && mult2[mult2deg] == 0) {
mult2deg--;
}
}
// d1 = gcd, e1 = mult1, e2 = mult2
*pgcddeg = gcddeg;
@@ -310,7 +337,7 @@ static void polynomial_xgcd(int adeg, const ui64 a[3], int bdeg, const ui64 b[3]
*pmult2deg = mult2deg;
}
static int u2poly(const TDivisor* src, ui64 polyu[3], ui64 polyv[2]) {
int u2poly(const TDivisor* src, ui64 polyu[3], ui64 polyv[2]) {
if (src->u[1] != BAD) {
polyu[0] = src->u[0];
polyu[1] = src->u[1];
@@ -332,7 +359,11 @@ static int u2poly(const TDivisor* src, ui64 polyu[3], ui64 polyv[2]) {
return 0;
}
static void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* dst) {
void divisor_double(const TDivisor* src, TDivisor* dst) {
return divisor_add(src, src, dst);
}
void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* dst) {
ui64 u1[3], u2[3], v1[2], v2[2];
int u1deg = u2poly(src1, u1, v1);
int u2deg = u2poly(src2, u2, v2);
@@ -353,13 +384,16 @@ static void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* ds
assert(ddeg >= 0);
ui64 dmult = residue_inv(d[ddeg]);
int i;
for (i = 0; i < ddeg; i++)
for (i = 0; i < ddeg; i++) {
d[i] = residue_mul(d[i], dmult);
}
d[i] = 1;
for (i = 0; i <= c1deg; i++)
for (i = 0; i <= c1deg; i++) {
c1[i] = residue_mul(c1[i], dmult);
for (i = 0; i <= c2deg; i++)
}
for (i = 0; i <= c2deg; i++) {
c2[i] = residue_mul(c2[i], dmult);
}
ui64 u[5];
int udeg = polynomial_mul(u1deg, u1, u2deg, u2, -1, u);
// u is monic
@@ -372,8 +406,9 @@ static void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* ds
tmpdeg = polynomial_mul(e1deg, e1, 1, v, -1, tmp);
vdeg = polynomial_mul(u1deg, u1, tmpdeg, tmp, -1, v);
vdeg = polynomial_mul(d1deg, d1, 1, v1, vdeg, v);
for (i = 0; i <= vdeg; i++)
for (i = 0; i <= vdeg; i++) {
v[i] = residue_mul(v[i], c1[0]);
}
memcpy(tmp, f, 6 * sizeof(f[0]));
tmpdeg = 5;
tmpdeg = polynomial_mul(1, v1, 1, v2, tmpdeg, tmp);
@@ -395,22 +430,27 @@ static void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* ds
assert(vdeg <= 3);
// u' = monic((f-v^2)/u), v'=-v mod u'
tmpdeg = polynomial_mul(vdeg, v, vdeg, v, -1, tmp);
for (i = 0; i <= tmpdeg && i <= 5; i++)
for (i = 0; i <= tmpdeg && i <= 5; i++) {
tmp[i] = residue_sub(f[i], tmp[i]);
for (; i <= tmpdeg; i++)
}
for (; i <= tmpdeg; i++) {
tmp[i] = residue_sub(0, tmp[i]);
for (; i <= 5; i++)
}
for (; i <= 5; i++) {
tmp[i] = f[i];
}
tmpdeg = i - 1;
ui64 udiv[5];
polynomial_div_monic(tmpdeg, tmp, udeg, u, udiv);
udeg = tmpdeg - udeg;
ui64 mult = residue_inv(udiv[udeg]);
for (i = 0; i < udeg; i++)
for (i = 0; i < udeg; i++) {
u[i] = residue_mul(udiv[i], mult);
}
u[i] = 1;
for (i = 0; i <= vdeg; i++)
for (i = 0; i <= vdeg; i++) {
v[i] = residue_sub(0, v[i]);
}
vdeg = polynomial_div_monic(vdeg, v, udeg, u, NULL);
}
if (udeg == 2) {
@@ -432,7 +472,7 @@ static void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* ds
}
}
static void divisor_mul(const TDivisor* src, ui64 mult, TDivisor* dst) {
void divisor_mul(const TDivisor* src, ui64 mult, TDivisor* dst) {
if (mult == 0) {
dst->u[0] = BAD;
dst->u[1] = BAD;
@@ -448,12 +488,13 @@ static void divisor_mul(const TDivisor* src, ui64 mult, TDivisor* dst) {
*dst = cur;
while ((mult >>= 1) != 0) {
divisor_double(&cur, &cur);
if (mult & 1)
if (mult & 1) {
divisor_add(dst, &cur, 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) {
if (mult_lo == 0 && mult_hi == 0) {
dst->u[0] = BAD;
dst->u[1] = BAD;
@@ -465,30 +506,34 @@ static void divisor_mul128(const TDivisor* src, ui64 mult_lo, ui64 mult_hi, TDiv
while (!(mult_lo & 1)) {
divisor_double(&cur, &cur);
mult_lo >>= 1;
if (mult_hi & 1)
if (mult_hi & 1) {
mult_lo |= (1ULL << 63);
}
mult_hi >>= 1;
}
*dst = cur;
for (;;) {
mult_lo >>= 1;
if (mult_hi & 1)
if (mult_hi & 1) {
mult_lo |= (1ULL << 63);
}
mult_hi >>= 1;
if (mult_lo == 0 && mult_hi == 0)
if (mult_lo == 0 && mult_hi == 0) {
break;
}
divisor_double(&cur, &cur);
if (mult_lo & 1)
if (mult_lo & 1) {
divisor_add(dst, &cur, dst);
}
}
}
static unsigned rol(unsigned x, int shift) {
unsigned rol(unsigned x, int shift) {
//assert(shift > 0 && shift < 32);
return (x << shift) | (x >> (32 - 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]) {
unsigned a, b, c, d, e;
a = 0x67452301;
b = 0xEFCDAB89;
@@ -497,10 +542,12 @@ static void sha1_single_block(unsigned char input[64], unsigned char output[20])
e = 0xC3D2E1F0;
unsigned w[80];
size_t i;
for (i = 0; i < 16; i++)
for (i = 0; i < 16; i++) {
w[i] = input[4*i] << 24 | input[4*i+1] << 16 | input[4*i+2] << 8 | input[4*i+3];
for (i = 16; i < 80; i++)
}
for (i = 16; i < 80; i++) {
w[i] = rol(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
}
for (i = 0; i < 20; i++) {
unsigned tmp = rol(a, 5) + ((b & c) | (~b & d)) + e + w[i] + 0x5A827999;
e = d;
@@ -545,7 +592,7 @@ static void sha1_single_block(unsigned char input[64], unsigned char output[20])
output[16] = e >> 24; output[17] = e >> 16; output[18] = e >> 8; output[19] = e;
}
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) {
unsigned char sha1_input[64];
unsigned char sha1_result[20];
size_t half = bufSize / 2;
@@ -560,8 +607,9 @@ static void Mix(unsigned char* buffer, size_t bufSize, const unsigned char* key,
sha1_input[sizeof(sha1_input) - 2] = static_cast<unsigned char>((half + keySize)) * 8 / 0x100;
sha1_single_block(sha1_input, sha1_result);
size_t i;
for (i = half & ~3; i < half; i++)
for (i = half & ~3; i < half; i++) {
sha1_result[i] = sha1_result[i + 4 - (half & 3)];
}
for (i = 0; i < half; i++) {
unsigned char tmp = buffer[i + half];
buffer[i + half] = buffer[i] ^ sha1_result[i];
@@ -570,7 +618,7 @@ static void Mix(unsigned char* buffer, size_t bufSize, const unsigned char* key,
}
}
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) {
unsigned char sha1_input[64];
unsigned char sha1_result[20];
size_t half = bufSize / 2;
@@ -585,8 +633,9 @@ static void Unmix(unsigned char* buffer, size_t bufSize, const unsigned char* ke
sha1_input[sizeof(sha1_input) - 2] = static_cast<unsigned char>((half + keySize)) * 8 / 0x100;
sha1_single_block(sha1_input, sha1_result);
size_t i;
for (i = half & ~3; i < half; i++)
for (i = half & ~3; i < half; i++) {
sha1_result[i] = sha1_result[i + 4 - (half & 3)];
}
for (i = 0; i < half; i++) {
unsigned char tmp = buffer[i];
buffer[i] = buffer[i + half] ^ sha1_result[i];
@@ -595,7 +644,7 @@ static void Unmix(unsigned char* buffer, size_t bufSize, const unsigned char* ke
}
}
static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_id[49]) {
int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_id[49]) {
unsigned char installation_id[19]; // 10**45 < 256**19
size_t installation_id_len = 0;
const CHARTYPE* p = installation_id_str;
@@ -603,16 +652,20 @@ static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_i
unsigned check = 0;
size_t i;
for (; *p; p++) {
if (*p == ' ' || *p == '-')
if (*p == ' ' || *p == '-') {
continue;
}
int d = *p - '0';
if (d < 0 || d > 9)
if (d < 0 || d > 9) {
return ERR_INVALID_CHARACTER;
}
if (count == 5 || p[1] == 0) {
if (!count)
if (!count) {
return (totalCount == 45) ? ERR_TOO_LARGE : ERR_TOO_SHORT;
if (d != check % 7)
}
if (d != check % 7) {
return (count < 5) ? ERR_TOO_SHORT : ERR_INVALID_CHECK_DIGIT;
}
check = 0;
count = 0;
continue;
@@ -620,8 +673,9 @@ static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_i
check += (count % 2 ? d * 2 : d);
count++;
totalCount++;
if (totalCount > 45)
if (totalCount > 45) {
return ERR_TOO_LARGE;
}
unsigned char carry = d;
for (i = 0; i < installation_id_len; i++) {
unsigned x = installation_id[i] * 10 + carry;
@@ -633,14 +687,17 @@ static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_i
installation_id[installation_id_len++] = carry;
}
}
if (totalCount != 41 && totalCount < 45)
if (totalCount != 41 && totalCount < 45) {
return ERR_TOO_SHORT;
for (; installation_id_len < sizeof(installation_id); installation_id_len++)
}
for (; installation_id_len < sizeof(installation_id); installation_id_len++) {
installation_id[installation_id_len] = 0;
}
static const unsigned char iid_key[4] = {0x6A, 0xC8, 0x5E, 0xD4};
Unmix(installation_id, totalCount == 41 ? 17 : 19, iid_key, 4);
if (installation_id[18] >= 0x10)
if (installation_id[18] >= 0x10) {
return ERR_UNKNOWN_VERSION;
}
#pragma pack(push, 1)
struct {
@@ -656,9 +713,10 @@ static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_i
unsigned productId3 = (parsed.ProductIDLow >> 27) & ((1 << 25) - 1);
unsigned version = (parsed.ProductIDLow >> 52) & 7;
unsigned productId4 = (parsed.ProductIDLow >> 55) | (parsed.ProductIDHigh << 9);
if (version != (totalCount == 41 ? 4 : 5))
if (version != (totalCount == 41 ? 4 : 5)) {
return ERR_UNKNOWN_VERSION;
//printf("Product ID: %05u-%03u-%07u-%05u\n", productId1, productId2, productId3, productId4);
}
printf("Product ID: %05u-%03u-%07u-%05u\n", productId1, productId2, productId3, productId4);
unsigned char keybuf[16];
memcpy(keybuf, &parsed.HardwareID, 8);
@@ -684,11 +742,13 @@ static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_i
x2++;
d.u[0] = residue_sub(residue_mul(x1, x1), residue_mul(NON_RESIDUE, residue_mul(x2, x2)));
d.u[1] = residue_add(x1, x1);
if (find_divisor_v(&d))
if (find_divisor_v(&d)) {
break;
}
}
if (attempt > 0x80)
if (attempt > 0x80) {
return ERR_UNLUCKY;
}
divisor_mul128(&d, 0x04e21b9d10f127c1, 0x40da7c36d44c, &d);
union {
struct {
@@ -753,8 +813,9 @@ static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_i
assert(e.encoded[0] == 0 && e.encoded[1] == 0 && e.encoded[2] == 0 && e.encoded[3] == 0);
CHARTYPE* q = confirmation_id;
for (i = 0; i < 7; i++) {
if (i)
if (i) {
*q++ = '-';
}
unsigned char* p = decimal + i*5;
q[0] = p[0] + '0';
q[1] = p[1] + '0';
@@ -768,8 +829,6 @@ static int generate(const CHARTYPE* installation_id_str, CHARTYPE confirmation_i
return 0;
}
static wchar_t strings[14][256];
#undef INTERFACE
#define INTERFACE ICOMLicenseAgent
DECLARE_INTERFACE_(ICOMLicenseAgent, IDispatch) {
@@ -862,7 +921,7 @@ static BOOL LoadLicenseManager(HWND hParentForMsgBox) {
if (!ComInitialized) {
HRESULT status = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(status)) {
MessageBox(hParentForMsgBox, strings[10], strings[8], MB_ICONSTOP);
MessageBox(hParentForMsgBox, strings[IDS_FAILED_INITIALIZE], strings[IDS_ERROR], MB_ICONSTOP);
return FALSE;
}
ComInitialized = TRUE;
@@ -881,20 +940,20 @@ static BOOL LoadLicenseManager(HWND hParentForMsgBox) {
}
}
if (!good) {
MessageBox(hParentForMsgBox, strings[10], strings[8], MB_ICONSTOP);
MessageBox(hParentForMsgBox, strings[IDS_FAILED_INITIALIZE], strings[IDS_ERROR], MB_ICONSTOP);
return FALSE;
}
}
ULONG dwWPALeft = 0, dwEvalLeft = 0;
HRESULT status = LicenseAgent->GetExpirationInfo(&dwWPALeft, &dwEvalLeft);
if (FAILED(status)) {
MessageBox(hParentForMsgBox, strings[11], strings[8], MB_ICONSTOP);
MessageBox(hParentForMsgBox, strings[IDS_FAILED_CHECK], strings[IDS_ERROR], MB_ICONSTOP);
LicenseAgent->Release();
LicenseAgent = NULL;
return FALSE;
}
if (dwWPALeft == 0x7FFFFFFF) {
MessageBox(hParentForMsgBox, strings[12], strings[9], MB_ICONWARNING);
MessageBox(hParentForMsgBox, strings[IDS_ALREADY_ACTIVATED], strings[IDS_INFORMATION], MB_ICONINFORMATION);
LicenseAgent->Release();
LicenseAgent = NULL;
return FALSE;
@@ -903,15 +962,16 @@ static BOOL LoadLicenseManager(HWND hParentForMsgBox) {
}
static void GetIdFromSystem(HWND hDlg) {
if (!LoadLicenseManager(hDlg))
if (!LoadLicenseManager(hDlg)) {
return;
SetDlgItemText(hDlg, 103, strings[7]);
}
SetDlgItemText(hDlg, 103, strings[IDS_TALKING_TO_SYS]);
EnableWindow(GetDlgItem(hDlg, 102), FALSE);
UpdateWindow(hDlg);
BSTR installationId = NULL;
HRESULT status = LicenseAgent->GenerateInstallationId(&installationId);
if (FAILED(status) || !installationId) {
MessageBox(hDlg, strings[13], strings[8], MB_ICONSTOP);
MessageBox(hDlg, strings[IDS_LIC_MAN_FAILED], strings[IDS_ERROR], MB_ICONSTOP);
} else {
SetDlgItemText(hDlg, 101, installationId);
SysFreeString(installationId);
@@ -921,12 +981,13 @@ static void GetIdFromSystem(HWND hDlg) {
}
static void PutIdToSystem(HWND hDlg) {
if (!LoadLicenseManager(hDlg))
if (!LoadLicenseManager(hDlg)) {
return;
}
ULONG dwRetCode;
wchar_t confirmationId[256];
GetDlgItemText(hDlg, 103, confirmationId, sizeof(confirmationId) / sizeof(confirmationId[0]));
SetDlgItemText(hDlg, 103, strings[7]);
SetDlgItemText(hDlg, 103, strings[IDS_TALKING_TO_SYS]);
EnableWindow(GetDlgItem(hDlg, 102), FALSE);
EnableWindow(GetDlgItem(hDlg, 104), FALSE);
UpdateWindow(hDlg);
@@ -937,14 +998,15 @@ static void PutIdToSystem(HWND hDlg) {
EnableWindow(GetDlgItem(hDlg, 104), TRUE);
SetDlgItemText(hDlg, 103, confirmationId);
if (FAILED(status) || dwRetCode) {
MessageBox(hDlg, strings[13], strings[8], MB_ICONSTOP);
MessageBox(hDlg, strings[IDS_LIC_MAN_FAILED], strings[IDS_ERROR], MB_ICONSTOP);
return;
}
MessageBox(hDlg, strings[0], strings[9], MB_ICONINFORMATION);
MessageBox(hDlg, strings[IDS_SUCC_ACTIVATION], strings[IDS_INFORMATION], MB_ICONINFORMATION);
}
INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
int i;
g_hMainDlg = hDlg;
switch (uMsg) {
case WM_INITDIALOG:
for (i = 0; i < 2; i++) {
@@ -999,16 +1061,13 @@ 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;
}
INITCOMMONCONTROLSEX cc = {sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES};
InitCommonControlsEx(&cc);
int i;
for (i = 0; i < 14; i++) {
for (i = 0; i < 16; i++) {
LoadString(NULL, i, strings[i], sizeof(strings[i]) / sizeof(strings[i][0]));
}
@@ -1018,6 +1077,11 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance,
hIcon[i] = getDialogIcon(false, 194, x, y);
}
std::wstring welcome_str = L"Welcome to XP_Activate32 ver. " + getVersionW();
std::wcout << welcome_str << std::endl;
std::cout << "Windows Version: " << GetOSName() << std::endl;
std::cout << "WinVer: " << WinVer << std::endl;
// Create main window
INT_PTR main_dialog = DialogBoxW(g_hInstance, MAKEINTRESOURCE(100), NULL, &DialogProc);
err_status = static_cast<long>(main_dialog);
+8 -6
View File
@@ -24,12 +24,12 @@ typedef struct {
ui64 v[2];
} TDivisor;
#define ERR_TOO_SHORT 1
#define ERR_TOO_LARGE 2
#define ERR_INVALID_CHARACTER 3
#define ERR_INVALID_CHECK_DIGIT 4
#define ERR_UNKNOWN_VERSION 5
#define ERR_UNLUCKY 6
#define ERR_TOO_SHORT IDS_WAITING_INPUT
#define ERR_TOO_LARGE IDS_ID_TOO_LARGE
#define ERR_INVALID_CHARACTER IDS_INVALID_CHAR
#define ERR_INVALID_CHECK_DIGIT IDS_INVALID_CHECK
#define ERR_UNKNOWN_VERSION IDS_UNKNOWN_ID
#define ERR_UNLUCKY IDS_UNLUCKY_ID
#define BAD 0xFFFFFFFFFFFFFFFFULL
@@ -65,6 +65,8 @@ void polynomial_xgcd(int adeg, const ui64 a[3], int bdeg, const ui64 b[3], int*
int u2poly(const TDivisor* src, ui64 polyu[3], ui64 polyv[2]);
void divisor_double(const TDivisor* src, TDivisor* dst);
void divisor_add(const TDivisor* src1, const TDivisor* src2, TDivisor* dst);
void divisor_mul(const TDivisor* src, ui64 mult, TDivisor* dst);