comparison win95kggui/src/win95kggui.c @ 64:1508aee998df

Add Windows 95 Keygen GUI
author Paper <mrpapersonic@gmail.com>
date Mon, 25 Apr 2022 02:10:41 -0400
parents
children dbf5ce219fe3
comparison
equal deleted inserted replaced
62:8be9281d7ade 64:1508aee998df
1 /**
2 * Windows 95 Keygen (Windows GUI ver.)
3 * Copyright (c) Paper 2022
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 **/
23 #include <stdio.h>
24 #include <windows.h>
25 #include <stdint.h>
26 #include <stdbool.h>
27 #include <commdlg.h>
28 #include <math.h>
29 #include <time.h>
30 #include <bass.h>
31 #include <resource.h>
32 #define _WIN32_WINNT 0x0400
33 #define ARRAYSIZE(a) \
34 sizeof(a)/sizeof(a[0])
35 #define CONCAT_INTS(x, y) \
36 x * pow(10, log10(y)+1) + y
37 #ifdef _MSC_VER
38 #define strdup(p) _strdup(p)
39 #endif
40 #define GENERATE_KEY 1
41 #define LISTBOX 2
42 #define KEY 3
43 int type;
44 HWND hWndListBox, key_box;
45 HMUSIC music;
46
47 extern char binary_src_bergsm_xm_start[];
48 extern char binary_src_bergsm_xm_end[];
49
50 int get_sum(int n) {
51 int sum;
52 for (sum = 0; n > 0; sum += n % 10, n /= 10); // copied this from google. sorry not sorry
53 return sum;
54 }
55
56 int win95_nt4_prefix() {
57 int num = rand() % 999;
58 while ((num == 333) || (num == 444) || (num == 555) || (num == 666) || (num == 777) || (num == 888) || (num == 999)) {
59 num = num + 1;
60 }
61 return num;
62 }
63
64 int win95_suffix(bool is_oem) {
65 int first_digits, last_digit, second_segment = 5;
66 while (get_sum(second_segment) % 7 != 0) {
67 if (is_oem == false) {
68 first_digits = rand() % 999999;
69 } else {
70 first_digits = rand() % 9999;
71 }
72 last_digit = rand() % 9;
73 while ((last_digit == 0) || (last_digit >= 8)) {
74 last_digit = rand() % 9;
75 }
76 second_segment = CONCAT_INTS(first_digits, last_digit);
77 }
78 return second_segment;
79 }
80
81 int office_prefix() {
82 int new_site = 0;
83 int ez_pwned = 0;
84 while (CONCAT_INTS(new_site, ez_pwned) == 0) {
85 new_site = rand() % 99;
86 ez_pwned = (new_site % 10) + 2;
87 if (ez_pwned >= 10) {
88 ez_pwned -= 10;
89 }
90 }
91 return CONCAT_INTS(new_site, ez_pwned);
92 }
93
94 int oem_prefix() {
95 const char* years[] = {
96 "95",
97 "96",
98 "97",
99 "98",
100 "99",
101 "00",
102 "01",
103 "02",
104 "03"
105 };
106 char buf[6];
107 sprintf(buf, "%03d", (rand() % 366) + 1);
108 strcat(buf, years[rand() % 9]);
109 int buf2 = atoi(buf);
110 return buf2;
111 }
112
113 void AddControls(HWND hWnd) {
114 int i = 0;
115 /* Open File */
116 HWND gen_button = CreateWindowA("Button", "Generate Key", WS_VISIBLE | WS_CHILD, (int)((225 - 100)/2), 5, 100, 20, hWnd, (HMENU)GENERATE_KEY, NULL, NULL);
117 /* Type */
118 TCHAR listbox_items[][22] = {"Windows 95 / NT 4 RTM", "Windows 95 OEM", "Office 97"};
119 hWndListBox = CreateWindowA("Listbox", NULL, WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_NOTIFY, (int)((225 - 150)/2), 30, 150, 60, hWnd, (HMENU)LISTBOX, NULL, NULL);
120 for (i = 0; i < ARRAYSIZE(listbox_items); i++) {
121 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]);
122 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i);
123 }
124 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
125 // idk
126 key_box = CreateWindowA("Edit", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_READONLY | ES_CENTER | ES_MULTILINE | SS_CENTER, (int)((225 - 150)/2), 100, 150, 40, hWnd, (HMENU)KEY, NULL, NULL);
127 if (gen_button == NULL || hWndListBox == NULL || key_box == NULL)
128 MessageBoxA(hWnd, "how did you even trigger this", "GUI could not be initialized!", MB_ICONEXCLAMATION);
129 }
130
131 bool CALLBACK SetFont(HWND child, LPARAM font) {
132 SendMessage(child, WM_SETFONT, font, true);
133 return true;
134 }
135
136 LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
137 switch(msg) {
138 case WM_COMMAND:
139 if(HIWORD(wParam) == CBN_SELCHANGE) {
140 if (LOWORD(wParam) == LISTBOX)
141 type = SendMessageA((HWND) lParam, (UINT) LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
142 }
143 switch(wParam) {
144 case GENERATE_KEY: {
145 char* p = calloc(24, sizeof(char));
146 switch(type) {
147 case 0:
148 snprintf(p, 24, "%04d-%07d", office_prefix(), win95_suffix(false));
149 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p);
150 break;
151 case 2:
152 snprintf(p, 24, "%05d-OEM-%07d-%05d", oem_prefix(), win95_suffix(true), (rand() % 100000));
153 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p);
154 break;
155 case 1:
156 snprintf(p, 24, "%03d-%07d", win95_nt4_prefix(), win95_suffix(false));
157 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p);
158 break;
159 }
160 }
161 case LISTBOX:
162 break;
163 case KEY:
164 break;
165 }
166 break;
167 case WM_CREATE: {
168 if (!BASS_Init(-1, 48000, 0, hWnd, NULL)) {
169 EndDialog(hWnd, 0);
170 break;
171 }
172 AddControls(hWnd);
173 EnumChildWindows(hWnd, (WNDENUMPROC)SetFont, (LPARAM)GetStockObject(DEFAULT_GUI_FONT));
174 music = BASS_MusicLoad(true, &binary_src_bergsm_xm_start, 0, (unsigned int)(binary_src_bergsm_xm_end - binary_src_bergsm_xm_start), BASS_SAMPLE_LOOP | BASS_MUSIC_FT2PAN | BASS_MUSIC_NONINTER | BASS_SAMPLE_FLOAT, 1);
175 BASS_ChannelPlay(music, FALSE);
176 break;
177 }
178 case WM_DESTROY:
179 BASS_MusicFree(music);
180 BASS_Free();
181 PostQuitMessage(0);
182 break;
183 default:
184 return DefWindowProcA(hWnd, msg, wParam, lParam);
185 }
186 return false;
187 }
188
189 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int ncmdshow) {
190 srand((unsigned) time(NULL)); // magic rand() stuff :p
191 WNDCLASSA wc = {0};
192
193 wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
194 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
195 wc.hInstance = hInstance;
196 wc.lpszClassName = "win95kg";
197 wc.lpfnWndProc = WindowProcedure;
198 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(PEED));
199
200 if (!RegisterClassA(&wc)) return -1;
201
202 CreateWindowA("win95kg", "Windows 95 Keygen", WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU, 100, 100, 225, 200, NULL, NULL, hInstance, NULL);
203
204 MSG msg = {0};
205
206 while (GetMessage(&msg, NULL, 0, 0)) {
207 TranslateMessage(&msg);
208 DispatchMessage(&msg);
209 }
210 return 0;
211 }