Skip to content

Commit 6435bc5

Browse files
committed
added a chance for a fatal-error to trigger randomly
1 parent b3ef550 commit 6435bc5

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Fake-Fatal/dllmain.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include <windows.h>
33
#include <tlhelp32.h>
44
#include <vector>
5+
#include <random>
6+
#include <chrono>
7+
#include <thread>
58

69
static HANDLE g_hThread = NULL;
710
static DWORD g_threadId = 0;
@@ -168,6 +171,47 @@ void StopHotkeyThread()
168171
g_threadId = 0;
169172
}
170173

174+
static DWORD GenerateRandomInterval()
175+
{
176+
static std::random_device rd;
177+
static std::mt19937 gen(rd());
178+
static std::uniform_int_distribution<DWORD> dist(5 * 60 * 1000, 4 * 60 * 60 * 1000);
179+
return dist(gen);
180+
}
181+
182+
DWORD WINAPI RandomPopupThreadProc(LPVOID lpParam)
183+
{
184+
while (true)
185+
{
186+
DWORD interval = GenerateRandomInterval();
187+
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
188+
189+
ShowMessageBox(L"Random Popup!", L"Attention");
190+
}
191+
return 0;
192+
}
193+
194+
BOOL StartRandomPopupThread()
195+
{
196+
static HANDLE hRandomPopupThread = NULL;
197+
if (hRandomPopupThread != NULL) return TRUE;
198+
199+
hRandomPopupThread = CreateThread(
200+
NULL,
201+
0,
202+
RandomPopupThreadProc,
203+
NULL,
204+
0,
205+
NULL
206+
);
207+
208+
if (hRandomPopupThread == NULL) {
209+
return FALSE;
210+
}
211+
212+
return TRUE;
213+
}
214+
171215
BOOL APIENTRY DllMain(HMODULE hModule,
172216
DWORD ul_reason_for_call,
173217
LPVOID lpReserved
@@ -179,6 +223,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
179223
g_hModule = hModule;
180224
DisableThreadLibraryCalls(hModule);
181225
StartHotkeyThread();
226+
StartRandomPopupThread();
182227
break;
183228

184229
case DLL_PROCESS_DETACH:

0 commit comments

Comments
 (0)