Mercurial > codedump
comparison win95kggui.c @ 63:bdcdd9c42043
Create win95kggui.c
committer: GitHub <noreply@github.com>
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Sat, 23 Apr 2022 05:57:34 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
62:8be9281d7ade | 63:bdcdd9c42043 |
---|---|
1 /** | |
2 * Windows 95 Keygen (Win32 version) | |
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 #define _WIN32_WINNT 0x0400 | |
31 #define ARRAYSIZE(a) \ | |
32 sizeof(a)/sizeof(a[0]) | |
33 #define CONCAT_INTS(x, y) \ | |
34 x * pow(10, log10(y)+1) + y | |
35 #ifdef _MSC_VER | |
36 #define strdup(p) _strdup(p) | |
37 #endif | |
38 #define GENERATE_KEY 1 | |
39 #define LISTBOX 2 | |
40 #define KEY 3 | |
41 int type; | |
42 HWND hWndListBox, key_box; | |
43 | |
44 int get_sum(int n) { | |
45 int sum; | |
46 for (sum = 0; n > 0; sum += n % 10, n /= 10); // copied this from google. sorry not sorry | |
47 return sum; | |
48 } | |
49 | |
50 int win95_nt4_prefix() { | |
51 int num = rand() % 1000; | |
52 while ((num == 333) || (num == 444) || (num == 555) || (num == 666) || (num == 777) || (num == 888) || (num == 999)) { | |
53 num = num + 1; | |
54 } | |
55 return num; | |
56 } | |
57 | |
58 int win95_suffix(bool isoem) { | |
59 int first_digits, last_digit, second_segment = 5; | |
60 while (get_sum(second_segment) % 7 != 0) { | |
61 if (isoem == false) { | |
62 first_digits = rand() % 1000000; | |
63 } else { | |
64 first_digits = rand() % 10000; | |
65 } | |
66 last_digit = rand() % 10; | |
67 while ((last_digit == 0) || (last_digit >= 8)) { | |
68 last_digit = rand() % 10; | |
69 } | |
70 second_segment = CONCAT_INTS(first_digits, last_digit); | |
71 } | |
72 return second_segment; | |
73 } | |
74 | |
75 int office_prefix() { | |
76 int new_site = 0; | |
77 int ez_pwned = 0; | |
78 while (CONCAT_INTS(new_site, ez_pwned) == 0) { | |
79 new_site = rand() % 100; | |
80 ez_pwned = (new_site % 10) + 2; | |
81 if (ez_pwned >= 10) { | |
82 ez_pwned -= 10; | |
83 } | |
84 } | |
85 return CONCAT_INTS(new_site, ez_pwned); | |
86 } | |
87 | |
88 int oem_prefix() { | |
89 const char* years[] = { | |
90 "95", | |
91 "96", | |
92 "97", | |
93 "98", | |
94 "99", | |
95 "00", | |
96 "01", | |
97 "02", | |
98 "03" | |
99 }; | |
100 char buf[6]; | |
101 sprintf(buf, "%03d", (rand() % 366) + 1); | |
102 strcat(buf, years[rand() % 9]); | |
103 int buf2 = atoi(buf); | |
104 return buf2; | |
105 } | |
106 | |
107 void AddControls(HWND hWnd) { | |
108 int i = 0; | |
109 /* Open File */ | |
110 HWND gen_button = CreateWindowA("Button", "Generate Key", WS_VISIBLE | WS_CHILD, (int)((225 - 100)/2), 5, 100, 20, hWnd, (HMENU)GENERATE_KEY, NULL, NULL); | |
111 /* Type */ | |
112 TCHAR listbox_items[][7] = {"Normal", "OEM", "Office"}; | |
113 hWndListBox = CreateWindowA("Listbox", NULL, WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_NOTIFY, (int)((225 - 100)/2), 55, 100, 40, hWnd, (HMENU)LISTBOX, NULL, NULL); | |
114 for (i = 0; i < ARRAYSIZE(listbox_items); i++) { | |
115 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]); | |
116 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i); | |
117 } | |
118 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0); | |
119 // idk | |
120 key_box = CreateWindowA("Edit", "", WS_VISIBLE | WS_CHILD | ES_READONLY | ES_CENTER | ES_MULTILINE, (int)((225 - 150)/2), 100, 150, 40, hWnd, (HMENU)KEY, NULL, NULL); | |
121 if (gen_button == NULL || hWndListBox == NULL || key_box == NULL) | |
122 MessageBoxA(hWnd, "how did you even trigger this", "GUI could not be initialized!", MB_ICONEXCLAMATION); | |
123 } | |
124 | |
125 bool CALLBACK SetFont(HWND child, LPARAM font) { | |
126 SendMessage(child, WM_SETFONT, font, true); | |
127 return true; | |
128 } | |
129 | |
130 LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { | |
131 switch(msg) { | |
132 case WM_COMMAND: | |
133 if(HIWORD(wParam) == CBN_SELCHANGE) { | |
134 if (LOWORD(wParam) == LISTBOX) | |
135 type = SendMessageA((HWND) lParam, (UINT) LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); | |
136 } | |
137 switch(wParam) { | |
138 case GENERATE_KEY: { | |
139 char* p = calloc(24, sizeof(char)); | |
140 switch(type) { | |
141 case 2: | |
142 snprintf(p, 24, "%04d-%07d", office_prefix(), win95_suffix(false)); | |
143 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | |
144 break; | |
145 case 1: | |
146 snprintf(p, 24, "%05d-OEM-%07d-%05d", oem_prefix(), win95_suffix(true), (rand() % 100000)); | |
147 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | |
148 break; | |
149 case 0: | |
150 snprintf(p, 24, "%03d-%07d", win95_nt4_prefix(), win95_suffix(false)); | |
151 SendMessageA(key_box, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | |
152 break; | |
153 } | |
154 } | |
155 case LISTBOX: | |
156 break; | |
157 case KEY: | |
158 break; | |
159 } | |
160 break; | |
161 case WM_CREATE: { | |
162 AddControls(hWnd); | |
163 EnumChildWindows(hWnd, (WNDENUMPROC)SetFont, (LPARAM)GetStockObject(DEFAULT_GUI_FONT)); | |
164 break; | |
165 } | |
166 case WM_DESTROY: | |
167 PostQuitMessage(0); | |
168 break; | |
169 default: | |
170 return DefWindowProcA(hWnd, msg, wParam, lParam); | |
171 } | |
172 return false; | |
173 } | |
174 | |
175 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int ncmdshow) { | |
176 srand((unsigned) time(NULL)); // magic rand() stuff :p | |
177 WNDCLASSA wc = {0}; | |
178 | |
179 wc.hbrBackground = (HBRUSH)COLOR_WINDOW; | |
180 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
181 wc.hInstance = hInstance; | |
182 wc.lpszClassName = "win95kg"; | |
183 wc.lpfnWndProc = WindowProcedure; | |
184 | |
185 if (!RegisterClassA(&wc)) return -1; | |
186 | |
187 CreateWindowA("win95kg", "Windows 95 Keygen", WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU, 100, 100, 225, 200, NULL, NULL, hInstance, NULL); | |
188 | |
189 MSG msg = {0}; | |
190 | |
191 while (GetMessage(&msg, NULL, 0, 0)) { | |
192 TranslateMessage(&msg); | |
193 DispatchMessage(&msg); | |
194 } | |
195 return 0; | |
196 } |