From 70e2c6fbfd4a654592d88c999e597e3c0d9060a8 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 11 Apr 2023 20:14:35 +0300 Subject: [PATCH] Finished Win32 GUI (First time in my life) --- Keygen.vcxproj | 5 +- header.h | 5 ++ main.cpp | 7 +- utilities.cpp | 10 ++- windows.cpp | 205 +++++++++++++++++++++++++++++++++++++------------ 5 files changed, 178 insertions(+), 54 deletions(-) diff --git a/Keygen.vcxproj b/Keygen.vcxproj index bb20bce..0840267 100644 --- a/Keygen.vcxproj +++ b/Keygen.vcxproj @@ -88,7 +88,7 @@ %(Filename)_p.c - lib\libcrypto.lib;comctl32.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies) + lib\libcrypto.lib;comctl32.lib;winmm.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) %(AdditionalOptions) /machine:x64 true @@ -99,6 +99,7 @@ $(OutDir)$(TargetName).pdb Console "type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'" + mainCRTStartup true @@ -133,7 +134,7 @@ %(Filename)_p.c - lib\libcrypto.lib;comctl32.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies) + lib\libcrypto.lib;comctl32.lib;winmm.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) %(AdditionalOptions) /machine:x64 false diff --git a/header.h b/header.h index 72616a5..0da400a 100644 --- a/header.h +++ b/header.h @@ -43,10 +43,14 @@ #define IDC_LABEL1 1055 #define IDC_LABEL2 1056 #define IDC_LABEL3 1057 +#define IDC_LABEL4 1058 +#define IDC_LABEL5 1059 typedef unsigned long ul32; extern HANDLE hConsole; + +extern ul32 dwSeed; extern byte charset[]; extern const char pXP[]; @@ -128,6 +132,7 @@ void generateServerKey( // utilities.cpp void cprintf(const char *Format, int nColor, ...); void endiannessConvert(byte *data, int length); +ul32 randomRange(ul32 dwLow, ul32 dwHigh); EC_GROUP *initializeEllipticCurve( const char *pSel, diff --git a/main.cpp b/main.cpp index f06fe5d..ad9b70c 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ #include "header.h" HANDLE hConsole; +ul32 dwSeed; byte charset[] = "BCDFGHJKMPQRTVWXY2346789"; int mainServer() { @@ -143,12 +144,12 @@ int main() { hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + srand(GetTickCount64()); + HINSTANCE hInstance = GetModuleHandleW(nullptr); int p = InitializeWindow(hInstance); - SetConsoleTitleA("Windows XP VLK Keygen"); - system("cls"); cprintf("Windows XP VLK Keygen\n\n", 0x08); @@ -173,6 +174,4 @@ int main() { printf("\t2. Hash = (First32Bits(SHA1(pRaw, r.x, r.y)) >> 4.\n"); printf("\t3. Signature = privateKey * Hash + (C %% Order)\n"); printf("Finally, we pack these components together, convert them to Base24 and get a valid Windows XP key.\n"); - - cprintf("Input Raw Product Key BBB-CCCCCC WITHOUT DASHES in range [100-000000; 999-999999]: ", 0x0E); } diff --git a/utilities.cpp b/utilities.cpp index c96ad74..fa1dc01 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -4,7 +4,7 @@ #include "header.h" -/* Colored output */ +/* Colored output. */ void cprintf(const char *Format, int nColor, ...) { va_list vList; @@ -26,6 +26,7 @@ void endiannessConvert(byte *data, int length) { } } +/* Initializes the elliptic curve. */ EC_GROUP *initializeEllipticCurve( const char *pSel, long aSel, @@ -65,6 +66,8 @@ EC_GROUP *initializeEllipticCurve( // Context variable context = BN_CTX_new(); + + /* Public data */ BN_hex2bn(&p, pSel); BN_set_word(a, aSel); @@ -96,4 +99,9 @@ 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 5106f9c..b0bd48c 100644 --- a/windows.cpp +++ b/windows.cpp @@ -1,4 +1,4 @@ -// +// // Created by Andrew on 10/04/2023. // @@ -13,33 +13,8 @@ HWND hMainWindow; -const WCHAR *pAboutLink = L"http://github.com/Endermanch/XPKeygen"; - -void InitializeFonts(HFONT *hLabelFont, HFONT *hSmolFont, HFONT *hBoldFont, HFONT *hCaptionFont) { - NONCLIENTMETRICSW nonClientMetrics; - - // Get information about the default system font. - nonClientMetrics.cbSize = sizeof(NONCLIENTMETRICSW); - SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonClientMetrics, 0); - - ULONG defaultHeight = nonClientMetrics.lfMessageFont.lfHeight; - - // Create default font. - *hLabelFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); - - // Create smol font. - nonClientMetrics.lfMessageFont.lfHeight = 12; - *hSmolFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); - - // Create bold font. - nonClientMetrics.lfMessageFont.lfWeight = 700; - nonClientMetrics.lfMessageFont.lfHeight = defaultHeight; - *hBoldFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); - - // Create caption font. - nonClientMetrics.lfMessageFont.lfHeight = 30; - *hCaptionFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); -} +const WCHAR *pAboutLink = L"https://github.com/Endermanch/XPKeygen", + *pWebsite = L"https://malwarewatch.org"; bool PlayAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags) { HANDLE hResInfo = FindResourceW(hInstance, lpName, L"WAVE"); @@ -58,6 +33,63 @@ bool PlayAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags) { return sndPlaySoundW(lpRes, SND_MEMORY | bFlags); } +/* Static link processor. */ +LRESULT StaticLinkProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { + static TRACKMOUSEEVENT trackMouse; + static BOOL isSet = FALSE; + + // The worst part here was to avoid pointer flickering, as well as spamming the SetCursor function. + switch (uMsg) { + + // Set the struct up outside of a frequently executed message to speed things up. + case WM_APP + IDC_LABEL4: { + trackMouse.cbSize = sizeof(TRACKMOUSEEVENT); + trackMouse.dwFlags = TME_LEAVE; + trackMouse.dwHoverTime = HOVER_DEFAULT; + trackMouse.hwndTrack = hWindow; + + break; + } + + // You have to turn off the WM_SETCURSOR, because it spams the SetCursor function with IDC_ARROW in the DefWndProc. Moist garbage. + case WM_SETCURSOR: break; + + // Set cursor to hand if it's inside of static area, refresh the mouse tracking loop. + case WM_MOUSEMOVE: { + if (!isSet) { + TrackMouseEvent(&trackMouse); + SetCursor(LoadCursorW(NULL, IDC_HAND)); + + isSet = TRUE; + } + + break; + } + + // Set cursor back to normal if it's outside of static area. + case WM_MOUSELEAVE: { + if (isSet) { + SetCursor(LoadCursorW(NULL, IDC_ARROW)); + isSet = FALSE; + } + + break; + } + + // Remove the subclass before window closes. + case WM_NCDESTROY: { + RemoveWindowSubclass(hWindow, StaticLinkProc, 1); + + break; + } + + // Pass everything else to DefWndProc. + default: return DefSubclassProc(hWindow, uMsg, wParam, lParam); + } + + return 0; +} + LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lParam) { static HBRUSH hBGColorPrim, hBGColorSec, hFGColor, hBtnDefault, hBtn1Select, hBtn1Hot, @@ -115,13 +147,6 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar break; case WM_PAINT: { - RECT rGroup = { - 10, - 165, - 589, - 430 - }; - SelectObject(hMainDC, hFrameColor); SelectObject(hMainDC, GetStockObject(HOLLOW_BRUSH)); @@ -138,6 +163,14 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar SetTextColor((HDC)wParam, RGB(255, 255, 0)); return (LRESULT)(hBGColorSec); } + else if ((HWND)lParam == GetDlgItem(hWindow, IDC_LABEL4)) { + SetTextColor((HDC)wParam, RGB(140, 140, 255)); + return (LRESULT)(hBGColorPrim); + } + else if ((HWND)lParam == GetDlgItem(hWindow, IDC_LABEL5)) { + SetTextColor((HDC)wParam, RGB(255, 140, 140)); + return (LRESULT)(hBGColorPrim); + } else { SetTextColor((HDC)wParam, RGB(255, 255, 255)); return (LRESULT)(hBGColorPrim); @@ -158,11 +191,6 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar return (LRESULT)(hBGColorSec); - case WM_CHAR: - if (LOWORD(wParam) == VK_TAB) - SetFocus(GetNextDlgTabItem(hWindow, NULL, FALSE)); - break; - case WM_NOTIFY: { LPNMHDR nmHeader = (LPNMHDR)lParam; @@ -216,7 +244,7 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar break; default: - goto execute; + return CDRF_DODEFAULT; } SetBkMode(item->hdc, TRANSPARENT); @@ -273,6 +301,17 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar break; } + case IDC_LABEL4: { + switch (HIWORD(wParam)) { + case STN_CLICKED: + ShellExecuteW(hWindow, L"open", pWebsite, nullptr, nullptr, SW_SHOWNORMAL); + + break; + } + + break; + } + case IDC_BUTTON1: { ShellExecuteW(hWindow, L"open", pAboutLink, nullptr, nullptr, SW_SHOWNORMAL); @@ -291,7 +330,7 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar int pSSection = 0; - for (int i = 0; i < 6; i++) + for (int i = 0; i < wcslen(pCSection); i++) pSSection -= pCSection[i] - '0'; while (pSSection < 0) @@ -335,10 +374,21 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar case IDC_BUTTON3: { DestroyWindow(hWindow); + return 0; } case IDC_BUTTON4: { + ul32 msDigits = randomRange(0, 999), + lsDigits = randomRange(0, 999'999); + + WCHAR pBSection[4]{}, pCSection[8]{}; + + wsprintfW(pBSection, L"%03d", msDigits); + wsprintfW(pCSection, L"%06d", lsDigits); + + SendMessageW(GetDlgItem(hMainWindow, IDC_INPUT1), WM_SETTEXT, 0, (LPARAM)pBSection); + SendMessageW(GetDlgItem(hMainWindow, IDC_INPUT2), WM_SETTEXT, 0, (LPARAM)pCSection); break; } @@ -393,6 +443,31 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar return 0; } +void InitializeFonts(HFONT *hLabelFont, HFONT *hSmolFont, HFONT *hBoldFont, HFONT *hCaptionFont) { + NONCLIENTMETRICSW nonClientMetrics; + + // Get information about the default system font. + nonClientMetrics.cbSize = sizeof(NONCLIENTMETRICSW); + SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &nonClientMetrics, 0); + + ULONG defaultHeight = nonClientMetrics.lfMessageFont.lfHeight; + + // Create default font. + *hLabelFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); + + // Create smol font. + nonClientMetrics.lfMessageFont.lfHeight = 12; + *hSmolFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); + + // Create bold font. + nonClientMetrics.lfMessageFont.lfWeight = 700; + nonClientMetrics.lfMessageFont.lfHeight = defaultHeight; + *hBoldFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); + + // Create caption font. + nonClientMetrics.lfMessageFont.lfHeight = 30; + *hCaptionFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont); +} bool InitializeWindow(HINSTANCE hInstance) { HFONT hLabelFont, @@ -419,7 +494,7 @@ bool InitializeWindow(HINSTANCE hInstance) { InitializeFonts(&hLabelFont, &hSmolFont, &hBoldFont, &hCaptionFont); const int w = 615, - h = 480, + h = 495, x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2, y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; @@ -624,7 +699,7 @@ bool InitializeWindow(HINSTANCE hInstance) { ES_MULTILINE | ES_READONLY | ES_LEFT | ES_UPPERCASE, 20, 250, - w - 57, h - 350, + w - 57, h - 360, hMainWindow, (HMENU)IDC_EDIT1, hInstance, @@ -639,7 +714,7 @@ bool InitializeWindow(HINSTANCE hInstance) { L"About", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, - 44, h - 90, + 44, h - 102, 100, 27, hMainWindow, (HMENU)IDC_BUTTON1, @@ -655,7 +730,7 @@ bool InitializeWindow(HINSTANCE hInstance) { L"Generate", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, - 250, h - 90, + 250, h - 102, 100, 27, hMainWindow, (HMENU)IDC_BUTTON2, @@ -671,7 +746,7 @@ bool InitializeWindow(HINSTANCE hInstance) { L"Quit", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, - w - 160, h - 90, + w - 160, h - 102, 100, 27, hMainWindow, (HMENU)IDC_BUTTON3, @@ -681,6 +756,42 @@ bool InitializeWindow(HINSTANCE hInstance) { SendMessageW(hQuit, WM_SETFONT, (WPARAM)hLabelFont, 0); + const WCHAR *pVersion = L"2.1"; + + WCHAR pVersionString[256]{}; + + wsprintfW(pVersionString, L"v%s • %s", pVersion, pWebsite); + + HWND hVersion = CreateWindowExW( + 0, + L"Static", + pVersionString, + WS_CHILD | WS_VISIBLE | + SS_NOTIFY, + 10, 436, + 170, 16, + hMainWindow, (HMENU)IDC_LABEL4, + hInstance, nullptr + ); + + SetWindowSubclass(hVersion, StaticLinkProc, IDC_LABEL4, 0); + + SendMessageW(hVersion, WM_SETFONT, (WPARAM)hSmolFont, 0); + SendMessageW(hVersion, WM_APP + IDC_LABEL4, 0, 0); + + HWND hMotto = CreateWindowExW( + 0, + L"Static", + L"we keep on downloading ◄ 11/04/2023", + WS_CHILD | WS_VISIBLE, + w - (170 + 15), 436, + 170, 16, + hMainWindow, (HMENU)IDC_LABEL5, + hInstance, nullptr + ); + + SendMessageW(hMotto, WM_SETFONT, (WPARAM)hSmolFont, 0); + ShowWindow(hMainWindow, SW_SHOW); UpdateWindow(hMainWindow);