Un-Terminatable process

Started by
16 comments, last by GameDev.net 18 years, 5 months ago
Hi, so I have two process calling DebugActiveProcess on each other, hopefully making them unclosable. It works fine for one process(calling DebugActiveProcess for other process making it unclosable), but not for the other process. I don't know if there is anything else I need do do besides call DebugActiveProcess in each process. Here is my code: Process 1: Searches for other processes via window, and calls DebugActiveProcess on it

#include <windows.h>
#include <process.h>

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	HWND hWindow=0;

	do{
		hWindow = FindWindowEx(NULL, NULL, "test","test");
		Sleep(1000);
	}
	while(!hWindow);

	SendMessage(hWindow, 0x55, _getpid(), NULL);

	unsigned long id =0;
	GetWindowThreadProcessId(hWindow, &id);

	if(!DebugActiveProcess(id))
		MessageBox(0,"Failed",0,0);
	else
		MessageBox(0,"Success",0,0);

	while(true)
		Sleep(1000);

return 0;

}

Process 2: Creates window, waits for message w/ other processes id in it, then calls DebugActiveProcess

#include <windows.h>


LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	switch( msg )
    {
		case 0x55:
			if(!DebugActiveProcess(wParam))
				MessageBox(0, "Failed",0 ,0);
			else
				MessageBox(0,"Success",0,0);
			break;
	}
    return DefWindowProc( hWnd, msg, wParam, lParam );
}


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASSEX wc;

	wc.cbSize = sizeof(WNDCLASSEX); 
	wc.style			= CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc	= MsgProc;
	wc.cbClsExtra		= 0;
	wc.cbWndExtra		= 0;
	wc.hInstance		= hInstance;
	wc.hIcon			= 0;
	wc.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground	= (HBRUSH)(0);
	wc.lpszMenuName	= 0;
	wc.lpszClassName	= "test";
	wc.hIconSm		= 0;
    RegisterClassEx(&wc);

	CreateWindow("test", "test", 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);

	MSG msg;
	while(true)
	{
		Sleep(1500);
		PeekMessage(&msg, NULL, 0,0,PM_REMOVE);
	}
}

Any ideas?
Advertisement
I'm guessing that this is actually a feature of Windows. It would be a Bad Thing to just let any application set themselves up so they couldn't be terminated.
The first problem I notice is that you're sending and relying on a randomly numbered message. Use WM_USER instead.
Also, are you properly using WaitForDebugEvent? Do you resume the threads of the process being debugged after they are suspended by the DebugActivePricess?
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Why do you want to spawn an "unterminable" process?
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:Original post by LessBread
Why do you want to spawn an "unterminable" process?


I'm writing a custom program to block bad websites and as such I don't want it to be closed.

[Edited by - BlueMana on November 12, 2005 2:25:11 AM]
Have you considered writing a service? Or hooking ExitProcess?

This might help: The Win32 Debugging Application Programming Interface

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:Original post by Extrarius
The first problem I notice is that you're sending and relying on a randomly numbered message. Use WM_USER instead.
Also, are you properly using WaitForDebugEvent? Do you resume the threads of the process being debugged after they are suspended by the DebugActivePricess?


I feel dumb asking this, but I can't figure out whats wrong with my enumerate threads code. It doesn't ever break out of the do loop :(.

	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, id);	THREADENTRY32 Thread;	Thread.dwSize = sizeof(THREADENTRY32);	 if (hSnap == INVALID_HANDLE_VALUE)         MessageBox(0,"Error",0,0);	if (Thread32First(hSnap, &Thread))	{		do		{			HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, Thread.th32ThreadID);			if(hThread && ResumeThread(hThread) != 0xFFFFFFFF)			{				CloseHandle(hThread);			}			else                MessageBox(0,"Failed",0,0);		}while(Thread32Next(hSnap, &Thread));	}	CloseHandle(hSnap);


Also, I added a WaitForDebugEvent loop
DEBUG_EVENT DebugEv;                   // debugging event informationDWORD dwContinueStatus = DBG_CONTINUE; // exception continuation 	while(true){ 	//do stuff    WaitForDebugEvent(&DebugEv, 100); 	ContinueDebugEvent(DebugEv.dwProcessId,     DebugEv.dwThreadId, dwContinueStatus);  } 



Do I need anything else? I just want the other process to run normally, while still being debugged.

[Edited by - BlueMana on November 12, 2005 2:31:14 PM]
Quote:Original post by BlueMana
I'm writing a custom program to block bad websites and as such I don't want it to be closed.


Stop right there. You should not be doing this; all this will ensure is that people such as myself will never, ever, ever use a program as badly behaved as yours.
Quote:Original post by Catafriggm
Quote:Original post by BlueMana
I'm writing a custom program to block bad websites and as such I don't want it to be closed.


Stop right there. You should not be doing this; all this will ensure is that people such as myself will never, ever, ever use a program as badly behaved as yours.



what?
Quote:Original post by BlueMana
Quote:Original post by Catafriggm
Quote:Original post by BlueMana
I'm writing a custom program to block bad websites and as such I don't want it to be closed.


Stop right there. You should not be doing this; all this will ensure is that people such as myself will never, ever, ever use a program as badly behaved as yours.



what?


unless its just for yourself, other people might want to use this. but if they can't close it...

This topic is closed to new replies.

Advertisement