From 1b6d38d222ecafb6365b4e7a818856e0510eb27f Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 16 Apr 2023 18:08:29 +0300 Subject: [PATCH] Further decomposition --- header.h | 8 +++- key.cpp | 81 ++++++++++++++++++++++++++++++++++++++-- utilities.cpp | 33 ++++++++++++++--- windows.cpp | 101 ++------------------------------------------------ 4 files changed, 116 insertions(+), 107 deletions(-) diff --git a/header.h b/header.h index 7146ae6..9035795 100644 --- a/header.h +++ b/header.h @@ -129,12 +129,13 @@ void generateServerKey( ul32 *prefix ); -void generate2003(char *pkey, EC_GROUP *ec, EC_POINT *generator, BIGNUM *order, BIGNUM *priv, ul32 *osfamily, ul32 *prefix); - // utilities.cpp void endiannessConvert(byte *data, int length); ul32 randomRange(ul32 dwLow, ul32 dwHigh); +void stopAudio(); +bool playAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags); + EC_GROUP *initializeEllipticCurve( const char *pSel, long aSel, @@ -153,6 +154,9 @@ EC_GROUP *initializeEllipticCurve( void unbase24(ul32 *byteSeq, const char *cdKey); void base24(char *cdKey, ul32 *byteSeq); +void formatXP(WCHAR *pBSection, WCHAR *pCSection, WCHAR *pText); +void formatServer(WCHAR *pText); + // windows.cpp bool InitializeWindow(HINSTANCE hInstance); diff --git a/key.cpp b/key.cpp index 9af64be..56a52ee 100644 --- a/key.cpp +++ b/key.cpp @@ -4,7 +4,7 @@ #include "header.h" -/* Convert from byte sequence to the CD-key. */ +/* Converts from byte sequence to the CD-key. */ void base24(char *cdKey, ul32 *byteSeq) { byte rbs[16]; BIGNUM *z; @@ -30,7 +30,7 @@ void base24(char *cdKey, ul32 *byteSeq) { BN_free(z); } -/* Convert from CD-key to a byte sequence. */ +/* Converts from CD-key to a byte sequence. */ void unbase24(ul32 *byteSeq, const char *cdKey) { byte pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{}; BIGNUM *y = BN_new(); @@ -65,4 +65,79 @@ void unbase24(ul32 *byteSeq, const char *cdKey) { // Reverse the byte sequence. endiannessConvert((byte *) byteSeq, n); -} \ No newline at end of file +} + +/* Formats Windows XP key output. */ +void formatXP(WCHAR *pBSection, WCHAR *pCSection, WCHAR *pText) { + WCHAR pFPK[32]{}; + + int pSSection = 0; + + for (int i = 0; i < wcslen(pCSection); i++) + pSSection -= pCSection[i] - '0'; + + while (pSSection < 0) + pSSection += 7; + + char pKey[PK_LENGTH + NULL_TERMINATOR]{}; + ul32 msDigits = _wtoi(pBSection), + lsDigits = _wtoi(pCSection); + + ul32 nRPK = msDigits * 1'000'000 + lsDigits, + hash = 0, + bKey[4]{}, + bSig[2]{}; + + bool bValid = keyXP(pKey, nRPK); + + unbase24(bKey, pKey); + unpackXP(nullptr, &hash, bSig, bKey); + + for (int i = 0; i < 5; i++) + wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]); + + wsprintfW( + pText, + L"Product ID:\tPPPPP-%03d-%06d%d-23XXX\r\n\r\nBytecode:\t%08lX %08lX %08lX %08lX\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n", + nRPK / 1'000'000, + nRPK % 1'000'000, + pSSection, + bKey[3], bKey[2], bKey[1], bKey[0], + hash, + bSig[1], bSig[0], + bValid ? L"True" : L"False", + pFPK + ); +} + +/* Formats Windows Server 2003 key output. */ +void formatServer(WCHAR *pText) { + WCHAR pFPK[32]{}; + + char pKey[PK_LENGTH + NULL_TERMINATOR]{}; + ul32 hash = 0, + osFamily = 0, + prefix = 0, + bKey[4]{}, + bSig[2]{}; + + bool bValid = keyServer(pKey); + + unbase24(bKey, pKey); + unpackServer(&osFamily, &hash, bSig, &prefix, bKey); + + for (int i = 0; i < 5; i++) + wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]); + + wsprintfW( + pText, + L"Bytecode:\t%08lX %08lX %08lX %08lX\r\nOS Family:\t%d\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nPrefix:\t\t%04lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n", + bKey[3], bKey[2], bKey[1], bKey[0], + osFamily, + hash, + bSig[1], bSig[0], + prefix, + bValid ? L"True" : L"False", + pFPK + ); +} diff --git a/utilities.cpp b/utilities.cpp index 1bbefb2..ae74061 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -13,6 +13,34 @@ void endiannessConvert(byte *data, int length) { } } +/* Generates a random 32-bit integer in range. */ +ul32 randomRange(ul32 dwLow, ul32 dwHigh) { + return rand() % (dwHigh - dwLow) + dwLow; +} + +/* Stops current asynchronously played audio. */ +void stopAudio() { + PlaySoundW(nullptr, nullptr, 0); +} + +/* Plays audio stored as a resource. */ +bool playAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags) { + HANDLE hResInfo = FindResourceW(hInstance, lpName, L"WAVE"); + + if (hResInfo == nullptr) + return false; + + HANDLE hRes = LoadResource(hInstance, (HRSRC)hResInfo); + + if (hRes == nullptr) + return false; + + WCHAR *lpRes = (WCHAR *)LockResource(hRes); + FreeResource(hRes); + + return sndPlaySoundW(lpRes, SND_MEMORY | bFlags); +} + /* Initializes the elliptic curve. */ EC_GROUP *initializeEllipticCurve( const char *pSel, @@ -84,9 +112,4 @@ EC_GROUP *initializeEllipticCurve( BN_CTX_free(context); return eCurve; -} - -/* Generates a random 32-bit integer in range. */ -ul32 randomRange(ul32 dwLow, ul32 dwHigh) { - return rand() % (dwHigh - dwLow) + dwLow; } \ No newline at end of file diff --git a/windows.cpp b/windows.cpp index a36b1b3..ef99995 100644 --- a/windows.cpp +++ b/windows.cpp @@ -22,102 +22,6 @@ const WCHAR *pAboutLink = L"https://github.com/Endermanch/XPKeygen", bool bServer = false, bMusic = true; -void formatXP(WCHAR *pBSection, WCHAR *pCSection, WCHAR *pText) { - WCHAR pFPK[32]{}; - - int pSSection = 0; - - for (int i = 0; i < wcslen(pCSection); i++) - pSSection -= pCSection[i] - '0'; - - while (pSSection < 0) - pSSection += 7; - - char pKey[PK_LENGTH + NULL_TERMINATOR]{}; - ul32 msDigits = _wtoi(pBSection), - lsDigits = _wtoi(pCSection); - - ul32 nRPK = msDigits * 1'000'000 + lsDigits, - hash = 0, - bKey[4]{}, - bSig[2]{}; - - bool bValid = keyXP(pKey, nRPK); - - unbase24(bKey, pKey); - unpackXP(nullptr, &hash, bSig, bKey); - - for (int i = 0; i < 5; i++) - wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]); - - wsprintfW( - pText, - L"Product ID:\tPPPPP-%03d-%06d%d-23XXX\r\n\r\nBytecode:\t%08lX %08lX %08lX %08lX\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n", - nRPK / 1'000'000, - nRPK % 1'000'000, - pSSection, - bKey[3], bKey[2], bKey[1], bKey[0], - hash, - bSig[1], bSig[0], - bValid ? L"True" : L"False", - pFPK - ); -} - - - -void formatServer(WCHAR *pText) { - WCHAR pFPK[32]{}; - - char pKey[PK_LENGTH + NULL_TERMINATOR]{}; - ul32 hash = 0, - osFamily = 0, - prefix = 0, - bKey[4]{}, - bSig[2]{}; - - bool bValid = keyServer(pKey); - - unbase24(bKey, pKey); - unpackServer(&osFamily, &hash, bSig, &prefix, bKey); - - for (int i = 0; i < 5; i++) - wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]); - - wsprintfW( - pText, - L"Bytecode:\t%08lX %08lX %08lX %08lX\r\nOS Family:\t%d\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nPrefix:\t\t%04lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n", - bKey[3], bKey[2], bKey[1], bKey[0], - osFamily, - hash, - bSig[1], bSig[0], - prefix, - bValid ? L"True" : L"False", - pFPK - ); -} - -void StopAudio() { - PlaySoundW(nullptr, nullptr, 0); -} - -bool PlayAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags) { - HANDLE hResInfo = FindResourceW(hInstance, lpName, L"WAVE"); - - if (hResInfo == nullptr) - return false; - - HANDLE hRes = LoadResource(hInstance, (HRSRC)hResInfo); - - if (hRes == nullptr) - return false; - - WCHAR *lpRes = (WCHAR *)LockResource(hRes); - FreeResource(hRes); - - return sndPlaySoundW(lpRes, SND_MEMORY | bFlags); -} - /* Bitmap link processor. */ LRESULT BitmapLinkProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { static TRACKMOUSEEVENT trackMouse; @@ -232,6 +136,7 @@ LRESULT StaticLinkProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam, UI return 0; } +/* Main window processor. */ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lParam) { static HINSTANCE hInstance; @@ -442,7 +347,7 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar case STN_CLICKED: if (bMusic) { SendMessageW((HWND)lParam, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBMusicOff); - StopAudio(); + stopAudio(); bMusic = false; } @@ -622,6 +527,7 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar return 0; } +/* Initialize system fonts. */ void InitializeFonts(HFONT *hLabelFont, HFONT *hSmolFont, HFONT *hBoldFont, HFONT *hCaptionFont) { NONCLIENTMETRICSW nonClientMetrics; @@ -648,6 +554,7 @@ void InitializeFonts(HFONT *hLabelFont, HFONT *hSmolFont, HFONT *hBoldFont, HFON *hCaptionFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); } +/* Initialize main window. */ bool InitializeWindow(HINSTANCE hInstance) { HFONT hLabelFont, hSmolFont,