Jump to content
  • Advertisement
Sign in to follow this  
BlueMana

Un-Terminatable process

This topic is 4629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 information
DWORD 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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!