| 211 | } |
| 212 | |
| 213 | void TestThreadSuspendResume() { |
| 214 | printf("\n=== TEST 1: Thread Suspend/Resume ===\n\n"); |
| 215 | |
| 216 | HANDLE hThread = CreateThread(NULL, 0, WorkerThread, NULL, 0, NULL); |
| 217 | if (!hThread) { |
| 218 | printf("[!] CreateThread failed: %lu\n", GetLastError()); |
| 219 | return; |
| 220 | } |
| 221 | printf("[Main] Created worker thread %lu\n", GetThreadId(hThread)); |
| 222 | |
| 223 | Sleep(50); |
| 224 | |
| 225 | printf("[Main] Suspending worker thread\n"); |
| 226 | DWORD prevSuspendCount = SuspendThread(hThread); |
| 227 | if (prevSuspendCount == (DWORD)-1) { |
| 228 | printf("[!] SuspendThread failed: %lu\n", GetLastError()); |
| 229 | } |
| 230 | else { |
| 231 | printf("[Main] Thread suspended (previous suspend count: %lu)\n", prevSuspendCount); |
| 232 | } |
| 233 | |
| 234 | printf("[Main] Thread is suspended (pausing for 0.1 second to demonstrate)...\n"); |
| 235 | Sleep(100); |
| 236 | |
| 237 | printf("[Main] Resuming worker thread\n"); |
| 238 | DWORD newSuspendCount = ResumeThread(hThread); |
| 239 | if (newSuspendCount == (DWORD)-1) { |
| 240 | printf("[!] ResumeThread failed: %lu\n", GetLastError()); |
| 241 | } |
| 242 | else { |
| 243 | printf("[Main] Thread resumed (previous suspend count: %lu)\n", newSuspendCount); |
| 244 | } |
| 245 | |
| 246 | WaitForSingleObject(hThread, INFINITE); |
| 247 | CloseHandle(hThread); |
| 248 | |
| 249 | printf("[Main] Test 1 done\n"); |
| 250 | } |
| 251 | |
| 252 | // ============================================================================= |
| 253 | // MODULE 2: Process Spawn + Shellcode Allocation |